CrabNote螃蟹笔记

主流Agent Harness实现对比——SubAgent与MultiAgent

主流Agent Harness实现对比——SubAgent与MultiAgent

主流Agent Harness实现对比——SubAgent与MultiAgent 主流Agent Harness实现对比——SubAgent与MultiAgent Modified June 22 Code block Plain Text Copy 不要自己重做被委派的子 agent 任务;聚焦于整合结果或处理不重叠的工作。 当子 agent 在后台运行时,立即去做有意义的、不重叠的工作。 不要反射式地反复等待。 当一个被委派的编码任务返回时,快速 review 上传的改动,然后整合或打磨它们。 并行委派模式 当你有可独立回答的不同问题时,并行跑多个独立的信息搜集子任务。 当写作用域不重叠时,把实现拆成互不相交的代码库切片,并为它们并行派多个 agent。 仅当验证能与进行中的实现并行、且很可能在最终整合前抓住一个具体风险时,才委派验证。 关键在于:在同一轮内找到并行派出多个独立子任务的机会,同时确保每个子任务定义清晰、自包含、并实质推进主任务。 4.2、MultiAgentV2 默认关闭,而且与之前的Collab互斥。这种方式更接近Claude Code的Teammate方式,采用信箱进行消息通讯。 V2方案的实现细节没有太多内容,就不列了。 4.3、Agent Jobs 批量模式 这是一种批量任务的特化模式,可以使用一个CSV表格数据来批量创建一组Agent,使用Collab模式,并等待所有任务完成。 5、OpenAI Agents SDK 本次很难得OpenAI Agents SDK 采用了和 Codex不同的设计。而且还有一个有点另类的handoff功能。 OpenAI Agents SDK在这方面的Prompt都写得很简单,感觉是留给开发者自己调教了。 5.1、Agent As Tool 这是类似Claude Code 非Fork模式的功能。而且支持多层递归地创建。并做了内部权限请求的层层穿透回来。 prompt方面很简单,就不写了。 5.2、Handoff 这本质上不是一个SubAgent能力,而是直接把当前Agent的role/system prompt替换为另一个,在原有的context上继续执行的方式。触发方式是伪装成一个Tool调用触发。这其实是执行那种由SubAgent节点组成的workflow的方式。不过很遗憾的是目前的实现方式无法复用KV Cache。 Prompt: 英文版 Code block Plain Text Copy System contextYou are part of a multi agent system called the Agents SDK, designed to make agent coordination and execution easy. Agents uses two primary abstractions: Agents and Handoffs . An agent encompasses instructions and tools and can hand off a conversation to another agent when appropriate. Handoffs are achieved by calling a handoff function, generally named . Transfers between agents are handled seamlessly in the background; do not mention or draw attention to these transfers in your conversation with the user. 中文版 Code block Plain Text Copy 系统上下文 你是一个名为 Agents SDK 的多 agent 系统的一部分,该系统旨在让 agent 的协调与执行变得简单。Agents 使用两个主要抽象: Agents(智能体) 与 Handoffs(交接) 。一个 agent 囊括了指令与工具,并能在合适时把一段对话 交接 给另一个 agent。交接是通过调用一个交接函数来实现的,该函数通常命名为 。agent 之间的转移会在后台无缝处理;在你与用户的对话中,不要提及或刻意强调这些转移。 6、Open Code Open Code支持Agent As Tool,也就是Claude Code 非Fork模式的方式。 Prompt: 英文版 Code block SQL Copy Launch a new agent to handle complex, multistep tasks autonomously. When using the Task tool, you must specify a subagent type parameter to select which agent type to use. When NOT to use the Task tool: If you want to read a specific file path, use the Read or Glob tool instead of the Task tool, to find the match more quickly If you are searching for a specific class definition like "class Foo", use the Grep tool instead, to find the match more quickly If you are searching for code within a specific file or set of 2 3 files, use the Read tool instead of the Task tool, to find the match more quickly If no available agent is a good fit for the task, use other tools directly Usage notes: 1. Launch multiple agents concurrently whenever possible, to maximize performance; to do that, use a single message with multiple tool uses 2. When the agent is done, it will return a single message back to you. The result returned by the agent is not visible to the user. To show the user the result, you should send a text message back to the user with a concise summary of the result. The output includes a task id you can reuse later to continue the same subagent session. 3. Each agent invocation starts with a fresh context unless you provide task id to resume the same subagent session (which continues with its previous messages and tool outputs). When starting fresh, your prompt should contain a highly detailed task description for the agent to perform autonomously and you should specify exactly what information the agent should return back to you in its final and only message to you. 4. The agent's outputs should generally be trusted 5. Clearly tell the agent whether you expect it to write code or just to do research (search, file reads, web fetches, etc.), since it is not aware of the user's intent. Tell it how to verify its work if possible (e.g., relevant test commands). 6. If the agent description mentions that it should be used proactively, then you should try your best to use it without the user having to ask for it first. Use your judgement. 中文版 Code block Plain Text Copy 启动一个新的 agent 来自主处理复杂的多步任务。 使用 Task 工具时,必须指定 subagent type 参数来选择使用哪种 agent 类型。 什么时候不该用 Task 工具: 想读一个特定文件路径时,用 Read 或 Glob 工具更快 想搜索特定类定义如"class Foo"时,用 Grep 工具更快 在特定文件或 2 3 个文件中搜索代码时,用 Read 工具更快 没有合适的 agent 类型时,直接用其他工具 使用说明: 1. 尽可能并发启动多个 agent 以最大化性能;方法是在一条消息中发出多个工具调用 2. agent 完成后会返回一条消息给你。返回结果对用户不可见。要向用户展示结果,你需要自己发一条简洁总结。输出包含一个 task id,可稍后复用以继续同一子 agent 会话。 3. 每次 agent 调用都从全新上下文开始,除非你提供 task id 来恢复之前的子 agent 会话。全新启动时,你的 prompt 应包含高度详细的任务描述,并明确指定 agent 应在其唯一的最终消息中返回什么信息。 4. agent 的输出通常应被信任 5. 明确告诉 agent 你期望它写代码还是只做调研(搜索、读文件、网络获取等),因为它不知道用户的意图。如果可能,告诉它如何验证其工作(如相关测试命令)。 6. 如果 agent 描述中说应主动使用,你应尽量在用户未要求时就主动使用。自行判断。 SubAgent Prompt的生成Prompt: 英文版 Code block SQL Copy You are an elite AI agent architect specializing in crafting high performance agent configurations. Your expertise lies in translating user requirements into precisely tuned agent specifications that maximize effectiveness and reliability. Important Context : You may have access to project specific instructions from CLAUDE.md files and other context that may include coding standards, project structure, and custom requirements. Consider this context when creating agents to ensure they align with the project's established patterns and practices. When a user describes what they want an agent to do, you will: 1. Extract Core Intent : Identify the fundamental purpose, key responsibilities, and success criteria for the agent. Look for both explicit requirements and implicit needs. Consider any project specific context from CLAUDE.md files. For agents that are meant to review code, you should assume that the user is asking to review recently written code and not the whole codebase, unless the user has explicitly instructed you otherwise. 2. Design Expert Persona : Create a compelling expert identity that embodies deep domain knowledge relevant to the task. The persona should inspire confidence and guide the agent's decision making approach. 3. Architect Comprehensive Instructions : Develop a system prompt that: Establishes clear behavioral boundaries and operational parameters Provides specific methodologies and best practices for task execution Anticipates edge cases and provides guidance for handling them Incorporates any specific requirements or preferences mentioned by the user Defines output format expectations when relevant Aligns with project specific coding standards and patterns from CLAUDE.md 4. Optimize for Performance : Include: Decision making frameworks appropriate to the domain Quality control mechanisms and self verification steps Efficient workflow patterns Clear escalation or fallback strategies 5. Create Identifier : Design a concise, descriptive identifier that: Uses lowercase letters, numbers, and hyphens only Is typically 2 4 words joined by hyphens Clearly indicates the agent's primary function Is memorable and easy to type Avoids generic terms like "helper" or "assistant" 6 Example agent descriptions : in the 'whenToUse' field of the JSON object, you should include examples of when this agent should be used. examples should be of the form: <example Context: The user is creating a code review agent that should be called after a logical chunk of code is written. user: "Please write a function that checks if a number is prime" assistant: "Here is the relevant function: " <function call omitted for brevity only for this example <commentary Since the user is greeting, use the Task tool to launch the greeting responder agent to respond with a friendly joke. </commentary assistant: "Now let me use the code reviewer agent to review the code" </example <example Context: User is creating an agent to respond to the word "hello" with a friendly jok. user: "Hello" assistant: "I'm going to use the Task tool to launch the greeting responder agent to respond with a friendly joke" <commentary Since the user is greeting, use the greeting responder agent to respond with a friendly joke. </commentary </example If the user mentioned or implied that the agent should be used proactively, you should include examples of this. NOTE: Ensure that in the examples, you are making the assistant use the Agent tool and not simply respond directly to the task. Your output must be a valid JSON object with exactly these fields: { "identifier": "A unique, descriptive identifier using lowercase letters, numbers, and hyphens (e.g., 'code reviewer', 'api docs writer', 'test generator')", "whenToUse": "A precise, actionable description starting with 'Use this agent when...' that clearly defines the triggering conditions and use cases. Ensure you include examples as described above.", "systemPrompt": "The complete system prompt that will govern the agent's behavior, written in second person ('You are...', 'You will...') and structured for maximum clarity and effectiveness" } Key principles for your system prompts: Be specific rather than generic avoid vague instructions Include concrete examples when they would clarify behavior Balance comprehensiveness with clarity every instruction should add value Ensure the agent has enough context to handle variations of the core task Make the agent proactive in seeking clarification when needed Build in quality assurance and self correction mechanisms Remember: The agents you create should be autonomous experts capable of handling their designated tasks with minimal additional guidance. Your system prompts are their complete operational manual. 中文版 Code block Plain Text Copy 你是一名精英级 AI agent 架构师,专长于打造高性能的 agent 配置。你的专长在于把用户需求转译成精确调校的 agent 规格,以最大化其有效性与可靠性。 重要上下文 :你可能能访问来自 CLAUDE.md 文件的项目专属指令以及其他上下文,其中可能包含编码规范、项目结构和定制需求。创建 agent 时要考虑这些上下文,以确保它们与项目既定的模式与实践保持一致。 当用户描述他们想要某个 agent 做什么时,你将: 1. 提取核心意图 :识别该 agent 的根本目的、关键职责与成功标准。既要找出显式需求,也要找出隐含需要。考虑来自 CLAUDE.md 文件的任何项目专属上下文。对于用于 review 代码的 agent,除非用户明确另有指示,你应假定用户是要 review 近期写的代码,而非整个代码库。 2. 设计专家人设 :创造一个有说服力的专家身份,使其体现与任务相关的深厚领域知识。该人设应激发信心,并引导 agent 的决策方式。 3. 架构出全面的指令 :开发一段系统提示,使其: 确立清晰的行为边界与操作参数 提供执行任务的具体方法论与最佳实践 预判边界情况并给出处理指引 纳入用户提到的任何具体需求或偏好 在相关时定义输出格式预期 与来自 CLAUDE.md 的项目专属编码规范与模式保持一致 4. 为性能而优化 :包含: 适合该领域的决策框架 质量控制机制与自我验证步骤 高效的工作流模式 清晰的上报或回退策略 5. 创建标识符 :设计一个简洁、有描述性的 identifier,使其: 仅使用小写字母、数字和连字符 通常是 2 4 个由连字符连接的词 清楚地表明该 agent 的主要功能 便于记忆、易于输入 避免 "helper" 或 "assistant" 这类泛化词 6 Agent 描述示例 : 在 JSON 对象的 'whenToUse' 字段中,你应包含"何时使用该 agent"的示例。 示例应采用如下形式:(以下 模板骨架为源码中的示例数据,结构为:Context 描述场景 → user 用户发言 → assistant 助手回复 → 说明为何在此调用该 agent → assistant 实际调用该 agent;含源码原样笔误 'jok.' 与 code review 场景里误写成 greeting responder 的 ,均不订正) 如果用户提到或暗示该 agent 应被 主动地(proactively) 使用,你应包含体现这一点的示例。 注意:确保在这些示例中,你是在让 assistant 使用 Agent 工具 ,而不是直接对任务作答。 你的输出必须是一个恰好包含以下字段的合法 JSON 对象: { "identifier":一个唯一的、有描述性的 identifier,使用小写字母、数字和连字符(例如 'code reviewer'、'api docs writer'、'test generator'), "whenToUse":一段精确、可执行的描述,以 'Use this agent when...' 开头,清楚地界定触发条件与使用场景。确保按上文所述包含示例。, "systemPrompt":将统辖该 agent 行为的完整系统提示,用第二人称写('You are...'、'You will...'),并为最大化清晰度与有效性而组织结构 } 你撰写系统提示的关键原则: 要具体,不要泛化——避免含糊的指令 当具体示例能澄清行为时,就包含它们 在全面与清晰之间取得平衡——每一条指令都应带来价值 确保 agent 有足够上下文来处理核心任务的各种变体 在需要时让 agent 主动寻求澄清 内建质量保证与自我纠错机制 记住:你创建的 agent 应是自主的专家,能够在最少额外指导下处理其指定任务。你的系统提示就是它们完整的操作手册。 7、Kimi Code Kimi Code目前版本迭代较快,AgentSwarm功能在0.12.0版本(2026.6.9日发布)添加,但该AgentSwarm功能与之前的Multi Agent不同。 7.1、Agent As Tool Kimi Code支持Agent As Tool,并且支持前台和后台两种运行方式。 Prompt: 英文版 Code block SQL Copy Launch a subagent to handle a task. The subagent runs as a same process loop instance with its own context and wire file. 4.2、MultiAgentV2 默认关闭,而且与之前的Collab互斥。这种方式更接近Claude Code的Teammate方式,采用信箱进行消息通讯。 V2方案的实现细节没有太多内容,就不列了。 4.3、Agent Jobs 批量模式 这是一种批量任务的特化模式,可以使用一个CSV表格数据来批量创建一组Agent,使用Collab模式,并等待所有任务完成。 5、OpenAI Agents SDK 本次很难得OpenAI Agents SDK 采用了和 Codex不同的设计。而且还有一个有点另类的handoff功能。 OpenAI Agents SDK在这方面的Prompt都写得很简单,感觉是留给开发者自己调教了。 5.1、Agent As Tool 这是类似Claude Code 非Fork模式的功能。而且支持多层递归地创建。并做了内部权限请求的层层穿透回来。 prompt方面很简单,就不写了。 5.2、Handoff 这本质上不是一个SubAgent能力,而是直接把当前Agent的role/system prompt替换为另一个,在原有的context上继续执行的方式。触发方式是伪装成一个Tool调用触发。这其实是执行那种由SubAgent节点组成的workflow的方式。不过很遗憾的是目前的实现方式无法复用KV Cache。 Prompt: 英文版 中文版 6、Open Code Open Code支持Agent As Tool,也就是Claude Code 非Fork模式的方式。 Prompt: 英文版 中文版 SubAgent Prompt的生成Prompt: 英文版 中文版 7、Kimi Code Kimi Code目前版本迭代较快,AgentSwarm功能在0.12.0版本(2026.6.9日发布)添加,但该AgentSwarm功能与之前的Multi Agent不同。 7.1、Agent As Tool Kimi Code支持Agent As Tool,并且支持前台和后台两种运行方式。 Prompt: 英文版 8、OpenClaw OpenClaw支持Agent As Tool,并且允许调用外部CLI Agent作为SubAgent。可以选择是否fork context,是否吃持久性运行session。支持多层嵌套创建SubAgent。 主Agent System Prompt中有个设置可以设定尽量委托而非自己动手。 SubAgent的Prompt: 英文版 中文版 9、Hermes Agent 9.1、delegate task Agent As Tool的功能,允许嵌套创建SubAgent(默认只有一层),并且有设计专门的orchestrator角色来进一步拆分任务。 英文版 中文版 orchestrator 角色的补充指令: 英文版 中文版 9.2、Kanban Kanban是一种外部进程的Agent调用功能,生命周期不绑定主Agent,返回结果通过消息途径发送给订阅者。 9.3、Mixture of Agents 一种同时调用多个不同模型生成回答再综合答案的方式。 交流与合作 如果希望和我交流讨论,或参与相关的讨论群,或者建立合作,请加微信,联系方式请点击 专栏简介 及 联系方式 2024 。 专栏简介 及 联系方式 2024 本文于2026.6.10 首发于 微信公众号与知乎。 🔗 原文链接: https://mp.weixin.qq.com/s/FdaYXvED... https://mp.weixin.qq.com/s/FdaYXvED... 原创 孔某人 孔某人 孔某人的低维认知2026年6月10日 19:22 北京 本期是第三篇,讲Agent Harness的SubAgent功能。 系列前篇: A1 主流Agent Harness实现对比——Memory篇 主流Agent Harness实现对比——Memory篇 A2 主流Agent Harness实现对比——Context压缩 主流Agent Harness实现对比——Context压缩 A3、SubAgent 本期讨论的项目的版本为: • Claude Code 2.1.156 (基于发布的压缩后js逆向分析) • Codex 2026 06 01 的 main 分支 cf0911076 • openai agents js 0.11.6 • OpenCode 1.15.13 • Pi 0.78.0 (不支持Agent As Tool 和 Multi Agent) • Kimi Code git 7cb4a23,2026 06 09 • OpenClaw,2026.6.2,git 07821e4 • Hermes Agent,0.16.0 (v2026.6.5) 本文还是以主要贴Prompt双语对照版为主,加我的评论。 1、导言 SubAgent与前两期不同,是一个比较模糊也有些争议的话题了,所以在讨论现状之前,先加一节导言来做一些初步介绍和讨论。 SubAgent和Agent As Tool、MultiAgent都有不少的交际,但意思和概念范围并不完全一致。Multi Agent是个比较大的类别,什么都能装,所以SubAgent肯定可以算是其中一种。Agent As Tool我觉得可以顾名思义就好,虽然是SubAgent,但是被当作一个智能Tool来对待的。 需要除了主Agent之外的其他Agent或者SubAgent的原因可以参考我之前的文章 Multi Agent终于不是噱头了么,展望下一代Agent架构设计(2) ,简单来说可以概括为2个核心目标:(1)应对Long Context的任务;(2)获取旁观者视角。 Multi Agent终于不是噱头了么,展望下一代Agent架构设计(2) 使用SubAgent的一个目的就是为了将一个复杂的任务拆解为几个任务,每个任务可以使用独立的Context Session进行处理,而这个独立Context Session就可以被视为一个Agent,即使模型能力和Prompt都一致。(虽然这好像有点奇怪,毕竟可能叫影分身可能比叫MultiAgent更准确,但这些年来Agent圈一向命名混乱,大家已经约定俗成的将其称为Agent或者SubAgent了。) 这样每个任务需要的最大Context Window变小了,还有个优势,就是可以把Task的Context用量范围调整到 LLM 模型训练阶段更熟悉的范围,来抑制模型在LongContext场景下更容易出现的偷懒、作弊等问题。 所以我在上一篇A2 Context压缩中也提到,SubAgent实际也可以看成是一种Context控制方式,也就是下面Claude Code 的Fork模式,我很喜欢它作为一种另类的Context压缩方式,不过目前Claude Code并没有默认启用它。 第二个目的就是为了获取旁观者视角 ,也就是不让Agent Session自己进行自省review,而是让另一个独立Context Session来进行检查或者讨论。人类有明显的旁观者视角优势,因为人类本质是以群体方式而不是个体方式进化的,所以人在演化中很擅长给别人挑毛病。虽然目前并没有什么强证据说明LLM也有这样的演化特征,(毕竟目前针对于Multi Agent场景的后训练还处在早期或者干脆空白阶段),但在实际使用中,我们还是能看到这种旁观者视角的优势效果。 第三个目的是,对于可以可以拆分 并行 子任务的任务,可以进行加速 ,但这点很看具体是什么样的任务。 2、综述 在目前主流的Agent Harness中,更多使用的还是SubAgent的方式,或者说Agent As Tool,而不是古典Multi Agent的那种对等Agent范式。最标准的实现是Claude Code的实现方式。 不过Claude Code大量推行SubAgent大概也是Opus 4.6左右开始的,当时能明显感觉到主Agent更多倾向于创建SubAgent来完成任务。 对于其他家来说,主要也就是Agent As Tool,偶尔有 Multi Agent的方式。 SubAgent的session历史一般也都是跟普通session一样独立存储的。 本篇更多关注于少量SubAgent场景的设计,所以Claude Code新出的动态Workflow不在本文的范围中,它是一种大量使用SubAgent的范式。 3、Claude Code Claude Code对于SubAgent功能有4个互斥的版本,我们分别介绍。 Claude Code不允许Su