A2A 协议参考
Performance Hub Agent 通过 HTTPS 上的 JSON-RPC 2.0 使用 A2A v1.0。代理所有者在 Performance Hub 中启用入站 A2A 并创建 bearer 密钥;然后外部系统调用该代理的端点。所有者的设置说明请参见 在 Performance Hub 外部连接代理 (A2A)。
A2A 对比 MCP。 MCP 允许您的 AI 工具调用 Performance Hub 功能(门禁、成员、报告等)。A2A 允许智能体之间作为对等体进行对话:您的 Performance Hub Agent 可以接受来自外部智能体的调用,并调用您配置的对等体。当工具需要在 Performance Hub 内部执行操作时,请使用 MCP;当另一个智能体需要与您的智能体对话时,请使用 A2A。
端点与 Agent Card
| 方法 | URL |
|---|---|
| JSON-RPC | POST https://app.performancehub.co/a2a/{agentId} |
| Agent Card | GET https://app.performancehub.co/a2a/{agentId}/.well-known/agent-card.json |
| Agent Card (别名) | GET https://app.performancehub.co/a2a/{agentId}/.well-known/agent.json |
请将 {agentId} 替换为 A2A 选项卡中的 Agent 设备 ID。如果 Agent 被替换为新硬件,ID(以及因此对应的 URL)将会更改,请务必更新你的调用方。
未知的 Agent 将返回 HTTP 404 以及 {"message":"Agent not found"}。
Card 可见性由所有者设置:
- 公开发现卡片: 任何人都可以读取该卡片
- 仅限已认证的调用方: 该卡片还要求提供 bearer 密钥
认证
在每个 JSON-RPC 调用中发送入站密钥:
Authorization: Bearer <your-inbound-key>
在 Agent 的 A2A 选项卡中为每个外部调用方创建一个密钥。密钥在创建时仅显示一次,请妥善保存。切勿在文档、源码管理或客户端代码中嵌入真实密钥。
Agent Card 字段
典型卡片包含:
| 字段 | 备注 |
|---|---|
name, description | 来自入站设置的显示身份 |
version | "1.0.0" (Agent Card 版本) |
protocolVersion | "1.0" |
url | JSON-RPC 端点 (v0.3 兼容性字段) |
supportedInterfaces | v1.0 的 { "url", "protocolBinding": "JSONRPC", "protocolVersion": "1.0" } 列表 |
capabilities.streaming | true |
capabilities.pushNotifications | false |
capabilities.stateTransitionHistory | false |
defaultInputModes / defaultOutputModes | ["text/plain"] |
securitySchemes.bearerAuth | { "type": "http", "scheme": "bearer" } |
security | [{ "bearerAuth": [] }] |
skills | 默认技能 ID general-assistance,名称 General Assistance,带有描述、标签以及 text/plain 类型的 inputModes / outputModes |
示例 (仅供参考):
{
"name": "Front Desk Agent",
"description": "Answers questions about visitor check-in, opening hours and meeting-room bookings for the front desk.",
"version": "1.0.0",
"protocolVersion": "1.0",
"url": "https://app.performancehub.co/a2a/example-agent-id",
"supportedInterfaces": [
{
"url": "https://app.performancehub.co/a2a/example-agent-id",
"protocolBinding": "JSONRPC",
"protocolVersion": "1.0"
}
],
"capabilities": {
"streaming": true,
"pushNotifications": false,
"stateTransitionHistory": false
},
"defaultInputModes": ["text/plain"],
"defaultOutputModes": ["text/plain"],
"securitySchemes": {
"bearerAuth": {
"type": "http",
"scheme": "bearer"
}
},
"security": [{ "bearerAuth": [] }],
"skills": [
{
"id": "general-assistance",
"name": "General Assistance",
"description": "Ask Front Desk Agent questions or delegate tasks.",
"tags": ["assistant"],
"inputModes": ["text/plain"],
"outputModes": ["text/plain"]
}
]
}
方法
每个调用都使用 A2A v1.0 方法名作为 JSON-RPC 的 method。v0.3 的斜杠名称仍可作为别名使用。请求体为 JSON-RPC 2.0。
| A2A v1.0 方法 | v0.3 别名 | 备注 |
|---|---|---|
SendMessage | message/send | 发送消息并接收任务 |
SendStreamingMessage | message/stream | 与发送相同,响应为服务器发送事件 (SSE) |
GetTask | tasks/get | params.id (或 taskId) |
ListTasks | tasks/list | 可选的 contextId 和 pageSize,返回 { tasks, totalSize } |
CancelTask | tasks/cancel | params.id (或 taskId) |
若要继续对话,请在下一条消息中发送相同的 contextId。
SendMessage
curl -sS https://app.performancehub.co/a2a/example-agent-id \
-H "Authorization: Bearer <your-inbound-key>" \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"id": "1",
"method": "SendMessage",
"params": {
"message": {
"role": "user",
"parts": [
{ "text": "What time does visitor check-in open on Saturday?" }
]
}
}
}'
成功的响应包含一个任务。回复文本位于 status.message.parts (角色 ROLE_AGENT) 中;当任务完成时,也位于 artifacts[0].parts (工件名称 response) 中。
SendStreamingMessage
结构与 SendMessage 相同,方法为 SendStreamingMessage。响应是任务更新的服务器发送事件流,直到任务完成或失败。
GetTask
curl -sS https://app.performancehub.co/a2a/example-agent-id \
-H "Authorization: Bearer <your-inbound-key>" \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"id": "2",
"method": "GetTask",
"params": { "id": "<task-id>" }
}'
ListTasks
curl -sS https://app.performancehub.co/a2a/example-agent-id \
-H "Authorization: Bearer <your-inbound-key>" \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"id": "3",
"method": "ListTasks",
"params": {}
}'
可选参数: 用于筛选单个对话的 contextId,以及 pageSize。结果为 { "tasks": […], "totalSize": N }。每个密钥仅列出其创建的任务。
CancelTask
curl -sS https://app.performancehub.co/a2a/example-agent-id \
-H "Authorization: Bearer <your-inbound-key>" \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"id": "4",
"method": "CancelTask",
"params": { "id": "<task-id>" }
}'
消息
部分 (Parts) 仅限文本。以下两种结构均可接受:
- A2A v1.0:
{ "text": "…" } - v0.3:
{ "kind": "text", "text": "…" }
文件、URL 或原始二进制部分会被拒绝,并返回 invalid-params 错误。
任务
| 状态 | 含义 |
|---|---|
TASK_STATE_SUBMITTED | 已接受 |
TASK_STATE_WORKING | Agent 正在处理 |
TASK_STATE_COMPLETED | 已完成并返回结果 |
TASK_STATE_INPUT_REQUIRED | Agent 需要更多输入 |
TASK_STATE_CANCELED | 已取消 |
TASK_STATE_FAILED | 失败 |
任务隔离以入站密钥为单位: 一个调用方永远无法看到其他密钥的任务。
错误
错误使用 JSON-RPC 错误对象 (code、message、可选的 data)。
| 代码 | 含义 |
|---|---|
| −32700 | 解析错误 |
| −32600 | 无效请求 |
| −32601 | 未找到方法 |
| −32602 | 无效参数 |
| −32603 | 内部错误 |
| −32001 | 未找到任务 |
| −32002 | AI 额度不足 |
| −32003 | 任务无法取消 |
| −32004 | 请求过多,请稍后重试 |
| −32005 | Agent 不可用 |
| −32006 | 未授权 (同时也是带有 JSON-RPC 错误体的 HTTP 401) |
| −32007 | 禁止访问 |
跨域资源共享 (CORS)
浏览器对 /a2a/ 的 GET、POST 和 OPTIONS 调用允许来自任何源,并带有 Content-Type、Authorization、A2A-Version 和 Accept 标头。这不涉及 Performance Hub 登录,入站密钥 (或公开的 Agent Card) 即是访问控制关卡。
来自 Performance Hub 的出站
当 Performance Hub Agent 调用外部对端时,该远程 agent 必须公开:
- 公共地址上的 HTTPS Agent Card 和 JSON-RPC 端点
- 以下认证方式之一: 无认证、bearer 令牌、API 密钥标头或 OAuth 2.0 客户端凭据
所有者可在 A2A 选项卡上配置对端。在发送任何内容之前,聊天中的人员会确认一个经过脱敏的预览。请参阅将 Performance Hub 外部的 agent 连接 (A2A)。
安全注意事项
- 每个外部系统创建一个入站密钥;撤销不再信任的密钥。
- 外部调用者无法从您的代理横向移动到您的其他代理。
- 每个密钥只能查看其自身的任务。
- 将来自外部代理的回复视为不受信任的输入。
- 当卡片本身不应公开时,对于 Agent Card,建议仅限经过身份验证的调用者。
相关页面
- 连接 Performance Hub 外部的代理 (A2A): 所有者设置
- 代理协同工作: 组织对等代理(非 A2A)
- 与 AI 一起使用: MCP 概述
- AI Agents MCP 工具: 从 MCP 发现代理并向其发送消息