3. 智能体技能与 Agent Card
A2A 智能体在做任何事情之前,需要先定义自己能做什么(技能),以及其他智能体或客户端如何了解这些能力(Agent Card)。
本教程使用位于 a2a-samples/samples/python/agents/helloworld/
的 helloworld 示例。
智能体技能
Agent Skill 描述智能体可以执行的一项具体能力或功能,它是告诉客户端“这个智能体擅长哪类任务”的基本单元。
AgentSkill(定义于 a2a.types)的主要属性:
id:技能的唯一标识;name:便于阅读的名称;description:对技能的详细说明;tags:用于分类和发现的关键词;examples:示例提示词或使用场景;input_modes/output_modes:支持的输入与输出媒体类型(如text/plain、application/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'],
)这是一个非常简单的技能:名为 “Echo Bot”,主要处理文本。
Agent Card
Agent Card 是 A2A 服务端公开的一份 JSON 文档,通常位于 /.well-known/agent-card.json 端点,相当于智能体的数字名片。
AgentCard(定义于 a2a.types)的主要属性:
name、description、version:基本身份信息;supported_interfaces:A2A 服务可被访问的端点与协议的有序列表;capabilities:支持的 A2A 特性,例如streaming或extended_agent_card;default_input_modes/default_output_modes:智能体默认的输入与输出媒体类型;skills:智能体提供的AgentSkill列表。
helloworld 示例这样定义公开的 Agent Card:
# 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],
)这张卡片说明:智能体名为 “Hello World Agent”,运行在 http://127.0.0.1:9999 上,使用 JSON-RPC 绑定与协议版本 1.0,支持文本交互与流式传输,并提供 echo_bot 技能。字段与语义的完整说明见智能体发现
与协议规范
。
下一步
下一步实现智能体的核心逻辑:智能体执行器 。