3. Agent 技能与 Agent 卡片¶
在 A2A agent 执行任何操作之前,它需要定义自己能做什么(它的技能)以及其他 agent 或客户端如何了解这些能力(它的 Agent 卡片)。
我们将使用位于 a2a-samples/samples/python/agents/helloworld/ 的 helloworld 示例。
Agent 技能¶
Agent 技能描述了 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'],
)
这个技能非常简单:它被命名为“返回 hello world”,主要处理文本。
Agent 卡片¶
Agent 卡片是 A2A 服务器提供的 JSON 文档,通常在 .well-known/agent-card.json 端点。它就像 agent 的数字名片。
AgentCard 的关键属性(在 a2a.types 中定义)
name,description,version:基本身份信息。url:可以访问 A2A 服务的端点。capabilities:指定支持的 A2A 功能,如streaming或pushNotifications。defaultInputModes/defaultOutputModes:agent 的默认媒体类型。skills:agent 提供的AgentSkill对象列表。
helloworld 示例这样定义它的 Agent 卡片
# This will be the public-facing agent card
public_agent_card = AgentCard(
name='Hello World Agent',
description='Just a hello world agent',
url='https://:9999/',
version='1.0.0',
default_input_modes=['text'],
default_output_modes=['text'],
capabilities=AgentCapabilities(streaming=True),
skills=[skill], # Only the basic skill for the public card
supports_authenticated_extended_card=True,
)
此卡片告诉我们该 agent 名为“Hello World Agent”,运行在 https://:9999/,支持文本交互,并具有 hello_world 技能。它还指示了公共身份验证,这意味着不需要特定的凭据。
理解 Agent 卡片至关重要,因为它是客户端发现 agent 并了解如何与其交互的方式。