专栏名称: 待字闺中
深度分析大数据、深度学习、人工智能等技术,切中实际应用场景,为大家授业解惑。间或,也会介绍国内外相关领域有趣的面试题。
目录
相关文章推荐
极客之家  ·  22k star,微软硬核开源,让 ... ·  昨天  
稀土掘金技术社区  ·  掘金 AI 编程社区- 人人都是 AI 编程家竞赛 ·  4 天前  
老刘说NLP  ·  两个有趣的工作:Huggingface知识图 ... ·  昨天  
伯乐在线  ·  为什么 DeepSeek ... ·  2 天前  
伯乐在线  ·  为什么 DeepSeek ... ·  2 天前  
51好读  ›  专栏  ›  待字闺中

详解A2A(Agent2Agent)协议

待字闺中  · 公众号  · 程序员  · 2025-04-12 11:06

正文

请到「今天看啥」查看全文



};
// The set of interaction modes that the agent
// supports across all skills. This can be overridden per-skill.
defaultInputModes : string []; // supported mime types for input
defaultOutputModes : string []; // supported mime types for output
// Skills are a unit of capability that an agent can perform.
skills : {
id : string ; // unique identifier for the agent's skill
name : string ; //human readable name of the skill
// 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 (e.g. "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. (e.g. "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)
inputModes ?: string []; // supported mime types for input
outputModes ?: string []; // supported mime types for output
}[];
}

内容很长,但是比较简单,我们用下图来表示:

完整的定义可以参考这里: https://github.com/sing1ee/a2a-agent-coder/blob/main/src/schema.ts

Task(任务)

任务是一个有状态的实体,允许客户端与远程代理协作以达成特定的结果并生成相应的输出。在任务内,客户端与远程代理之间会交换消息,远程代理则生成工件作为结果(代理即是 Agent)。

任务始终由客户端创建,而其状态则由远程代理决定。如果客户端需要,多个任务可以归属于同一个会话(通过可选的 sessionId 表示)。在创建任务时,客户端可以设置这个可选的 sessionId。

代理收到请求之后,可以采取以下几种行动:

  • • 立即满足请求

  • • 安排稍后执行的工作

  • • 拒绝请求

  • • 协商不同的执行方式

  • • 向客户端索要更多信息

  • • 委派给其他代理或系统

即使在完成目标后,客户端仍然可以请求更多信息或在同一任务的上下文中进行更改。例如,客户端可以请求:“画一只兔子的图片”,代理回应:“”,随后客户端又可以要求:“把它画成红色”。

任务不仅用于传递工件(结果)和消息(思考、指令等),还维护着任务的状态及其可选的历史记录,包括状态变化和消息记录。

这些特性非常重要,尤其是同一个任务的上下文,可以进行多轮的对话,这些状态,还有历史记录,都有保存,这个非常匹配现在以 Chat 形式为主的AI 交互。

任务的定义如下:

interface Task {
  idstring// unique identifier for the task
  sessionIdstring// client-generated id for the session holding the task.
  statusTaskStatus// current status of the task
  history?: Message[];
  artifacts?: Artifact[]; // collection of artifacts created by the agent.
  metadata?: Record<stringany>; // extension metadata
}
// TaskState and accompanying message.
interface TaskStatus {
  stateTaskState;
  message?: Message//additional status updates for client
  timestamp?: string// ISO datetime value
}
// sent by server during sendSubscribe or subscribe requests
interface TaskStatusUpdateEvent {
  idstring;
  statusTaskStatus;
  finalboolean//indicates the end of the event stream
  metadata?: Record<stringany>;
}
// sent by server during sendSubscribe or subscribe requests
interface TaskArtifactUpdateEvent {
  idstring;
  artifactArtifact;
  metadata?: Record<stringany>;
}
// Sent by the client to the agent to create, continue, or restart a task.
interface TaskSendParams {
  idstring;
  sessionId?: string//server creates a new sessionId for new tasks if not set
  messageMessage






请到「今天看啥」查看全文