A2A 协议中 Agent Skill 与 Agent Card 的定义方式

介绍 A2A 协议里 Agent Skill 与 Agent Card 的作用和字段构成,并以 helloworld 示例展示技能对象与公开卡片的定义方式,说明客户端如何据此发现智能体能力。

## 3. 代理技能与代理卡[¶](<https://a2a-protocol.org/latest/tutorials/python/3-agent-skills-and-card/#3-agent-skills-agent-card>) 在A2A代理能够做任何事情之前,它需要定义它是什么 *能够* 做(它的技能),以及其他特工或客户如何发现这些能力(它的代理卡). 我们用一下 `helloworld` 实例位于 [`a2a-samples/samples/python/agents/helloworld/`](<https://github.com/a2aproject/a2a-samples/tree/main/samples/python/agents/helloworld>). ## 代理技能[¶](<https://a2a-protocol.org/latest/tutorials/python/3-agent-skills-and-card/#agent-skills>) 一个 **特工技能** 描述代理能够执行的特定能力或功能。它是一个构件,可以告诉客户该代理的哪些任务是好的。 a 属性 `AgentSkill` (定义于 `a2a.types`): - `id`:该技能的独特标识符. - `name`:一个人可读的名字. - `description`:更详细地解释技能的作用. - `tags`:分类和发现的关键词. - `examples`:样本提示或使用案例。 - `input_modes` / `output_modes`: 支持输入和输出的媒体类型(如"文本/平面","应用程序/json"). - `security_requirements`: 这种技能所需的安全计划。 内 `__main__.py`,您可以看到 Helloworld 代理的技巧是如何定义的: ``` # Defines the abilities or functions that agent can perform. skill = AgentSkill( id='echo_bot', name='Echo Bot', description='An example agent that acknowledges client request and responds with a "Hello World" message.', input_modes=['text/plain'], output_modes=['text/plain'], tags=['a2a', 'echo-example'], examples=['hi', 'how are you'], ) ``` 这种技能非常简单:它被命名为"回归好友世界"(Returns hello world),主要处理文字. ## 代理卡[¶](<https://a2a-protocol.org/latest/tutorials/python/3-agent-skills-and-card/#agent-card>) 那个... **代理卡** 是一个 JSON 文档, 一个 A2A 服务器提供的, 通常在一个 `.well-known/agent-card.json` 终点,就像代理商的数码名片 a 的关键属性 `AgentCard` (定义于 `a2a.types`): - `name`, `description`, `version`: 基本身份资料. - `supported_interfaces`: 排序的端点和协议列表,其中可以实现A2A服务. - `capabilities`: 支持的 A2A 特性如 `streaming` 或 时 间 `extended_agent_card`. - `default_input_modes` / `default_output_modes`: 代理机的默认介质类型。 - `skills`: 清单 `AgentSkill` 代理商提供的对象。 那个... `helloworld` 示例对它的代理卡进行这样的定义 : ``` # Define a public-facing agent card that allows clients to discover your agent's capabilities. public_agent_card = AgentCard( # Basic identity information of A2A server name='Hello World Agent', # Identity description='Just a hello world agent', version='0.0.1', # Default Media Types for the agent's interactions default_input_modes=['text/plain'], # Supported media types default_output_modes=['text/plain'], # Supported A2A features (like streaming or extended config) capabilities=AgentCapabilities(streaming=True, extended_agent_card=True), # Ordered list of endpoints and protocols where the service can be reached supported_interfaces=[ AgentInterface( protocol_binding='JSONRPC', url='http://127.0.0.1:9999', protocol_version='1.0', ) ], # The list of AgentSkill objects that this agent offers skills=[skill], # Optional attributes (omitted here for simplicity): # icon_url -> A URL to an icon representing the agent ) ``` 这张卡告诉我们经纪人叫"Hello World Agent" 可以运行在 `http://127.0.0.1:9999/`中,支持文本交互,并具有 `hello_world` 技术。

查看原始来源