A2A协议拆解

  |   0 评论   |   0 浏览

Agent2Agent (A2A) 协议是一种用于 AI 智能体的通信协议,最初由 Google 于 2025 年 4 月推出。

使用JSON-RPC 2.0 协议

核心元素

Agent card

用户描述Agent基本信息的一段json,一般通过/.well-known/agent-card.json 访问

image.png

Message

Agent之间交换信息的结构体

Artifact

被调用Agent的产物

Part

代表message或者artifact里面的信息

Task

被调用Agent根据请求所生成的任务

Fundamental Communication Elements

The following table describes the fundamental communication elements in A2A:

ElementDescriptionKey Purpose
Agent CardA JSON metadata document describing an agent's identity, capabilities, endpoint, skills, and authentication requirements.Enables clients to discover agents and understand how to interact with them securely and effectively.
TaskA stateful unit of work initiated by an agent, with a unique ID and defined lifecycle.Facilitates tracking of long-running operations and enables multi-turn interactions and collaboration.
MessageA single turn of communication between a client and an agent, containing content and a role ("user" or "agent").Conveys instructions, context, questions, answers, or status updates that are not necessarily formal artifacts.
PartThe fundamental content container (for example, TextPart, FilePart, DataPart) used within Messages and Artifacts.Provides flexibility for agents to exchange various content types within messages and artifacts.
ArtifactA tangible output generated by an agent during a task (for example, a document, image, or structured data).Delivers the concrete results of an agent's work, ensuring structured and retrievable outputs.

https://a2a-protocol.org/latest/topics/key-concepts/

请求示例

{
    "id": "90320f73-d6be-462f-bf3d-020ab5043924",
    "jsonrpc": "2.0",
    "method": "message/send",
    "params": {
        "configuration": {
            "acceptedOutputModes": [
                "text",
                "text/plain",
                "image/png"
            ]
        },
        "message": {
            "contextId": "f0b3fa91-b771-47c5-9ded-cd840e770d1b",
            "kind": "message",
            "messageId": "66675023-04aa-4584-8452-746f271f1c9a",
            "parts": [
                {
                    "kind": "text",
                    "text": "西雅图明天的天气怎么样?"
                }
            ],
            "role": "user"
        }
    }
}

{
    "id": "90320f73-d6be-462f-bf3d-020ab5043924",
    "jsonrpc": "2.0",
    "result": {
        "artifacts": [
            {
                "artifactId": "8401aa09-cb36-4d5c-8d75-ad8308d2c6c4",
                "description": "",
                "name": "天气查询结果",
                "parts": [
                    {
                        "kind": "text",
                        "text": "未来 3 天的天气如下:1. 明天(2025年6月1日):晴天;2. 后天(2025年6月2日):小雨;3. 大后天(2025年6月3日):大雨。"
                    }
                ]
            }
        ],
        "contextId": "f0b3fa91-b771-47c5-9ded-cd840e770d1b",
        "history": [
            {
                "contextId": "f0b3fa91-b771-47c5-9ded-cd840e770d1b",
                "kind": "message",
                "messageId": "66675023-04aa-4584-8452-746f271f1c9a",
                "parts": [
                    {
                        "kind": "text",
                        "text": "西雅图明天的天气怎么样?"
                    }
                ],
                "role": "user",
                "taskId": "e3ee4048-afca-47a9-9ba4-7e2553726c20"
            }
        ],
        "id": "e3ee4048-afca-47a9-9ba4-7e2553726c20",
        "kind": "task",
        "status": {
            "state": "completed"
        }
    }
}

叫法

  • A2A Client A2A Server
  • Client Agent Remote Agent

image.png

运行链路图

多智能体的交互:

附录

官方仓库:

https://github.com/a2aproject/a2a-samples/tree/main/samples/java/agents/weather_mcp

官方文档地址:

https://developers.googleblog.com/en/a2a-a-new-era-of-agent-interoperability/


标题:A2A协议拆解
作者:guobing
地址:http://guobingwei.tech/articles/2025/12/25/1766653951236.html