3. Agent Skills 和 Agent Card¶
在 A2A agent 能够执行任何操作之前,它需要定义它_能_做什么(它的技能)以及其他 agent 或客户端如何了解这些能力(它的 Agent Card)。
我们将使用位于 a2a-samples/samples/python/agents/helloworld/ 的 helloworld 示例。
Agent Skills¶
Agent Skill 描述了 agent 可以执行的特定能力或功能。它是一个构建块,告诉客户端 agent 适合处理什么类型的任务。
AgentSkill(在 a2a.types 中定义)的关键属性:
id:技能的唯一标识符。name:人类可读的名称。description:对技能功能的更详细解释。tags:用于分类和发现的关键词。examples:示例提示或使用场景。inputModes/outputModes:支持的输入和输出媒体类型(例如,"text/plain"、"application/json")。
在 __main__.py 中,您可以看到 Helloworld agent 的技能是如何定义的:
skill = AgentSkill(
id='hello_world',
name='Returns hello world',
description='just returns hello world',
tags=['hello world'],
examples=['hi', 'hello world'],
)
这个技能非常简单:它被命名为"Returns hello world",主要处理文本。
Agent Card¶
Agent Card 是一个 JSON 文档,A2A 服务器通常通过 .well-known/agent.json 端点提供。它就像是 agent 的数字化名片。
AgentCard(在 a2a.types 中定义)的关键属性:
name、description、version:基本身份信息。url:可以访问 A2A 服务的端点。capabilities:指定支持的 A2A 功能,如streaming或pushNotifications。defaultInputModes/defaultOutputModes:agent 的默认媒体类型。skills:agent 提供的AgentSkill对象列表。
helloworld 示例这样定义其 Agent Card:
# This will be the public-facing agent card
public_agent_card = AgentCard(
name='Hello World Agent',
description='Just a hello world agent',
url='http://localhost:9999/',
version='1.0.0',
defaultInputModes=['text'],
defaultOutputModes=['text'],
capabilities=AgentCapabilities(streaming=True),
skills=[skill], # Only the basic skill for the public card
supportsAuthenticatedExtendedCard=True,
)
这个卡片告诉我们 agent 名为"Hello World Agent",运行在 http://localhost:9999/,支持文本交互,并具有 hello_world 技能。它还表明使用公共认证,意味着不需要特定的凭证。
理解 Agent Card 至关重要,因为它是客户端发现 agent 并了解如何与之交互的方式。