多智能体系统协调专门的组件来处理复杂的工作流程。然而,并非每个复杂任务都需要这种方法——单个智能体配合正确的(有时是动态的)工具和提示词通常可以实现类似的结果。
Key insight:
Handoffs, Skills, and Router are most efficient for single tasks (3 calls each). Subagents adds one extra call because results flow back through the main agent—this overhead provides centralized control.
Key insight:
Stateful patterns (Handoffs, Skills) save 40-50% of calls on repeat requests. Subagents maintain consistent cost per request—this stateless design provides strong context isolation but at the cost of repeated model calls.
Key insight:
For multi-domain tasks, patterns with parallel execution (Subagents, Router) are most efficient. Skills has fewer calls but high token usage due to context accumulation. Handoffs is inefficient here—it must execute sequentially and can’t leverage parallel tool calling for consulting multiple domains simultaneously.
Choosing a pattern:
为什么选择多智能体?
当开发者说他们需要"多智能体"时,通常是在寻找以下一种或多种能力:- 上下文管理 :在不压垮模型上下文窗口的情况下提供专门的知识。如果上下文是无限的且延迟为零,您可以将所有知识放入单个提示词中——但由于实际情况并非如此,您需要模式来有选择地呈现相关信息。
- 分布式开发 :允许不同团队独立开发和维护功能,将它们组合成具有清晰边界的更大系统。
- 并行化 :为子任务生成专门的工作者并同时执行它们以获得更快的结果。
模式
以下是构建多智能体系统的主要模式,每种模式适合不同的用例:选择模式
使用此表格将您的需求与正确的模式进行匹配:- 分布式开发 :不同的团队能否独立维护组件?
- 并行化 :多个智能体能否同时执行?
- 多跳 :该模式是否支持连续调用多个子智能体?
- 直接用户交互 :子智能体能否直接与用户对话?
可视化概览
-
Subagents
-
Handoffs
-
Skills
-
Router
A main agent coordinates subagents as tools. All routing passes through the main agent.
Performance comparison
Different patterns have different performance characteristics. Understanding these tradeoffs helps you choose the right pattern for your latency and cost requirements. Key metrics:- Model calls : Number of LLM invocations. More calls = higher latency (especially if sequential) and higher per-request API costs.
- Tokens processed : Total context window usage across all calls. More tokens = higher processing costs and potential context limits.
One-shot request
User: “Buy coffee”A specialized coffee agent/skill can call a
buy_coffee
tool.
-
Subagents
-
Handoffs
-
Skills
-
Router
4 model calls:
Repeat request
Turn 1: “Buy coffee” Turn 2: “Buy coffee again”The user repeats the same request in the same conversation.
-
Subagents
-
Handoffs
-
Skills
-
Router
4 calls again → 8 total
- Subagents are stateless by design —each invocation follows the same flow
- The main agent maintains conversation context, but subagents start fresh each time
- This provides strong context isolation but repeats the full flow
Multi-domain
User: “Compare Python, JavaScript, and Rust for web development”Each language agent/skill contains ~2000 tokens of documentation. All patterns can make parallel tool calls.
-
Subagents
-
Handoffs
-
Skills
-
Router
5 calls, ~9K tokens
Each subagent works in
isolation
with only its relevant context. Total:
9K tokens
.