核心协议规范

A2A Protocol 的核心协议规范定义了协议使用的数据结构、交互模型和 API 端点。这些规范是确保不同 Agent 之间能够正确、一致地通信的基础。

基于 JSON Schema

核心协议规范主要通过 JSON Schema 文件进行定义。该 Schema 文件详细描述了协议中涉及的各种对象(如 AgentCard, Task, Artifact, Message, Part 等)的结构、字段、类型和约束。

您可以在 A2A Protocol 的官方 GitHub 仓库或相关发布中找到完整的 a2a.json Schema 文件。

核心数据结构示例

以下是从 JSON Schema 中提取的部分核心数据结构定义示例,以帮助理解其结构:

AgentCard

AgentCard 用于描述 Agent 的能力。

{
  "type": "object",
  "title": "AgentCard",
  "required": [
    "name",
    "url",
    "version",
    "capabilities",
    "skills"
  ],
  "properties": {
    "name": { "type": "string", "title": "Name" },
    "description": { "type": ["string", "null"], "title": "Description" },
    "url": { "type": "string", "title": "Url" },
    "provider": { "$ref": "#/$defs/AgentProvider" },
    "version": { "type": "string", "title": "Version" },
    "documentationUrl": { "type": ["string", "null"], "title": "Documentationurl" },
    "capabilities": { "$ref": "#/$defs/AgentCapabilities" },
    "authentication": { "$ref": "#/$defs/AgentAuthentication" },
    "defaultInputModes": { "type": "array", "items": { "type": "string" }, "default": ["text"] },
    "defaultOutputModes": { "type": "array", "items": { "type": "string" }, "default": ["text"] },
    "skills": { "type": "array", "items": { "$ref": "#/$defs/AgentSkill" } }
  }
}

Task

Task 代表一个交互任务。

{
  "type": "object",
  "title": "Task",
  "required": [
    "id",
    "status"
  ],
  "properties": {
    "id": { "type": "string", "title": "Id" },
    "sessionId": { "type": ["string", "null"], "title": "Sessionid" },
    "status": { "$ref": "#/$defs/TaskStatus" },
    "history": { "type": ["array", "null"], "items": { "$ref": "#/$defs/Message" } },
    "artifacts": { "type": ["array", "null"], "items": { "$ref": "#/$defs/Artifact" } },
    "metadata": { "$ref": "#/$defs/Metadata" }
  }
}

Artifact

Artifact 代表 Agent 生成的工件。

{
  "type": "object",
  "title": "Artifact",
  "required": [
    "parts",
    "index"
  ],
  "properties": {
    "name": { "type": ["string", "null"], "title": "Name" },
    "description": { "type": ["string", "null"], "title": "Description" },
    "parts": { "type": "array", "items": { "$ref": "#/$defs/Part" } },
    "metadata": { "$ref": "#/$defs/Metadata" },
    "index": { "type": "integer", "title": "Index" },
    "append": { "type": ["boolean", "null"], "title": "Append" },
    "lastChunk": { "type": ["boolean", "null"], "title": "Lastchunk" }
  }
}

Message

Message 用于传递非工件内容。

{
  "type": "object",
  "title": "Message",
  "required": [
    "role",
    "parts"
  ],
  "properties": {
    "role": { "$ref": "#/$defs/Role" },
    "parts": { "type": "array", "items": { "$ref": "#/$defs/Part" } },
    "metadata": { "$ref": "#/$defs/Metadata" }
  }
}

Part

Part 是消息或工件中的原子内容单元。

{
  "anyOf": [
    { "$ref": "#/$defs/TextPart" },
    { "$ref": "#/$defs/UriPart" },
    { "$ref": "#/$defs/DataPart" },
    { "$ref": "#/$defs/JsonPart" },
    { "$ref": "#/$defs/FormPart" },
    { "$ref": "#/$defs/IFramePart" },
    { "$ref": "#/$defs/VideoPart" },
    { "$ref": "#/$defs/AudioPart" },
    { "$ref": "#/$defs/ActionPart" }
  ],
  "title": "Part"
}

如何查阅完整规范

要深入了解协议的技术细节,包括所有字段、约束和枚举值,建议查找并查阅协议的官方 a2a.json 文件。

您可以使用任何支持 JSON Schema 查看的工具或编辑器来更好地理解其结构。

[如果 a2a.json 文件在线托管,可以在此提供链接]

理解核心协议规范对于希望实现 A2A Client 或 Server 的开发者至关重要。