A2ap

API key required
Other

Agent-to-Agent Protocol — AI Agent间通信协议。可执行参考实现,四层架构(传输/发现/协商/执行)。CC BY-SA 4.0开放标准。

Install

openclaw skills install a2ap

A2AP — Agent-to-Agent Protocol

不是白皮书,是代码。 Agent间通信的第一个开放协议标准。

四层架构

┌──────────────────────┐
│  L4  Execution       │  远程调用 + 重试 + 信任评分
├──────────────────────┤
│  L3  Negotiation     │  能力注册/发现/协商
├──────────────────────┤
│  L2  Discovery       │  UDP广播 + mDNS风格发现
├──────────────────────┤
│  L1  Transport       │  TCP + JSON + HMAC签名
└──────────────────────┘

快速开始

# Demo: 两个Agent互调
python cli.py demo

# 启动服务端
python cli.py serve 9800

# 发现网络上的Agent
python cli.py discover

# 调用远程Agent能力
python cli.py invoke 127.0.0.1 9800 add '{"a":3,"b":5}'

Python API

from a2ap import A2APServer, A2APClient

# Agent A — 提供服务
server = A2APServer(name="Hermes", port=9800, secret="shared_key")
server.register_capability(
    name="humanize",
    impl=lambda text="": f"Humanized: {text}",
    description="Humanize AI-written text",
    input_schema={"text": "string"},
    output_schema={"result": "string"}
)
server.serve(background=True)

# Agent B — 调用服务
client = A2APClient()
caps = client.query_capabilities("127.0.0.1", 9800)
print(caps)  # ['humanize']

result = client.invoke("127.0.0.1", 9800, "humanize", {"text": "hello"})
print(result)  # {'success': True, 'result': 'Humanized: hello'}

信任模型

  • HMAC-SHA256签名 — 每条消息带签名防止篡改
  • 信任评分trust_peer() / is_trusted() 白名单机制
  • 可选加密 — 传输层可叠加TLS

协议规范

完整协议规范:A2AP-whitepaper.md (CC BY-SA 4.0)

许可证

MIT — 代码 | CC BY-SA 4.0 — 协议规范