A2A完整周期

A2A完整生命周期全景

┌──────────┐                                      ┌──────────┐
│  Client  │                                      │  Server  │
│ (Agent A)│                                      │ (Agent B)│
└────┬─────┘                                      └────┬─────┘
     │                                                 │
     │ ① 发现: GET /.well-known/agent-card.json        │
     │ ────────────────────────────────────────────────>
     │ <──────────────── AgentCard ────────────────────│
     │   (解析能力/技能/端点/认证方案)                  │
     │                                                 │
     │ ② 认证: 按 securitySchemes 获取凭证(OAuth2 等)  │
     │                                                 │
     │ ③ 发起: SendMessage / SendStreamingMessage      │
     │ ────────────────────────────────────────────────>
     │ <─────────── Task{state: submitted} ────────────│
     │                                                 │
     │ ④ 处理: (流式时持续收到事件)                     │
     │ <──── TaskStatusUpdateEvent{working} ───────────│
     │ <──── TaskStatusUpdateEvent{input-required}? ───│ ←需要补充时
     │ ───── SendMessage(taskId=...) 补充信息 ─────────>│   暂停/恢复
     │ <──── TaskArtifactUpdateEvent{产物} ────────────│
     │                                                 │
     │ ⑤ 完成: 任务进入终态                             │
     │ <──── TaskStatusUpdateEvent{completed, final} ──│
     │                                                 │
     │ ⑥ (可选)GetTask 取完整结果 / ListTasks 盘点     │
     │ ────────────────────────────────────────────────>

六个阶段:发现 → 认证 → 发起 → 处理(可多轮) → 完成 → 回查。

JSON-RPC 方法速查

所有请求都是 POST 到 Agent Card 中声明的 URL,请求头建议带A2A-Version: 1.0,Body 为标准 JSON-RPC 2.0 信封。

功能 v1.0 方法名 v0.3 旧名(兼容/旧教程常见)
发消息(创建/续传任务) SendMessage message/send
发消息(SSE 流式) SendStreamingMessage message/stream
查任务状态/结果 GetTask tasks/get
列出任务 ListTasks (v0.3 无)
取消任务 CancelTask tasks/cancel
断线重连任务事件流 SubscribeToTask tasks/resubscribe
创建推送配置 CreateTaskPushNotificationConfig tasks/pushNotificationConfig/set
查推送配置 GetTaskPushNotificationConfig tasks/pushNotificationConfig/get
列推送配置 ListTaskPushNotificationConfigs tasks/pushNotificationConfig/list
删推送配置 DeleteTaskPushNotificationConfig tasks/pushNotificationConfig/delete
取认证后的扩展名片 GetExtendedAgentCard agent/getAuthenticatedExtendedCard

v1.0 同时定义了等价的 gRPC 和 HTTP+JSON/REST 绑定 (如 REST: POST /message:send、GET /tasks/{id}),三选一实现即可, 语义完全一致。

错误码

JSON-RPC code 错误 含义
-32001 TaskNotFoundError 任务 id 不存在/不可见
-32002 TaskNotCancelableError 任务已终态,不能取消
-32003 PushNotificationNotSupportedError 不支持推送
-32004 UnsupportedOperationError 不支持该操作(如向终态任务发消息)
-32005 ContentTypeNotSupportedError 媒体类型不支持
-32006 InvalidAgentResponseError Agent 产生了不合规响应
-32600/-32601/-32602/-32603 标准 JSON-RPC 错误 请求/方法/参数/内部错误

任务状态

submitted ─> working ─> completed | failed | canceled | rejected (终态)
                │
                ├─> input-required ─(补充后)─> working
                └─> auth-required ──(授权后)─> working