Agent2Agent (A2A) 是一个开放的通信协议,专为 AI Agent 之间的互操作性而设计。它于 2025 年 4 月由 Google 联合超过 50 家技术合作伙伴(包括 Atlassian、Salesforce、SAP、LangChain 等)共同发布,并于同年捐赠给 Linux 基金会,成为厂商中立的开放标准。
graph TB
subgraph "A2A 协议定位"
A[AI Agent A<br/>Claude/GPT]
B[AI Agent B<br/>Gemini]
C[AI Agent C<br/>企业自建Agent]
A <-->|A2A Protocol| B
B <-->|A2A Protocol| C
C <-->|A2A Protocol| A
end
subgraph "协议层"
P1[HTTP/HTTPS]
P2[JSON-RPC 2.0]
P3[Server-Sent Events]
end
A --- P1
B --- P2
C --- P3
style A fill:#e1f5fe
style B fill:#fff3e0
style C fill:#f3e5f5
stateDiagram-v2
[*] --> submitted: 创建任务
submitted --> working: 开始处理
working --> working: 处理中
working --> input_required: 需要输入
working --> auth_required: 需要认证
input_required --> working: 收到输入
auth_required --> working: 认证完成
working --> completed: 成功完成
working --> failed: 处理失败
working --> canceled: 用户取消
submitted --> rejected: 拒绝任务
completed --> [*]
failed --> [*]
canceled --> [*]
rejected --> [*]
note right of working: 可发送状态更新<br/>可产生 Artifact
note right of input_required: Human-in-the-Loop<br/>等待人工输入
3. Message(消息)
消息是 Agent 之间单次交互的载体,包含一个或多个 Part。
graph LR
subgraph "Message 结构"
M[Message]
M --> R[role: user/agent]
M --> ID[messageId]
M --> P[parts]
P --> P1[TextPart]
P --> P2[FilePart]
P --> P3[DataPart]
end
subgraph "Part 类型"
P1 --> T1["kind: 'text'<br/>text: '...'"]
P2 --> T2["kind: 'file'<br/>file: {name, mimeType, bytes/uri}"]
P3 --> T3["kind: 'data'<br/>data: {type: 'json', data: {...}}"]
end
4. Artifact(产出物)
Artifact 是 Server Agent 产生的交付物,如文档、图片、代码文件等。
graph TB
subgraph "Artifact 结构"
A[Artifact]
A --> AID[artifactId]
A --> N[name]
A --> D[description]
A --> P[parts]
P --> P1[Part 1: 代码文件]
P --> P2[Part 2: 文档]
P --> P3[Part 3: 图片]
end
subgraph "流式产出"
S1[ArtifactUpdate 1<br/>append: false]
S2[ArtifactUpdate 2<br/>append: true]
S3[ArtifactUpdate 3<br/>lastChunk: true]
S1 --> S2 --> S3
end
style S1 fill:#e3f2fd
style S2 fill:#e3f2fd
style S3 fill:#c8e6c9
协议实现详解
JSON-RPC 方法
A2A 定义了以下核心 RPC 方法:
graph TB
subgraph "A2A RPC 方法"
subgraph "消息发送"
M1[message/send<br/>发送消息并等待响应]
M2[message/stream<br/>发送消息并接收流式响应]
end
subgraph "任务管理"
T1[tasks/get<br/>获取任务状态]
T2[tasks/cancel<br/>取消任务]
T3[tasks/resubscribe<br/>重新订阅任务流]
end
subgraph "推送通知"
P1[tasks/pushNotification/set<br/>设置推送配置]
P2[tasks/pushNotification/get<br/>获取推送配置]
end
end
style M1 fill:#e3f2fd
style M2 fill:#e3f2fd
style T1 fill:#e8f5e9
style T2 fill:#e8f5e9
style T3 fill:#e8f5e9
style P1 fill:#fff3e0
style P2 fill:#fff3e0
三种通信模式
模式 1:同步请求/响应
sequenceDiagram
participant C as Client Agent
participant S as Server Agent
C->>S: message/send (JSON-RPC)
Note right of S: 处理请求...
S-->>C: Response (Task/Message)
Note over C,S: 适用于简单、快速的任务
模式 2:流式响应 (SSE)
sequenceDiagram
participant C as Client Agent
participant S as Server Agent
C->>S: message/stream (HTTP POST)
S-->>C: HTTP 200 + Content-Type: text/event-stream
loop 流式更新
S-->>C: data: {"kind": "status-update", ...}
S-->>C: data: {"kind": "artifact-update", ...}
end
S-->>C: data: {"kind": "status-update", "final": true}
Note over C,S: 连接关闭
Note over C,S: 适用于需要实时反馈的任务
模式 3:异步推送通知
sequenceDiagram
participant C as Client Agent
participant S as Server Agent
participant W as Webhook (Client)
C->>S: tasks/pushNotification/set<br/>{taskId, webhookUrl}
S-->>C: OK
C->>S: message/send
S-->>C: Task (working)
Note right of S: 长时间处理...
S->>W: POST /webhook<br/>{taskId, state: completed}
W-->>S: 200 OK
C->>S: tasks/get {taskId}
S-->>C: Task (completed) + Artifacts
Note over C,S: 适用于长时间运行的任务
错误处理
A2A 定义了标准的 JSON-RPC 错误码:
错误码
名称
说明
-32700
Parse error
JSON 解析错误
-32600
Invalid Request
无效的请求
-32601
Method not found
方法不存在
-32602
Invalid params
无效的参数
-32603
Internal error
内部错误
-32000
Task not found
任务不存在
-32001
Task not cancelable
任务无法取消
-32002
Push notification not supported
不支持推送通知
-32003
Unsupported operation
不支持的操作
Multi-Agent 协作模式
协作架构
graph TB
subgraph "Multi-Agent 协作场景"
U[用户请求]
subgraph "Orchestrator Agent"
O[协调者 Agent]
end
subgraph "Specialist Agents"
S1[代码生成 Agent]
S2[代码审查 Agent]
S3[测试 Agent]
S4[部署 Agent]
end
U --> O
O <-->|A2A| S1
O <-->|A2A| S2
O <-->|A2A| S3
O <-->|A2A| S4
S1 -.->|MCP| T1[GitHub API]
S2 -.->|MCP| T2[Code Analysis Tool]
S3 -.->|MCP| T3[Test Runner]
S4 -.->|MCP| T4[K8s API]
end
style O fill:#ff9800,color:#fff
style S1 fill:#4caf50,color:#fff
style S2 fill:#2196f3,color:#fff
style S3 fill:#9c27b0,color:#fff
style S4 fill:#f44336,color:#fff
协作流程示例
sequenceDiagram
participant User
participant Orch as Orchestrator
participant Coder as Code Agent
participant Review as Review Agent
participant Test as Test Agent
User->>Orch: "开发一个用户认证模块"
Note over Orch: 分解任务
Orch->>Coder: message/send<br/>"实现 JWT 认证逻辑"
Coder-->>Orch: Task (working)
Coder-->>Orch: Artifact (auth.ts)
Coder-->>Orch: Task (completed)
Orch->>Review: message/send<br/>"审查 auth.ts 代码"
Review-->>Orch: Task (working)
Review-->>Orch: Message ("发现安全问题...")
Review-->>Orch: Task (input-required)
Orch->>Coder: message/send<br/>"修复安全问题"
Coder-->>Orch: Artifact (auth.ts v2)
Orch->>Review: message/send<br/>"重新审查"
Review-->>Orch: Task (completed, "审查通过")
Orch->>Test: message/send<br/>"运行测试"
Test-->>Orch: Task (completed, "100% 通过")
Orch-->>User: "认证模块开发完成 ✓"
不透明协作(Opaque Collaboration)
A2A 的核心设计理念是不透明协作:
graph LR
subgraph "Agent A (内部不可见)"
A1[私有记忆]
A2[专有逻辑]
A3[内部工具]
A4[接口层]
end
subgraph "Agent B (内部不可见)"
B1[私有记忆]
B2[专有逻辑]
B3[内部工具]
B4[接口层]
end
A4 <-->|A2A Protocol<br/>仅交换任务和消息| B4
style A1 fill:#ffcdd2
style A2 fill:#ffcdd2
style A3 fill:#ffcdd2
style B1 fill:#ffcdd2
style B2 fill:#ffcdd2
style B3 fill:#ffcdd2
style A4 fill:#c8e6c9
style B4 fill:#c8e6c9
优势:
保护知识产权和商业机密
保护用户隐私数据
降低集成复杂度
支持异构 Agent 协作
与其他协议的对比
协议定位对比
graph TB
subgraph "AI Agent 协议生态"
subgraph "工具层 (Agent-to-Tool)"
MCP[MCP<br/>Model Context Protocol]
end
subgraph "Agent 协作层 (Agent-to-Agent)"
A2A[A2A<br/>Agent2Agent Protocol]
ACP[ACP<br/>Agent Communication Protocol]
end
subgraph "框架层"
LC[LangChain]
AG[AutoGPT]
CW[CrewAI]
end
subgraph "应用层"
APP[企业应用]
end
end
APP --> LC
APP --> AG
APP --> CW
LC --> MCP
LC --> A2A
AG --> MCP
AG --> A2A
CW --> A2A
style MCP fill:#ff9800,color:#fff
style A2A fill:#4caf50,color:#fff
style ACP fill:#2196f3,color:#fff
类比:如果 MCP 是将键盘插入电脑的 USB 接口,那么 A2A 就是电脑之间发送邮件的网络协议。
应用场景
场景 1:企业供应链协作
graph LR
subgraph "零售商"
R[库存 Agent]
end
subgraph "供应商 A"
SA[销售 Agent]
end
subgraph "供应商 B"
SB[销售 Agent]
end
subgraph "物流商"
L[物流 Agent]
end
R <-->|A2A: 询价| SA
R <-->|A2A: 询价| SB
R <-->|A2A: 安排配送| L
SA <-->|A2A: 协调配送| L
style R fill:#2196f3,color:#fff
style SA fill:#4caf50,color:#fff
style SB fill:#4caf50,color:#fff
style L fill:#ff9800,color:#fff
案例:Tyson Foods 和 Gordon Food Service 正在使用 A2A 协议构建协作系统,实现产品数据和销售线索的实时共享。
场景 2:软件开发流水线
graph TB
subgraph "DevOps Agent 协作"
PM[产品经理 Agent]
DEV[开发 Agent]
QA[测试 Agent]
SEC[安全 Agent]
OPS[运维 Agent]
end
PM -->|需求| DEV
DEV -->|代码| QA
QA -->|测试报告| DEV
DEV -->|代码| SEC
SEC -->|安全报告| DEV
DEV -->|构建产物| OPS
OPS -->|部署状态| PM
style PM fill:#9c27b0,color:#fff
style DEV fill:#4caf50,color:#fff
style QA fill:#2196f3,color:#fff
style SEC fill:#f44336,color:#fff
style OPS fill:#ff9800,color:#fff
场景 3:跨云 Agent 协作
graph LR
subgraph "Azure"
A1[Copilot Agent]
end
subgraph "Google Cloud"
G1[Vertex AI Agent]
end
subgraph "AWS"
W1[Bedrock Agent]
end
subgraph "企业私有云"
E1[企业 Agent]
end
A1 <-->|A2A| G1
G1 <-->|A2A| W1
W1 <-->|A2A| E1
E1 <-->|A2A| A1
style A1 fill:#0078d4,color:#fff
style G1 fill:#4285f4,color:#fff
style W1 fill:#ff9900,color:#fff
style E1 fill:#6b7280,color:#fff
Microsoft 已宣布:Azure AI Foundry 和 Copilot Studio 将很快支持 A2A 协议。