Agent-to-Agent通信协议的完整技术规范
A2A (Agent-to-Agent) Protocol 旨在提供一个标准化的通信框架,使不同的AI Agent能够:
统一的消息格式和交互协议,确保跨平台兼容性
动态发现和注册Agent能力,支持智能任务分配
优化的通信机制,支持高并发和低延迟交互
内置身份验证和消息完整性保护机制
原则 | 说明 | 实现方式 |
---|---|---|
互操作性 | 跨平台、跨语言支持 | JSON消息格式,标准HTTP/WebSocket |
可扩展性 | 支持新能力和消息类型 | 插件化架构,版本兼容机制 |
容错性 | 处理网络故障和Agent异常 | 重试机制,优雅降级 |
透明性 | 可观测和可调试 | 详细日志,性能指标 |
{
"version": "1.0",
"messageId": "uuid-v4-string",
"timestamp": "2024-12-19T10:30:00.000Z",
"source": {
"agentId": "sender-agent-id",
"agentType": "customer-service",
"instanceId": "instance-123"
},
"target": {
"agentId": "target-agent-id",
"agentType": "knowledge-base",
"routingStrategy": "direct|broadcast|load-balance"
},
"message": {
"type": "REQUEST|RESPONSE|EVENT|HEARTBEAT",
"subType": "query|command|notification",
"correlationId": "original-message-id",
"priority": "low|normal|high|urgent"
},
"payload": {
"action": "specific-capability-name",
"parameters": {
// 具体的参数内容
},
"metadata": {
"timeout": 5000,
"retryCount": 3,
"encoding": "utf-8"
}
},
"security": {
"signature": "digital-signature",
"timestamp": "message-creation-time",
"nonce": "random-value"
}
}
Agent向其他Agent请求服务或信息
对REQUEST消息的回复
异步事件通知,无需响应
维持连接和监控Agent健康状态
{
"version": "1.0",
"messageId": "req_kb_001",
"timestamp": "2024-12-19T10:30:00.000Z",
"source": {
"agentId": "customer-service-01",
"agentType": "customer-service"
},
"target": {
"agentId": "knowledge-base-01",
"agentType": "knowledge-base"
},
"message": {
"type": "REQUEST",
"subType": "query",
"priority": "normal"
},
"payload": {
"action": "search",
"parameters": {
"query": "退款政策相关信息",
"category": "customer-service",
"language": "zh-CN",
"maxResults": 5
},
"metadata": {
"timeout": 3000,
"retryCount": 2
}
}
}
{
"version": "1.0",
"messageId": "resp_kb_001",
"timestamp": "2024-12-19T10:30:01.500Z",
"source": {
"agentId": "knowledge-base-01",
"agentType": "knowledge-base"
},
"target": {
"agentId": "customer-service-01",
"agentType": "customer-service"
},
"message": {
"type": "RESPONSE",
"correlationId": "req_kb_001",
"priority": "normal"
},
"payload": {
"status": "success",
"results": [
{
"id": "policy_001",
"title": "退款政策说明",
"content": "商品在未使用的情况下,7天内可申请退款...",
"confidence": 0.92,
"source": "official_policy"
}
],
"metadata": {
"processingTime": 1200,
"totalResults": 3
}
}
}
Agent Card是A2A Protocol中的核心概念,类似于"名片",用于描述Agent的身份、能力和访问方式。每个Agent必须提供一个标准化的Agent Card。
{
"agentInfo": {
"id": "knowledge-base-agent-01",
"name": "智能知识库Agent",
"type": "knowledge-base",
"version": "2.1.0",
"description": "企业知识库智能检索和问答服务Agent",
"vendor": "A2A Protocol Demo",
"license": "MIT"
},
"capabilities": [
{
"name": "search",
"displayName": "知识检索",
"description": "在知识库中搜索相关信息",
"inputSchema": {
"type": "object",
"properties": {
"query": {"type": "string", "description": "搜索关键词"},
"category": {"type": "string", "enum": ["FAQ", "policy", "technical"]},
"language": {"type": "string", "default": "zh-CN"}
},
"required": ["query"]
},
"outputSchema": {
"type": "object",
"properties": {
"results": {
"type": "array",
"items": {
"type": "object",
"properties": {
"title": {"type": "string"},
"content": {"type": "string"},
"confidence": {"type": "number", "minimum": 0, "maximum": 1}
}
}
}
}
},
"performance": {
"averageResponseTime": 800,
"maxConcurrentRequests": 100,
"reliability": 0.99
}
}
],
"endpoints": {
"primary": "wss://kb-agent.example.com/ws",
"backup": "https://kb-agent.example.com/api",
"healthCheck": "https://kb-agent.example.com/health"
},
"security": {
"authMethods": ["bearer-token", "mutual-tls"],
"requiredPermissions": ["read:knowledge-base"],
"dataClassification": "internal"
},
"constraints": {
"rateLimits": {
"requestsPerMinute": 1000,
"concurrentConnections": 50
},
"availability": {
"schedule": "24/7",
"maintenanceWindows": ["Sunday 02:00-04:00 UTC"]
}
},
"metadata": {
"createdAt": "2024-01-01T00:00:00Z",
"updatedAt": "2024-12-19T10:00:00Z",
"tags": ["nlp", "search", "enterprise"],
"documentation": "https://docs.example.com/kb-agent"
}
}
多个Agent按顺序处理任务,前一个Agent的输出作为下一个Agent的输入。
用户问题 → 意图识别Agent → 知识库Agent → 答案生成Agent → 用户
多个Agent同时处理不同方面的任务,最后聚合结果。
数据输入 → [统计Agent + 趋势Agent + 异常Agent] → 结果聚合