# A2A Protocol:Agent 之间的通用语,一个 pip 包就能部署 > Google 捐给 Linux 基金会的 agent 互联协议,v1.0 已稳定。最小部署只要一个 SDK、一张 Agent Card、一个 ASGI 服务,5 分钟跑通闭环。 ## 一句话 A2A(Agent2Agent)是让两个**不共享代码、不共享内存**的 AI agent 互相发现、委派任务、交付结果的开放协议——agent 世界的"普通话"。Google 发起、捐给 Linux 基金会,2026 年 3 月发布首个稳定版 v1.0。 ## 为什么值得现在上手 它的差异化不在某个单点功能,而在**协作闭环**:发现(Agent Card)→ 协商交互方式 → 委派任务(Task 全生命周期)→ 流式进度回传 → 产物(artifacts)交付,一段协议全包。 - **出身**:Google 2025-04 发起 → 捐赠 Linux 基金会(现属 AAIF,与 MCP 同一个基金会) - **生态**:150+ 组织支持(AWS、Microsoft、Salesforce、SAP、ServiceNow…),已内嵌进 Azure AI Foundry / Copilot Studio、AWS Bedrock AgentCore;GitHub 22k+ stars - **与 MCP 互补不打架**:MCP 是 agent 插工具(垂直,一个 agent 向下接数据/服务),A2A 是 agent 找 agent(水平,跨组织委派任务) ## 部署前只需懂三个概念 1. **Agent Card**:agent 的名片(JSON),声明名称/能力/技能/接入地址。客户端先读卡,再决定怎么调用——v1.0 起卡片可签名(RFC 8785 规范化 + JWS),防仿冒 2. **Task**:一次委派的完整生命周期(submitted → working → completed/failed),支持 SSE 流式进度和 artifacts 产物回传,长任务可异步 + 推送通知 3. **传输**:同一套语义三种线材——JSON-RPC 2.0 over HTTPS(标配)、HTTP+JSON(REST 风格)、gRPC,客户端按 Agent Card 里的 `supportedInterfaces` 协商 ## 最小部署(Python,5 分钟跑通) **1. 装 SDK**(Python 3.10+,另有 JS/Java/Go/.NET 四套 SDK): ```bash pip install "a2a-sdk[http-server]" # 全量: "a2a-sdk[all]" ``` **2. 定义名片和技能,起一个 ASGI 服务**(官方 helloworld 示例核心代码): ```python import uvicorn from a2a.server.request_handlers import DefaultRequestHandler from a2a.server.routes import create_agent_card_routes, create_jsonrpc_routes from a2a.server.tasks import InMemoryTaskStore from a2a.types import AgentCapabilities, AgentCard, AgentInterface, AgentSkill from starlette.applications import Starlette skill = AgentSkill( id='echo_bot', name='Echo Bot', description='Responds with a Hello World message', input_modes=['text/plain'], output_modes=['text/plain'], tags=['a2a', 'echo-example'], examples=['hi', 'how are you'], ) public_agent_card = AgentCard( name='Hello World Agent', description='Just a hello world agent', version='0.0.1', default_input_modes=['text/plain'], default_output_modes=['text/plain'], capabilities=AgentCapabilities(streaming=True, extended_agent_card=True), supported_interfaces=[ AgentInterface(protocol_binding='JSONRPC', url='http://127.0.0.1:9999', protocol_version='1.0') ], skills=[skill], ) # 配合 DefaultRequestHandler + InMemoryTaskStore 挂到 Starlette,uvicorn 起在 :9999 ``` **3. 验证**:另开终端跑 `test_client.py`(先拉 Agent Card 再发消息),或用官方可视化调试器 [a2a-inspector](https://github.com/a2aproject/a2a-inspector)。 ```bash git clone https://github.com/a2aproject/a2a-samples.git cd a2a-samples/samples/python/agents/helloworld uv run . # 终端 1:起 server uv run test_client.py # 终端 2:跑客户端 ``` ## 生产部署要点 - **任务存储**:示例用 `InMemoryTaskStore`,生产换 SQL 后端——SDK 自带 PostgreSQL / MySQL / SQLite 驱动(`a2a-sdk[postgresql]` 等 extras) - **可观测**:`a2a-sdk[telemetry]` 接 OpenTelemetry tracing - **安全**:签名 Agent Card 验证对端身份;OAuth 只留 Device Code + PKCE(v1.0 砍掉了 implicit/密码流) - **v0.3 → v1.0 不兼容**:枚举全部改成 `TASK_STATE_COMPLETED` 式命名、三种 Part 合并成一个、Agent Card 顶层 `url` 字段移入 `supportedInterfaces`——老集成必须迁移,别硬扛 - **云上省事路径**:Azure AI Foundry / AWS Bedrock AgentCore 已原生支持 A2A,托管部署可以不管传输层 ## 什么场景该上、什么场景先等等 - **该上**:跨组织/跨框架的 agent 协作(自家 LangGraph agent 要调供应商的 CrewAI agent)、需要任务级状态机和流式回传的委派 - **先等等**:全同构的自建 fleet(比如几台 Hermes Agent 互联),用各框架自带的直连方式(如 `hermes mcp serve` over SSH)更轻;等要接外部生态再切 A2A 不迟 ## 链接 - 官网 / 规范:https://a2a-protocol.org/ - 主仓库:https://github.com/a2aproject/A2A - Python SDK:https://github.com/a2aproject/a2a-python - 官方示例集(Py/JS):https://github.com/a2aproject/a2a-samples - 可视化调试器:https://github.com/a2aproject/a2a-inspector --- **分类**:程序员 **标签**:Agent · agent · a2a **作者**:子龙 **链接**:https://octohz.com/p/2176