Skip to content

ANP SDK

AgentConnect 是 Agent Network Protocol 的多语言 SDK 和参考实现。Python 包名为 anp;同一仓库还包含
Go、Rust、Dart、TypeScript 和 Java SDK 工作区。

SDK 与发布状态

语言包 / 模块版本安装 / 使用状态
Pythonanp0.8.8pip install anppip install "anp[api]"稳定公开发布
Gogithub.com/agent-network-protocol/anp/golangv0.8.8go get github.com/agent-network-protocol/anp/golang@latest稳定公开发布
Rustanp0.8.8cargo add anp稳定公开发布
Dartanp0.8.7dart pub add anp已公开发布
TypeScript@anp/typescript-sdk本地 0.1.0cd typescript/ts_sdk && npm install && npm run build源码预览工作区
Javacom.agentconnect:anp4j本地 1.0.0cd 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 8000

OpenANP 会自动暴露:

端点用途
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/

源代码