【6G新技术探索】A2A协议介绍
博主未授权任何人或组织机构转载博主任何原创文章,感谢各位对原创的支持!
博主链接
本人就职于国际知名终端厂商,负责modem芯片研发。
在5G早期负责终端数据业务层、核心网相关的开发工作,目前牵头6G技术研究。
博客内容主要围绕:
5G/6G协议讲解
高级C语言讲解
Rust语言讲解
文章目录
- 【6G新技术探索】A2A协议介绍
- 一、什么是A2A?解决什么问题?
- 二、核心概念说明
- 2.1 核心参与者
- 2.2 通信基本元素
- 2.2.1 代理卡(Agent Card)
- 2.2.2 Task
- 2.2.3 Message
- 2.2.4 Part
- 2.2.5 Artifact
- 三、A2A中代理发现机制
- 3.1 代理卡的作用
- 3.2 发现策略
- 3.2.1 熟知的URI
- 3.2.2 基于注册中心(基于目录的发现)
- 3.2.3 直接配置或私有发现
- 3.3 AgentCard 数据对象结构
- 3.3.1 AgentProvider 对象
- 3.3.2 AgentCapabilities 对象
- 3.3.3 AgentExtension 对象
- 3.3.4 SecurityScheme 对象
- 3.3.5 AgentSkill 对象
- 3.3.6 代理卡例子
- 四、A2A中的流和异步操作
- 4.1 Streaming
- 4.2 Push Notification
- 五、A2A与MCP
- 5.1 MCP
- 5.2 A2A
- 5.3 A2A和MCP如何互补
【6G新技术探索】A2A协议介绍
A2A官方网站
一、什么是A2A?解决什么问题?
Agent2Agent (A2A) 协议是一项开放标准,旨在促进独立且可能不透明的 AI 代理系统之间的通信和互操作性。如果代理间使用不同的框架、语言或是由不同供应商构建的生态系统,那么A2A 提供了一种通用语言和交互模型。使用A2A可以,
- 增强互操作性:打破不同 AI 代理生态系统之间的孤岛,允许来自不同供应商和框架的代理协同工作;
- 增强的代理功能:允许开发人员通过组合多个专门代理的优势来创建更复杂的应用程序;
- 降低集成复杂性:标准化代理间的通信方式,使代理研发团队能够专注于代理自身功能;
- 促进创新:鼓励开发更丰富的专门代理生态系统,这些代理可以很容易地插入更大的协作工作流中;
- 面向未来:提供一个灵活的框架,可以随着代理技术的不断发展而适应;
二、核心概念说明
Agent2Agent (A2A) 协议围绕一组定义代理交互方式的核心概念构建。理解这些概念对于开发或集成符合 A2A 标准的系统至关重要。
2.1 核心参与者
- 用户:发起需要代理协助的请求或目标的最终用户(人工或自动化服务);
- A2A 客户端(客户端代理):代表用户向远程代理请求操作或信息的应用程序、服务或其他 AI 代理,客户端使用 A2A 协议发起通信;
- A2A 服务器(远程代理):AI 代理或代理系统,它会公开一个实现了 A2A 协议的 HTTP 端点。接收来自客户端的请求,处理任务,并返回结果或状态更新。从客户端的角度来看,远程代理是一个“不透明”的系统,这意味着客户端不需要了解其内部工作原理、内存或工具;
2.2 通信基本元素
2.2.1 代理卡(Agent Card)
一个JSON元数据文档,它描述了一个A2A服务器,它详细说明了代理身份、服务端点URL、版本、支持的A2A功能(如流或推送通知),它提供的特定技能,默认输入/输出模式和身份验证要求。客户端使用代理卡来发现代理,并了解如何安全有效地与他们互动。
2.2.2 Task
当客户端向代理发送消息时,每个任务都有一个由代理定义的唯一ID。如果任务是有状态的,可能涉及客户端和服务器之间的多轮信息交换。
2.2.3 Message
表示客户端和代理之间的单轮通信单元。消息有一个角色(对于客户端发送的消息是“用户”,对于服务器发送的消息是“代理”),并且包含一个或多个携带实际内容的Part对象。Message对象的messageId部分是消息发送方设置的每个消息的唯一标识符。
2.2.4 Part
Message 或 Artifact 中的基本内容单位。每个部分都有特定的类型,可以携带不同类型的数据:
- TextPart:包含纯文本内容;
- FilePart:表示一个文件,它可以作为内联 base64 编码字节传输或通过 URI 引用。包括元数据,如文件名和媒体类型;
- DataPart:携带结构化的 JSON 数据,用于表单、参数或任何机器可读的信息;
2.2.5 Artifact
表示远程代理在处理任务期间生成的有形输出或结果:
- 示例包括生成的文档、图像、电子表格、结构化数据结果或任何其他作为任务直接结果的自包含信息;
- Artifact 由一个或多个Part对象组成,并且可以增量地流化;
三、A2A中代理发现机制
对于使用Agent2Agent (A2A)协议进行协作的AI代理,它们首先需要找到彼此并了解其提供的功能。A2A通过代理卡
规范代理自我描述的格式。但是,发现这些代理卡的方法可能因环境和需求而异。
3.1 代理卡的作用
代理卡是一个 JSON 文档,可作为 A2A 服务器(远程代理)的数字“名片”。它对于发现和发起交互至关重要。代理卡中通常包含以下关键信息:
- 身份: name、description、provider信息;
- 服务端点:可以找到 A2A 服务的端点url;
- A2A 功能:类似支持 streaming 或 pushNotifications 的协议特性;
- 身份验证:需要身份验证 schemes(例如“Bearer”、“OAuth2”)才能与代理交互;
- 技能:代理可以执行的特定任务或功能的列表( AgentSkill 对象),包括它们的 id 、 name 、 descriptionin 、 putModes 、 outputModes 和 examples 。
客户端代理解析代理卡以确定远程代理是否适合给定的任务、如何构建其技能请求以及如何与其安全地通信。
3.2 发现策略
下面是客户端代理发现远程代理的常用策略:
3.2.1 熟知的URI
对于公共代理或希望在特定领域内获得广泛可发现性的代理,这是一种推荐的方法。
- 机制:A2A服务器在其域内的一个标准化的且熟知的路径上托管代理卡;
- 标准路径:https://{agent-server-domain}/.well-known/agent.json(遵循RFC 8615对驰名uri的原则);
- 过程:
- 客户端代理知道或通过编程发现潜在的A2A服务器的域名(例如,smart-thermostat.example.com);
- 客户端向 https://smart-thermostat.example.com/.well-known/agent.json 发起HTTP GET请求;
- 如果代理卡存在并且可访问,服务器将其作为JSON响应返回;
这种方式简单、标准化,可以通过爬虫或可以解析域名的系统自动发现。有效地将发现问题简化为“查找代理域”问题。最适合用于开放发现或在控制域的组织内发现的代理。如果代理卡包含敏感信息,则为代理卡提供服务的端点本身可能需要身份验证。
3.2.2 基于注册中心(基于目录的发现)
对于企业环境、市场或专门的生态系统,可以将代理卡发布到中心注册表或目录,并通过其发现。
- 机制:一个中介服务(注册中心)维护代理卡。客户端根据各种标准(例如,所提供的技能、标记、提供者名称、所需的功能)查询此注册中心以查找代理;
- 过程:
- A2A服务器(或管理员)向注册服务注册代理卡。这种注册机制超出了A2A协议本身的范围;
- 客户端代理查询注册表的API(例如,“查找具有支持流处理的‘图像生成’技能的代理”);
- 注册中心返回一个匹配的代理卡或对它们的引用列表;
这种方式实现了对可用代理的集中管理,实现了基于功能而不仅仅是域名的发现,能够在注册表级别实现访问控制、策略和信任机制。但是这种方式需要一个额外的注册中心服务。A2A协议目前还没有为此类注册中心定义标准API,尽管这是一个潜在的未来探索和社区标准化的领域。
3.2.3 直接配置或私有发现
在许多情况下,特别是在紧耦合的系统中,对于私有代理,或者在开发和测试期间,可能直接用代理卡信息或获取它的URL配置客户端。
- 机制:客户端应用硬编码代理卡的详细信息,从本地配置文件读取,通过环境变量接收,或从客户端已知的私有API端点获取;
- 流程:这与应用程序的部署和配置策略密切相关。
这种方式简单有效,适用于代理之间已知的静态关系,或者不需要动态发现的情况。但是这种方式不能够动态发现新的或更新的代理。对远程代理卡的更改可能需要重新配置客户端。基于专有api的发现并没有被A2A标准化。
3.3 AgentCard 数据对象结构
/*** An AgentCard conveys key information:* - Overall details (version, name, description, uses)* - Skills: A set of capabilities the agent can perform* - Default modalities/content types supported by the agent.* - Authentication requirements*/
export interface AgentCard {/*** The version of the A2A protocol this agent supports.* @default "0.2.5"*/protocolVersion: string;/*** Human readable name of the agent.* @TJS-examples ["Recipe Agent"]*/name: string;/*** A human-readable description of the agent. Used to assist users and* other agents in understanding what the agent can do.* @TJS-examples ["Agent that helps users with recipes and cooking."]*/description: string;/*** A URL to the address the agent is hosted at. This represents the* preferred endpoint as declared by the agent.*/url: string;/*** The transport of the preferred endpoint. If empty, defaults to JSONRPC.*/preferredTransport?: string;/*** Announcement of additional supported transports. Client can use any of* the supported transports.*/additionalInterfaces?: AgentInterface[];/** A URL to an icon for the agent. */iconUrl?: string;/** The service provider of the agent */provider?: AgentProvider;/*** The version of the agent - format is up to the provider.* @TJS-examples ["1.0.0"]*/version: string;/** A URL to documentation for the agent. */documentationUrl?: string;/** Optional capabilities supported by the agent. */capabilities: AgentCapabilities;/** Security scheme details used for authenticating with this agent. */securitySchemes?: { [scheme: string]: SecurityScheme };/** Security requirements for contacting the agent. */security?: { [scheme: string]: string[] }[];/*** The set of interaction modes that the agent supports across all skills. This can be overridden per-skill.* Supported media types for input.*/defaultInputModes: string[];/** Supported media types for output. */defaultOutputModes: string[];/** Skills are a unit of capability that an agent can perform. */skills: AgentSkill[];/*** true if the agent supports providing an extended agent card when the user is authenticated.* Defaults to false if not specified.*/supportsAuthenticatedExtendedCard?: boolean;
}
其中,
字段名称 | 类型 | 必选 | 描述 |
---|---|---|---|
protocolVersion | string | 是的 | 此代理支持的 A2A 协议版本 |
name | string | 是的 | 代理的人类可读名称 |
description | string | 是的 | 易于理解的描述,可以使用CommonMark |
url | string | 是的 | 代理 A2A 服务的基本 URL,必须是绝对 URL,生产环境请使用 HTTPS 协议 |
provider | AgentProvider | 不 | 有关代理提供商的信息 |
iconUrl | string | 不 | 代理图标的 URL |
version | string | 是的 | 代理或 A2A 实现版本字符串 |
documentationUrl | string | 不 | 代理的可读文档的 URL |
capabilities | AgentCapabilities | 是的 | 指定支持的可选 A2A 协议功能(例如流媒体、推送通知) |
securitySchemes | { [scheme: string]: SecurityScheme } | 不 | 用于与此代理进行身份验证的安全方案详细信息,未定义表示没有 A2A 通告的身份验证(不建议用于生产) |
security | { [scheme: string]: string[]; }或者[] | 不 | 进行通信的代理的安全要求 |
defaultInputModes | string[] | 是的 | 代理接受的输入媒体类型 |
defaultOutputModes | string[] | 是的 | 代理生成的输出媒体类型 |
skills | AgentSkill[] | 是的 | 技能数组,应该至少有一个技能 |
supportsAuthenticatedExtendedCard | boolean | 不 | 表示支持通过经过身份验证的端点检索更详细的代理卡 |
3.3.1 AgentProvider 对象
有关提供代理的组织或实体的信息。
/*** Represents the service provider of an agent.* @TJS-examples [{ "organization": "Google", "url": "https://ai.google.dev" }]*/
export interface AgentProvider {/** Agent provider's organization name. */organization: string;/** Agent provider's URL. */url: string;
}
字段名称 | 类型 | 必选 | 描述 |
---|---|---|---|
organization | string | 是的 | 组织/实体的名称 |
url | string | 是的 | 提供商网站/联系方式的 URL |
3.3.2 AgentCapabilities 对象
指定代理支持的可选 A2A 协议功能。
/*** Defines optional capabilities supported by an agent.*/
export interface AgentCapabilities {/** true if the agent supports SSE. */streaming?: boolean;/** true if the agent can notify updates to client. */pushNotifications?: boolean;/** true if the agent exposes status change history for tasks. */stateTransitionHistory?: boolean;/** extensions supported by this agent. */extensions?: AgentExtension[];
}
字段名称 | 类型 | 必选 | 默认 | 描述 |
---|---|---|---|---|
streaming | boolean | 不 | false | 表示支持 SSE 流方法(message/stream,tasks/resubscribe) |
pushNotifications | boolean | 不 | false | 表示支持推送通知方法(tasks/pushNotificationConfig/*) |
stateTransitionHistory | boolean | 不 | false | 未来功能的占位符:公开详细的任务状态变化历史记录 |
extensions | AgentExtension[] | 不 | [] | 此代理支持的扩展列表 |
3.3.3 AgentExtension 对象
指定代理支持的 A2A 协议的扩展。
/*** A declaration of an extension supported by an Agent.* @TJS-examples [{"uri": "https://developers.google.com/identity/protocols/oauth2", "description": "Google OAuth 2.0 authentication", "required": false}]*/
export interface AgentExtension {/** The URI of the extension. */uri: string;/** A description of how this agent uses this extension. */description?: string;/** Whether the client must follow specific requirements of the extension. */required?: boolean;/** Optional configuration for the extension. */params?: { [key: string]: any };
}
字段名称 | 类型 | 必选 | 描述 |
---|---|---|---|
uri | string | 是的 | 受支持扩展的 URI |
required | boolean | 不 | 代理是否要求客户端遵循特定于扩展程序的某些协议逻辑。当客户端尝试与需要其不支持的扩展程序的服务器交互时,应该预料到会失败 |
description | string | 不 | 关于代理如何使用扩展的描述 |
params | object | 不 | 特定于扩展的配置参数 |
3.3.4 SecurityScheme 对象
描述访问代理端点的身份验证要求url。
/*** Mirrors the OpenAPI Security Scheme Object* (https://swagger.io/specification/#security-scheme-object)*/
export type SecurityScheme =| APIKeySecurityScheme| HTTPAuthSecurityScheme| OAuth2SecurityScheme| OpenIdConnectSecurityScheme;
3.3.5 AgentSkill 对象
描述代理可以执行或解决的特定能力、功能或专业领域。
/*** Represents a unit of capability that an agent can perform.*/
export interface AgentSkill {/** Unique identifier for the agent's skill. */id: string;/** Human readable name of the skill. */name: string;/*** Description of the skill - will be used by the client or a human* as a hint to understand what the skill does.*/description: string;/*** Set of tagwords describing classes of capabilities for this specific skill.* @TJS-examples [["cooking", "customer support", "billing"]]*/tags: string[];/*** The set of example scenarios that the skill can perform.* Will be used by the client as a hint to understand how the skill can be used.* @TJS-examples [["I need a recipe for bread"]]*/examples?: string[]; // example prompts for tasks/*** The set of interaction modes that the skill supports* (if different than the default).* Supported media types for input.*/inputModes?: string[];/** Supported media types for output. */outputModes?: string[];
}
字段名称 | 类型 | 必选 | 描述 |
---|---|---|---|
id | string | 是的 | 此代理内的唯一技能标识符 |
name | string | 是的 | 人类可读的技能名称 |
description | string | 是的 | 详细的技能描述,可以使用CommonMark |
tags | string[] | 是的 | 可用于发现的关键字或类别 |
examples | string[] | 不 | 展示技能使用情况的示例提示或用例 |
inputModes | string[] | 不 | 此技能接受的媒体类型,会覆盖 defaultInputModes |
outputModes | string[] | 不 | 此技能产生的媒体类型,会覆盖 defaultOutputModes |
3.3.6 代理卡例子
{"protocolVersion": "0.2.9","name": "GeoSpatial Route Planner Agent","description": "Provides advanced route planning, traffic analysis, and custom map generation services. This agent can calculate optimal routes, estimate travel times considering real-time traffic, and create personalized maps with points of interest.","url": "https://georoute-agent.example.com/a2a/v1","provider": {"organization": "Example Geo Services Inc.","url": "https://www.examplegeoservices.com"},"iconUrl": "https://georoute-agent.example.com/icon.png","version": "1.2.0","documentationUrl": "https://docs.examplegeoservices.com/georoute-agent/api","capabilities": {"streaming": true,"pushNotifications": true,"stateTransitionHistory": false},"securitySchemes": {"google": {"type": "openIdConnect","openIdConnectUrl": "https://accounts.google.com/.well-known/openid-configuration"}},"security": [{ "google": ["openid", "profile", "email"] }],"defaultInputModes": ["application/json", "text/plain"],"defaultOutputModes": ["application/json", "image/png"],"skills": [{"id": "route-optimizer-traffic","name": "Traffic-Aware Route Optimizer","description": "Calculates the optimal driving route between two or more locations, taking into account real-time traffic conditions, road closures, and user preferences (e.g., avoid tolls, prefer highways).","tags": ["maps", "routing", "navigation", "directions", "traffic"],"examples": ["Plan a route from '1600 Amphitheatre Parkway, Mountain View, CA' to 'San Francisco International Airport' avoiding tolls.","{\"origin\": {\"lat\": 37.422, \"lng\": -122.084}, \"destination\": {\"lat\": 37.7749, \"lng\": -122.4194}, \"preferences\": [\"avoid_ferries\"]}"],"inputModes": ["application/json", "text/plain"],"outputModes": ["application/json","application/vnd.geo+json","text/html"]},{"id": "custom-map-generator","name": "Personalized Map Generator","description": "Creates custom map images or interactive map views based on user-defined points of interest, routes, and style preferences. Can overlay data layers.","tags": ["maps", "customization", "visualization", "cartography"],"examples": ["Generate a map of my upcoming road trip with all planned stops highlighted.","Show me a map visualizing all coffee shops within a 1-mile radius of my current location."],"inputModes": ["application/json"],"outputModes": ["image/png","image/jpeg","application/json","text/html"]}],"supportsAuthenticatedExtendedCard": true
}
四、A2A中的流和异步操作
A2A协议被设计用来处理不能立即完成的任务。许多人工智能驱动的操作可能是长期运行的,涉及多个步骤,产生增量结果,或需要人工干预。A2A提供了健壮的机制来管理这种异步交互,确保客户端可以有效地接收更新,无论它们保持持续连接还是以多次断开的方式操作。
4.1 Streaming
对于产生增量结果(如生成长文档或流媒体)或提供持续状态更新的任务,A2A支持使用服务器发送事件(Server-Sent Events, SSE)进行实时通信。当客户端可以与A2A服务器保持HTTP连接时这是最佳的选择。
关键流程:
- 初始化:客户端使用
message/stream
RPC方法发送初始消息,并同时订阅该任务的更新; - 服务器能力:A2A服务器必须通过在代理卡中设置
capabilities.streaming: true
来表明它支持Streaming; - 服务器响应(连接):如果订阅成功,服务器将使用HTTP 200 OK 状态和
Content-Type: text/event-stream
进行响应。此HTTP连接保持打开状态,以便服务器推送事件; - 构造事件:服务器通过该流发送事件。每个事件的 data 字段包含一个JSON-RPC 2.0响应对象,特别是一个
SendStreamingMessageResponse
。这个JSON-RPC响应中的 id 与来自客户端原始message/stream
请求的 id 一致; - 事件类型(在
SendStreamingMessageResponse.result
中):- Task:表示A2A服务器为A2A客户端处理的有状态工作单元;
- TaskStatusUpdateEvent:更新任务生命周期的状态变化(例如,从 working 到 input-required 或 completed)。它还可以提供来自代理的中间消息(例如,“我目前正在分析数据……”);
- TaskArtifactUpdateEvent:反馈新生成或更新的任务产物。该对象包含 append 和 lastChunk 等字段,以帮助客户端将多个数据块重新组装成完整的产物;
- 流终止:服务器通过在
TaskStatusUpdateEvent
中设置final: true
来标记特定交互周期的更新结束。这通常发生在任务达到终结状态(completed、failed、 canceled)或 input-required 状态(服务器期望从客户端获得进一步输入)时。在发送final: true
事件之后,服务器通常会为该特定请求关闭SSE连接; - 重新订阅:如果客户端的SSE连接在任务仍处于活动状态时过早断开(并且服务器没有为该阶段发送
final: true
事件),则客户端可以尝试使用tasks/resubscribe
RPC方法重新连接到流;
何时使用Streaming:
- 需要对长时间运行的任务进行实时进度监控;
- 增量接收大量的结果数据,可以在整个结果可用之前开始处理;
- 互动式、对话式交流,即时反馈或部分回应是有益的;
- 应用程序要求代理进行低延迟更新;
4.2 Push Notification
对于需要非常长时间运行的任务(例如,持续几分钟、几小时甚至几天),或者当客户端不能或不喜欢维护持久连接(如移动客户端或serverless 功能)时,A2A支持通过 Push Notification
进行异步更新。该机制允许A2A服务器在发生重大任务更新时主动通知客户端提供的webhook。
关键流程:
- 服务器能力:A2A服务器必须通过在代理卡中设置
capabilities.pushNotifications: true
来表明它支持 push Notifications; - 配置:客户端向服务器提供一个
PushNotificationConfig
;- 这个配置参数可以在以下过程中提供给服务端:
- 在初始
message/send
或message/stream
请求(通过TaskSendParams
中可选的pushNotification
参数); - 单独使用现有任务的
tasks/pushNotificationConfig/set
RPC方法;
- 在初始
- PushNotificationConfig 包含下面的参数:
- url:绝对HTTPS webhook URL,A2A服务器向该URL发送任务更新通知;
- token(可选):客户端生成的不透明字符串(例如,密钥或特定于任务的标识符)。服务器应该在通知请求中包含这个参数(例如,在像X-A2A-Notification-Token这样的自定义报头中),以便由客户端的webhook接收器进行验证;
- authentication(可选):一个
AuthenticationInfo
对象,指定A2A服务器应该如何对客户端的webhook URL进行身份验证。客户端(webhook的接收者)定义这些身份验证需求;
- 这个配置参数可以在以下过程中提供给服务端:
- 通知触发器:A2A服务器决定何时发送推送通知。通常,当任务达到重要的状态更新时,例如转换到终结状态(completed、failed、canceled、rejected)或 input-required 和 auth-required 状态,特别是在其相关的消息和产物完全生成并稳定之后,就会发生这种情况;
- 通知有效载荷:A2A协议本身并没有严格定义服务器发送到客户端 webhook 的推送通知的HTTP主体有效载荷。但是,通知应该包含足够的信息,以便客户端识别任务ID并理解更新的内容(例如,新的TaskState)。服务器可以发送最小的有效负载(只有Task ID和新状态)或更全面的有效负载(例如,摘要甚至完整的Task对象);
- 客户端行为:在收到推送通知(并成功验证其真实性和相关性)后,客户端通常使用包含任务ID的
tasks/get
RPC方法获取完整的、更新的task对象,包括任何新的产物或详细消息;
客户端侧如何处理 Push Notification 服务:
PushNotificationConfig.url
指向推送通知服务端点,此url是客户端上负责接收来自A2A服务器的HTTP POST通知的组件;- 职责包括:
- 验证收到的通知(即验证它来自合法的A2A服务器);
- 验证通知的相关性(例如,检查 token);
- 将通知或其内容转发给适当的客户端应用程序;
- 在简单的场景下(例如,本地开发),客户端应用程序本身可能直接暴露webhook端点;
- 在企业或生产环境中,这通常是一个健壮、安全的服务,可以处理传入的webhooks、调用者身份验证和路由消息(例如,到消息队列、内部API、移动推送通知网关或其他事件驱动系统);
更详细的业务流程和数据结构可以参考A2A协议
五、A2A与MCP
在人工智能代理开发领域,两种关键类型的协议正在出现,以促进互操作性:一种用于将代理连接到工具和资源,另一种用于实现代理到代理的协作。Agent2Agent(A2A)协议和模型上下文协议(MCP)处理这些不同但相关的需求。二者的区别在于代理交互的性质:
- 工具与资源:
- 它们通常是具有定义良好的结构化输入和输出的原语。它们执行特定的、通常是无状态的功能(例如,计算器、数据库查询API、天气查询服务);
- 他们的行为通常是可预测和交易的;
- 交互通常是单个请求-响应周期;
- 代理:
- 这些都是更加自主的系统。他们可以推理、计划、使用多种工具、在更长时间的交互中维持状态,并参与复杂的、通常是多回合的对话,以完成新颖或不断变化的任务;
- 它们的行为可能是突发的,比一个简单的工具更难以预测;
- 交互通常包括正在进行的任务、上下文共享和协商;
代理应用程序需要利用这两者:代理使用工具收集信息并执行操作,代理与其他代理协作以解决更广泛、更复杂的目标。
5.1 MCP
- 焦点:MCP规范了AI模型和代理如何连接工具、API、数据源和其他外部资源并与之交互;
- 机制:它定义了一种结构化的方式来描述工具功能(类似于大型语言模型中的函数调用),将输入传递给它们,并接收结构化的输出;
- 用例:
- 使LLM能够调用外部API(例如,获取当前股票价格);
- 允许代理使用特定参数查询数据库;
- 将代理连接到一组预定义的功能或服务;
- 生态系统:MCP旨在创建一个生态系统,在这个生态系统中,工具提供者可以轻松地将其服务暴露给各种AI模型和代理框架,代理开发者可以轻松地以标准化的方式使用这些工具;
5.2 A2A
- 焦点:A2A规范了独立的、通常不透明的AI代理如何作为同伴相互交流和合作;
- 机制:它为代理提供了一个应用层协议:
- 发现彼此的高级技能和能力(通过代理卡);
- 协商交互模式(文本、文件、结构化数据);
- 管理共享的、有状态的、可能长时间运行的任务;
- 交流会话上下文、指令和复杂的、多部分的结果;
- 用例:
- 客户服务代理将复杂的计费查询委托给专门的计费代理,维护客户交互的上下文;
- 旅行计划代理与不同的航班、酒店和活动预订代理进行协调,管理多阶段的预订流程;
- 随着时间的推移,智能体为协作项目交换信息和状态更新;
- 与工具交互的关键区别:与简单的工具调用相比,A2A允许更动态、有状态和潜在的多模态交互。使用A2A的代理作为代理进行通信,而不仅仅是调用一个离散函数。
5.3 A2A和MCP如何互补
A2A和MCP并不相互排斥;它们是高度互补的,并位于处理代理系统交互需求的不同层级。
其实A2A服务器(远程代理)也可以将一些技能暴露为 MCP 兼容的资源,特别是如果这些技能是定义良好的,并且可以以更类似于工具的无状态方式调用的话。在这种情况下,另一个代理可能通过 MCP 风格的工具描述(可能源自其代理卡)“发现”这个A2A代理的特定技能。不过,A2A的主要优势在于它支持更灵活、有状态和协作的交互,这超越了典型的工具调用。A2A是关于智能体在任务上的合作,而MCP更多是关于智能体可以使用的能力。通过利用A2A进行agent间协作和MCP进行工具集成,开发人员可以构建更强大、灵活和可互操作的AI系统。