Skip to main content
AUTOGEN INTEGRATION

AutoGen payment integration.

There is no AutoGen package, and you do not need one. Wrap the real blockchain0x client in a function, hand it to your agent, and it can move USDC on Base.

SHORT ANSWER

There is no AutoGen-specific package, and you do not need one. AutoGen already turns a plain typed function into a tool, so you wrap the real Python client in a function, hand it to an via , and the agent can send USDC, settle invoices, and read wallets on Base. Set and go.

WHY THERE IS NO PACKAGE

AutoGen already makes a function a tool. Use that.

AutoGen builds a tool schema straight from a Python function's signature and docstring. A dedicated AutoGen adapter would only wrap a function we would have written anyway, then drift out of sync with AutoGen's fast-moving API. So we do not ship one. You write a few lines that call the real blockchain0x client, and you keep full control of the arguments, validation, and error handling.

This is the same client the shipped LangChain and CrewAI adapters wrap under the hood. Here you wrap it yourself, which means there is no adapter version to track and nothing between your agent and the API except your own function. Multi-agent teams work the same way: give the wallet function to one agent, leave the others without it, and spending authority stays in one place.

INSTALLATION

Install AutoGen and the core SDK. One environment variable.

There is no dedicated AutoGen package to add. You install AutoGen (Python 3.10+) and the real blockchain0x core SDK, then write the function below. That is the whole dependency list.

INSTALL
pip install autogen-agentchat "autogen-ext[openai]" blockchain0x
ENVIRONMENT VARIABLE
export BLOCKCHAIN0X_API_KEY=sk_test_...   # sk_test_ = Base Sepolia, sk_live_ = Base mainnet

BLOCKCHAIN0X_API_KEY is a sk_test_ testnet or sk_live_ mainnet key from your dashboard; the client reads it from the environment. If your agent also receives money, the webhook handler additionally needs BLOCKCHAIN0X_WEBHOOK_SECRET, which the dashboard returns once when you create or rotate a webhook.

THE RECIPE

A function that pays, handed to an AssistantAgent.

Below is the whole integration. send_usdc calls the real blockchain0x client; AssistantAgent(tools=[send_usdc]) turns it into a tool the model can call. AutoGen reads the type hints and docstring to build the schema, so keep them honest. Run it and the agent moves USDC on Base.

AGENT.PY
from autogen_agentchat.agents import AssistantAgent
from autogen_ext.models.openai import OpenAIChatCompletionClient
from blockchain0x import Client

blockchain0x = Client()  # reads BLOCKCHAIN0X_API_KEY from the environment

# AutoGen turns a plain typed function into a tool. No dedicated package needed.
def send_usdc(agent_id: str, to: str, amount_wei: str) -> str:
    """Send a USDC payment from an agent wallet.

    amount_wei is USDC base units (6 decimals), so "10000" is 0.01 USDC.
    """
    result = blockchain0x.payments.create(
        body={"agentId": agent_id, "to": to, "amountWei": amount_wei},
    )
    return str(result)

treasurer = AssistantAgent(
    name="treasurer",
    model_client=OpenAIChatCompletionClient(model="gpt-4o"),
    tools=[send_usdc],
    system_message="You pay vendor invoices in USDC within owner-set limits.",
)

result = await treasurer.run(
    task="Pay 0.01 USDC from agent agt_123 to 0xVendor for the dataset.",
)

When the agent decides to pay, it calls send_usdc, the SDK submits the transfer, and you get a transaction hash back. amount_wei is base units, so 0.01 USDC is "10000". A sk_test_ key keeps it on Base Sepolia until you switch to sk_live_. Add more functions - read a wallet, settle an invoice - the same way; each becomes another entry in tools.

WEBHOOK HANDLING

Confirm inbound payments with a signed webhook.

If your agent also receives USDC, confirm it with the webhook rather than polling. The verify helper ships in the Node SDK; in a Python service you verify by hand against the documented HMAC, which is all the helper does. FastAPI example below; the same code works in any async Python framework.

WEBHOOK.PY
import hmac, hashlib, os, time
from fastapi import FastAPI, Request, HTTPException

app = FastAPI()
SECRET = os.environ["BLOCKCHAIN0X_WEBHOOK_SECRET"].encode()

@app.post("/webhooks/payment")
async def receive(request: Request):
    raw = await request.body()  # RAW bytes - do not parse first
    sig = request.headers.get("X-Blockchain0x-Signature", "")
    ts = request.headers.get("X-Blockchain0x-Timestamp", "")
    parts = dict(p.split("=", 1) for p in sig.split(",") if "=" in p)
    t, v1 = parts.get("t", ts), parts.get("v1", sig)
    want = hmac.new(SECRET, t.encode() + b"." + raw, hashlib.sha256).hexdigest()
    if not hmac.compare_digest(want, v1) or abs(time.time() - int(t)) > 300:
        raise HTTPException(status_code=401)
    if request.headers.get("X-Blockchain0x-Event-Type") == "payment.received":
        await trigger_followup()  # USDC landed - run the next step
    return {"ok": True}

