Anthropic建议将子智能体折叠进主循环以优化性能
Building agents: When to fold subagents into your main agent loop | Claude by Anthropic
Agent 架构师必读,Anthropic 直接给出了从多智能体迁移到单循环的实操路径和避坑指南,能显著降低延迟和成本。
If you’ve built an agent in Claude Platform that includes multiple subagents, see which may make sense to fold into the main agent loop using our migration kit. It runs a guided workflow to identify your patterns, evaluate alternatives, and verify the best approach. It includes a demo that you can try on a mock system before running on your agent.
如果您在 Claude Platform 上构建的代理包含多个子代理,请参阅我们的迁移工具包,了解哪些子代理适合折叠到主代理循环中。该工具包提供引导式工作流程,用于识别您的模式、评估替代方案并验证最佳方法。它还包含一个演示,您可以在实际应用于自己的代理之前,先在模拟系统上进行尝试。
Subagents – agents with their own context window, tools, and instructions, orchestrated by a coordinator – are a core component of agent design. They are effective at verification, parallel work, and modular permissioning. We use them in many of our own agents that we build using Claude Platform, for example our multi-agent research system.
子代理——拥有独立上下文窗口、工具和指令,并由协调器编排的代理——是代理设计的核心组件。它们在验证、并行工作和模块化权限控制方面非常有效。我们在许多使用 Claude Platform 构建的自有代理中也使用了子代理,例如我们的多代理研究系统。
However, recently the Applied AI team has found a pattern of enterprise agent deployments that have benefited from folding routers, planners, and domain subagents into the main agent loop. In our comparisons across several enterprise deployments, a single agent with skills frequently outperformed both the one-prompt-for-everything design and the subagent design on quality, and often at a lower cost and latency per task.
然而,最近应用 AI 团队发现了一种企业级代理部署模式:将路由器、规划器和领域子代理折叠到主代理循环中会带来益处。在跨多个企业部署的比较中,具备多种技能的单一代理在质量上通常优于“一切皆用单提示词”的设计以及子代理设计,并且往往以更低的任务成本和延迟实现。
For example, one company found the dozen of specialist subagents within its customer-facing agent made a consistent on-brand experience difficult to maintain and added latency that hurt the user experience.
例如,某公司发现其面向客户的代理中包含的十几个专家型子代理,使得维持一致的品牌体验变得困难,并增加了损害用户体验的延迟。
We also often see proposed agent designs that follow a familiar progression: an intent classifier, a fixed multi-step reasoning pipeline, user-segment buckets, separate recommendation branches, and a multi-agent orchestrator on top.
我们还经常看到遵循熟悉演进路径提出的代理设计方案:意图分类器、固定的多步推理流水线、用户细分桶、独立的推荐分支,以及顶层的多代理协调器。
In these cases feedback is often that most of this structure was doing work the model no longer needed done for it, and that one clear system prompt, 4-5 thin data tools, and firm output guardrails would cover most of the use case.
在这些情况下,反馈通常是:这种结构中的大部分工作实际上是模型不再需要代为完成的;而一个清晰明确的系统提示词、4-5 个轻量数据工具以及严格的输出护栏即可覆盖大多数用例。
To be clear, subagents still have their place, including at the research frontier. Use them when:
明确地说,子代理仍有其适用场景,包括在研究前沿领域。请在以下情况使用它们:
- A single agent loop hits measurable performance degradation from context bloat, or
- Multiple tasks need to be tackled in parallel with fresh context windows that can be discarded once the task is done, or
- A single agent struggles to select appropriate tools or there are conflicting instructions in the system prompt.
- 单一代理循环因上下文膨胀而出现可衡量的性能下降,或者
- 需要并行处理多个任务,且这些任务可使用独立的上下文窗口,并在任务完成后丢弃,或者
- 单一代理难以选择合适的工具,或系统提示词中存在冲突的指令。
But too often we see enterprises give each team or problem type its own subagent, with the agent architecture becoming a copy of their org chart (Conway’s law at work).
但更常见的情况是,企业为每个团队或问题类型都分配一个独立的子代理,导致代理架构成为其组织架构图的翻版(康威定律在起作用)。
This post explains when to consider folding subagents into your main agent loop with best practices we’ve learned from building agents in large organizations.
本文解释了何时考虑将子智能体折叠到主智能体循环中,并分享了我们在大型组织中构建智能体时学到的最佳实践。
Agent building failure modes for large organizations
大型组织构建智能体的失败模式
Companies often want to build an agent that unites multiple products and capabilities into a single customer interface.
公司通常希望构建一个智能体,将多个产品和功能整合到一个客户界面中。
Typically, each capability is owned by a separate team, so companies start by letting each individual team build their own agent, then a central platform team builds an orchestrator on top. This can take on several structures including orchestrator-subagent or a single agent with specific agents exposed as MCP tools.
通常,每个功能由不同的团队负责,因此公司会先让各个团队分别构建自己的智能体,然后由中央平台团队在其之上构建一个编排器(orchestrator)。这可以呈现多种结构,包括编排器-子智能体架构,或单个智能体并将特定智能体作为 MCP 工具暴露出来。
This looks like the simplest solution but introduces immediate complexity around:
这看起来是最简单的解决方案,但会立即引入围绕以下方面的复杂性:
- Context management: You need to decide what context is exchanged between agents and often lose details in the back and forth.
- Subagent sprawl: Every team ships its own subagent, so companies end up with hundreds of overlapping subagents with no enforced standards and no specific owner.
- The Frankenprompt: Every team adds a sentence to the system prompt, resulting in conflicting rules and no consistent voice.
- Unvetted, overly localized evals: Everyone adds their own evals that are overly optimized for their subtask. No one owns or maintains the whole set, and leadership makes decisions based on watered-down, overly localized scores.
- Latency: Multi-agent architectural complexity adds latency. One customer that evaluated their multi-agent harness against a single agent loop saw a roughly 2x faster runtime with the latter.
- 上下文管理:你需要决定在智能体之间交换哪些上下文,并且往往在来回交互中丢失细节。
- 子智能体泛滥:每个团队都发布自己的子智能体,导致公司最终拥有数百个重叠的子智能体,缺乏强制执行的标准且没有明确的所有者。
- 弗兰肯提示词(Frankenprompt):每个团队都在系统提示词中添加一句话,导致规则冲突且没有一致的语气。
- 未经审核、过度局部化的评估:每个人都添加针对其子任务过度优化的评估指标。没有人负责维护整套评估体系,而领导层却基于被稀释的、过度局部化的分数做出决策。
- 延迟:多智能体架构的复杂性增加了延迟。某客户将其多智能体框架与单智能体循环进行对比评估后发现,后者的运行速度快了约 2 倍。
Using an agent loop with progressive disclosure
使用带有渐进式披露的智能体循环
The orchestrator-subagent design described above is a reasonable approach to coordinating specialists built across teams, but often a more effective approach can be progressively disclosing context via skills and progressively disclosing tools via tool search. In other words, the agent sees short descriptions of the skills and tools, which are fully loaded only when needed.
上述编排器-子智能体设计是协调跨团队构建的专业智能体的合理方法,但更有效的方法通常是:通过技能渐进式地披露上下文,并通过工具搜索渐进式地披露工具。换句话说,智能体仅看到技能和工具的简短描述,仅在需要时才完全加载它们。
There are three reasons why this approach can make sense:
这种方法之所以合理,主要有三个原因:
- Shared context produces better answers: for longer-running agents, we want the context from several different tasks to sit in the main context window. An agent that has seen the result of each earlier step can connect them, which leads to richer outputs and better insights than a set of summaries handed back by subagents. It also means fewer context windows and fewer lossy handoffs.
- Progressive disclosure prevents context bloat: this technique allows teams to build single agents that can accomplish a wide variety of tasks without requiring all of the context to be immediately loaded into one long system prompt. This removes the main reason teams previously split work across subagents. In fact, we reduced Claude Code’s system prompt for more advanced models by over 80% which included cuts related to progressively disclosing skills and tools.
- Models are more capable: starting with Opus 4.5, models became capable of managing far more in a single loop than most teams expected. You cannot turn off thinking on Opus 5.5, and Fable 5.1, and recent models increasingly narrate their progress and check their work as they go, which makes some harness elements redundant. Each new model lets you move more of the decision-making out of the harness and into the model itself. A simpler loop is also easier to move to the next model; in migrations we have helped customers with, rigid multi-agent structures were often what stopped the new model from doing more of the work.
- 共享上下文能产生更好的答案:对于运行时间较长的智能体,我们希望来自不同任务的上下文能够保留在主上下文窗口中。能够看到每一步结果的智能体可以将它们联系起来,从而比由子智能体返回的一组摘要产生更丰富的输出和更深入的见解。这也意味着更少的上下文窗口和更少有损的交接。
- 渐进式披露可防止上下文膨胀:该技术使团队能够构建单一代理,以完成各种任务,而无需将所有上下文立即加载到一个冗长的系统提示中。这消除了团队此前将工作拆分到多个子代理的主要原因。事实上,我们为更高级的模型减少了 Claude Code 系统提示超过 80% 的内容,其中包括与渐进式披露技能和工具相关的削减。
- 模型能力更强:从 Opus 4.5 开始,模型在单个循环中处理的能力远超大多数团队的预期。你无法关闭 Opus 5.5、Fable 5.1 以及近期模型的思考功能,这些模型在运行过程中会越来越多地叙述其进度并检查工作,这使得某些控制框架(harness)元素变得冗余。每个新模型都让你能够将更多的决策从控制框架转移到模型本身。更简单的循环也更容易迁移到下一个模型;在我们协助客户的迁移案例中,僵化的多代理结构往往是阻碍新模型承担更多工作的原因。
The single agent loop design requires discipline: a carefully managed system prompt, skill and tool descriptions that trigger at the right times, and deliberate handling of context windows, memory, and note-taking. This article goes deeper into migration and design considerations in subsequent sections.
单一代理循环设计需要纪律:需要精心管理的系统提示、能在正确时机触发的技能和工具描述,以及对上下文窗口、记忆和笔记的刻意处理。本文将在后续章节更深入地探讨迁移和设计考量。
One central team should own end-to-end quality and the system prompt, vetting every new tool and eval before it ships. Keeping that central team small helps iteration move quickly and lowers coordination cost across a large org.
一个中央团队应负责端到端的质量和系统提示,并在发布前审核每一个新工具和评估。保持该中央团队精简有助于加快迭代速度,并降低大型组织内的协调成本。
If you go the multi-agent route, start with the simplest pattern (generator-verifier, orchestrator-subagent, or other) that could work. Decompose boundaries effectively by dividing by context: give each subagent a piece of work that needs little from the rest of the system and have it hand back a compact result (good candidates are independent research paths, separate components with clean interfaces, or black-box verification). When agents are split by problem type, they engage in a "telephone game," passing information back and forth with each handoff degrading fidelity.
如果你选择多代理路线,应从最简单的可行模式开始(生成器-验证器、编排器-子代理或其他)。通过按上下文划分来有效分解边界:给每个子代理分配一部分对系统其余部分依赖较少的工作,并让它返回紧凑的结果(好的候选项包括独立的研究路径、具有清晰接口的独立组件,或黑盒验证)。当代理按问题类型拆分时,它们会陷入“传话游戏”,每次交接都会导致信息保真度下降。
How to fold subagents into the main agent loop
如何将子代理折叠到主代理循环中
Many teams already have an orchestrator and a set of specialist agents in production. The following is the single loop design we'd suggest working toward:
许多团队在生产环境中已经拥有编排器和一组专家代理。以下是我们建议逐步实现的目标:单一循环设计
- One model and one context window running an open-ended tool loop, with limits (turn and cost budgets, write gates) set in the harness.
- Each turn, the model emits a batch of tool calls. The harness runs them in parallel and returns raw results to the same model, which decides the next step: another batch, a question to the user, or an answer.
- The loop stops when the model answers or hits a budget. A goal or verifier check can optionally run after the answer.
- 一个模型和一个上下文窗口运行开放式工具循环,并在框架中设置了限制(轮次和成本预算、写入门控)。
- 每一轮,模型发出一批工具调用。框架并行执行这些调用并将原始结果返回给同一模型,由该模型决定下一步操作:发出另一批调用、向用户提问或给出答案。
- 当模型给出答案或达到预算时,循环停止。在答案之后可选择性地运行目标检查或验证器检查。
更进一步:量化金融体系
看懂新闻只是起点——沿量化金融路径,把它变成能交付的工程能力