ANP SDK
AgentConnect 是 Agent Network Protocol 的多语言 SDK 和参考实现。Python 包名为 anp;同一仓库还包含
Go、Rust、Dart、TypeScript 和 Java SDK 工作区。
SDK 与发布状态
| 语言 | 包 / 模块 | 版本 | 安装 / 使用 | 状态 |
|---|---|---|---|---|
| Python | anp | 0.8.8 | pip install anp 或 pip install "anp[api]" | 稳定公开发布 |
| Go | github.com/agent-network-protocol/anp/golang | v0.8.8 | go get github.com/agent-network-protocol/anp/golang@latest | 稳定公开发布 |
| Rust | anp | 0.8.8 | cargo add anp | 稳定公开发布 |
| Dart | anp | 0.8.7 | dart pub add anp | 已公开发布 |
| TypeScript | @anp/typescript-sdk | 本地 0.1.0 | cd typescript/ts_sdk && npm install && npm run build | 源码预览工作区 |
| Java | com.agentconnect:anp4j | 本地 1.0.0 | cd java && mvn clean install -DskipTests | 本地 Maven 工作区 |
快速开始:Python OpenANP
安装 API extras:
bash
pip install "anp[api]"创建 app.py:
python
from fastapi import FastAPI
from anp.openanp import AgentConfig, anp_agent, interface
@anp_agent(AgentConfig(
name="Calculator",
did="did:wba:example.com:calculator",
prefix="/agent",
description="A simple calculator agent",
))
class CalculatorAgent:
@interface
async def add(self, a: int, b: int) -> int:
return a + b
app = FastAPI(title="Calculator Agent")
app.include_router(CalculatorAgent.router())启动服务:
bash
uvicorn app:app --port 8000OpenANP 会自动暴露:
| 端点 | 用途 |
|---|---|
GET /agent/ad.json | 用于发现的 Agent Description 文档 |
GET /agent/interface.json | 基于 Python type hints 生成的 OpenRPC 接口文档 |
POST /agent/rpc | 用于方法调用的 JSON-RPC 2.0 端点 |
学习路径
- 构建并调用 ANP 智能体:
examples/python/openanp_examples/ - 添加 DID WBA 身份认证:
examples/python/did_wba_examples/ - 生成和验证 proof:
examples/python/proof_examples/ - 校验和解析 WNS Handle:
examples/python/wns_examples/ - 发现并调用其他智能体:
examples/python/anp_crawler_examples/ - 运行 AP2 支付流程:
examples/python/ap2_examples/ - 了解 Direct E2EE 和 Group E2EE:
docs/e2e/