The algorithm is HMAC-SHA256 over the string t.rawBody, a constant-time compare, and a 300-second replay window. Read the raw body via await request.body(), never request.json() re-serialized, because that changes the bytes the signature covers. The shipped events are payment.received, payment.sent, wallet.deployed, and webhook.test. For heavy follow-up work, enqueue a job (Celery, RQ, arq) and respond 200 immediately rather than blocking the handler.

SOURCE AND DOCS

The client you are wrapping is open. Read it.

There is no AutoGen starter package to clone - the recipe above is the integration. The blockchain0x SDKs are open source on GitHub; this recipe wraps the Python SDK (blockchain0x-python), with the full method surface in the docs. Read it for a reference for the function bodies.

github.com/tosh-labs/blockchain0x-python

The full SDK method surface and scopes are documented at the docs. Start on a sk_test_ key against Base Sepolia, then switch to sk_live_ when the function does what you expect.

COMMON PITFALLS

Five group-chat and async traps to avoid.

AutoGen's multi-agent + async design unlocks powerful patterns but introduces its own footguns. These come from our support inbox.

PITFALL 1

There is no AutoGen package - you wrap the SDK

Blockchain0x ships shipped adapters for LangChain and CrewAI plus the MCP server; there is no dedicated AutoGen package. The recipe above is the supported path: a plain typed function that calls the real blockchain0x client, handed to AssistantAgent(tools=[...]). AutoGen reads the function signature and docstring to build the tool schema, so keep the docstring accurate.

PITFALL 2

Amounts are USDC base units, as strings

payments.create takes amountWei: a string of USDC base units, not a float and not a dollar figure. USDC has 6 decimals, so 0.01 USDC is "10000" and 5 USDC is "5000000". Type the tool argument as str and validate it before the call - a float that sneaks through either errors at the backend or moves a millionth of what you meant.

PITFALL 3

send_payment can answer 503 early on

payments.create does not retry by default and can return 503 until the chain adapter is wired for your network. Do not let the group chat loop on a failed payment - catch the error in your function, return a clear message the model can act on, and rely on the auto-minted idempotency key so a manual retry does not double-pay.

PITFALL 4

AutoGen 0.4+ is async; the SDK call is sync

AutoGen 0.4 runs tools in an async loop. The blockchain0x client call is synchronous, which is fine for a quick request, but a slow call blocks the loop. If you are moving real volume, wrap the SDK call with asyncio.to_thread so the event loop stays responsive. For a single payment per turn, calling it directly is fine.

PITFALL 5

Verify inbound webhooks against the raw body

If your agent also RECEIVES money, confirm it with the webhook, not by polling. Verify the signature over the RAW request bytes (await request.body()), never request.json() re-serialized, because the HMAC covers the exact bytes. It is HMAC-SHA256 with a 300-second replay window. The handler below is the whole thing.

FREQUENTLY ASKED

Three AutoGen-specific questions.

Is there a dedicated AutoGen package to install?

No. There is no dedicated AutoGen adapter, and that is deliberate - AutoGen already turns a plain typed function into a tool, so the honest path is to wrap the real blockchain0x client in a function and hand it to your agent, exactly as shown above. The only shipped framework packages are blockchain0x-langchain and blockchain0x-crewai (both Python) plus the @blockchain0x/mcp server. Everything else, AutoGen included, is this few-line recipe.

Does the recipe work on classic AutoGen (0.2.x) as well as 0.4+?

Yes, because the payment logic is just a Python function - nothing AutoGen-version-specific lives in it. On 0.4+ you pass it via AssistantAgent(tools=[...]) as above. On the 0.2.x ConversableAgent line you register the same function with register_function. There is no .legacy submodule to import because there is no package; you own the function.

How does my agent receive USDC or settle an invoice, not just send it?

Wrap more of the client the same way. blockchain0x.transactions.get reads a transaction, blockchain0x.agents.get and blockchain0x.agents.list read wallets, and blockchain0x.payment_requests.settle settles an invoice you created in the dashboard with on-chain proof. Each becomes another typed function in your tools list. Inbound payments confirm via the payment.received webhook (verify it with the handler below); there is no tool that mints a fresh invoice, since payment requests are created in the dashboard.

Give your AutoGen agent a wallet.

A few lines wrapping the real client, no package to install. Free to start.