Agno支付集成。
没有 Agno 包,您不需要一个。将真实的 blockchain0x 客户端包装在一个小工具包中,您的代理可以在 Base 上移动 USDC - 最小化抽象,Agno 的方式。
没有 Agno-specific package,而且你也不需要。Agno 会把一个 方法变成工具,因此你只需把真实的 Python client 包装成一个小型 toolkit,并将其加入你的 。代理可以发送 USDC、结算 invoice、读取钱包,适用于所有 Agno model(OpenAI、Anthropic、DeepSeek、Llama、Mistral)。支付在 Base 上结算。
轻量级Python框架。没有抽象税。
Agno(前身为Phidata)是您在需要最小仪式时选择的代理框架。没有图形构建器,没有Crew,没有工作流 - 只有代理、工具和run()方法。工具是Python可调用的。该框架添加了足够的脚手架,以支持工具调用LLM,管理内存,并生成流输出,然后让您自由使用。
该食谱遵循相同的理念。您编写一个小的 Toolkit 子类,注册一个调用真实客户端的方法 - 它看起来和行为与其他 Agno 工具一样。除了实例化之外没有特殊设置,没有图形需要连接,没有适配器版本需要跟踪。简单性就是关键:如果您想要图形,您会在 LangGraph 上。
安装Agno和核心SDK。两个密钥。
没有可以添加的 blockchain0x Agno 包。您安装 Agno(Python 3.10+,在 Phidata 重命名后的 1.0+ 版本)和真正的 blockchain0x 核心 SDK,然后编写下面的工具包。如果您仍在使用 phi.* 导入,请先运行 pip install -U agno。
pip install agno blockchain0xexport OPENAI_API_KEY=sk-... export BLOCKCHAIN0X_API_KEY=sk_test_... # sk_test_ = Base Sepolia, sk_live_ = Base mainnet
OPENAI_API_KEY(或你使用的任一 Agno 支持模型对应的等效密钥)。BLOCKCHAIN0X_API_KEY 是你 dashboard 中的 sk_test_ testnet 或 sk_live_ mainnet key;client 会从环境变量读取它。如果你的 agent 也会收款,webhook handler 还需要 BLOCKCHAIN0X_WEBHOOK_SECRET。
一个支付的工具包,交给代理。
以下是整个集成。WalletTools是一个Toolkit子类,注册send_usdc,该方法调用真实的blockchain0x客户端。将其添加到代理中,run()调用协调工具调用。Agno读取方法签名和文档字符串以构建架构。
from agno.agent import Agent from agno.models.openai import OpenAIChat from agno.tools import Toolkit from blockchain0x import Client blockchain0x = Client() # reads BLOCKCHAIN0X_API_KEY from the environment # Wrap the real client in an Agno Toolkit. No dedicated package needed. class WalletTools(Toolkit): def __init__(self): super().__init__(name="wallet_tools") self.register(self.send_usdc) def send_usdc(self, 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. """ return str( blockchain0x.payments.create(body={"agentId": agent_id, "to": to, "amountWei": amount_wei}) ) agent = Agent( model=OpenAIChat(id="gpt-4o"), tools=[WalletTools()], instructions=["You pay vendor invoices in USDC within owner-set limits."], ) result = agent.run("Pay 0.01 USDC from agent agt_123 to 0xVendor for the dataset.") print(result.content)
When agent.run() executes, the model decides to pay, 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_. Register more methods on the toolkit - read a wallet, settle an invoice - the same way.
通过签名的 webhook 确认入站支付。
如果您的代理还接收USDC,请通过Webhook确认,而不是轮询。验证助手包含在Node SDK中;在Python服务中,您手动验证文档中的HMAC,这就是助手所做的一切。下面是FastAPI示例;相同的代码适用于任何异步Python框架。
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}
该算法是针对字符串 t.rawBody 的 HMAC-SHA256,具有常量时间比较和 300 秒的重放窗口。通过 await request.body() 读取原始主体,绝不要 request.json() 重新序列化,因为这会更改签名覆盖的字节。已发布的事件是 payment.received、payment.sent、wallet.deployed 和 webhook.test。对于重的后续工作,排队一个作业(Celery、arq)并立即响应 200,而不是阻塞处理程序。
您正在包装的客户端是开放的。阅读它。
没有可供克隆的 Agno starter package - 上面的 recipe 就是集成方式。blockchain0x SDKs 在 GitHub 上开源;这个 recipe 封装的是 Python SDK(blockchain0x-python),完整 method surface 见 docs。可以阅读它作为 toolkit methods 的参考。
github.com/tosh-labs/blockchain0x-python完整的 SDK method surface 和 scopes 已记录在 the docs 中。先使用 sk_test_ key 对接 Base Sepolia 进行测试,然后在 toolkit 符合预期后切换到 sk_live_。
五个 Agno 特定的关注点。
Agno是一个较为干净的代理框架,易于集成,但它有自己的陷阱 - 尤其是在Phidata重命名和Markdown渲染方面。
没有 Agno 包 - 您在工具包中包装 SDK
Blockchain0x 为 LangChain 和 CrewAI 以及 MCP 服务器提供适配器;没有专门的 Agno 包。上面的配方是路径:一个 Toolkit 子类,注册一个调用真实 blockchain0x 客户端的方法。Agno 读取方法签名和文档字符串以构建工具架构,因此请保持文档字符串的准确性。
Phidata到Agno迁移混淆
Agno在2024年从Phidata更名。导入自phi.agent或phi.tools的旧代码库仍然可以通过兼容性适配器正常工作,但agno.*导入是当前的。该配方在整个过程中使用agno.*;如果你的代码仍在使用phi.*导入,请运行pip install -U agno并在添加工具包之前切换导入路径。
金额是USDC基本单位,以字符串形式表示
payments.create takes amountWei: a string of USDC base units (6 decimals), so 0.01 USDC is "10000" and 5 USDC is "5000000". Type the method argument as str. It also does not retry by default and can answer 503 until the chain adapter is wired for your network - return a clear message rather than letting the agent loop.
同步与异步运行
Agno支持agent.run()(同步)和agent.arun()(异步)。每个代理选择一种模式 - 调用agent.run()并尝试等待结果,你会得到一个协程,而你期待的是一个字符串。工具包中的blockchain0x调用是同步的;如果你在异步路径上并且处理真实的交易量,请用asyncio.to_thread包装它,以便事件循环保持响应。
根据原始主体验证 webhook
如果您的代理还接收USDC,请通过Webhook确认,而不是轮询。验证原始请求字节上的签名(await request.body()),绝不要请求.json()重新序列化,因为HMAC覆盖了确切的字节。它是HMAC-SHA256,具有300秒的重放窗口。下面的处理程序就是全部内容。