multi-agent-patterns
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseMulti-Agent Architecture Patterns
Multi-Agent架构模式
Multi-agent architectures distribute work across multiple LLM instances, each with its own context window. The critical insight: sub-agents exist primarily to isolate context, not to anthropomorphize role division.
Multi-Agent架构将工作分配到多个LLM实例中,每个实例都有自己的上下文窗口。核心要点:子智能体的主要作用是隔离上下文,而非拟人化地划分角色。
Why Multi-Agent?
为什么选择Multi-Agent?
Context Bottleneck: Single agents fill context with history, documents, and tool outputs. Performance degrades via lost-in-middle effect and attention scarcity.
Token Economics:
| Architecture | Token Multiplier |
|---|---|
| Single agent chat | 1× baseline |
| Single agent + tools | ~4× baseline |
| Multi-agent system | ~15× baseline |
Parallelization: Research tasks can search multiple sources simultaneously. Total time approaches longest subtask, not sum.
上下文瓶颈:单智能体会将历史记录、文档和工具输出填满上下文。由于“中间信息丢失效应”和注意力资源稀缺,性能会下降。
Token经济性:
| 架构 | Token乘数 |
|---|---|
| 单智能体对话 | 基准值的1倍 |
| 单智能体+工具 | 基准值的约4倍 |
| 多智能体系统 | 基准值的约15倍 |
并行化:研究类任务可以同时搜索多个来源。总耗时趋近于耗时最长的子任务,而非所有子任务耗时之和。
Architectural Patterns
架构模式
Pattern 1: Supervisor/Orchestrator
模式1:监督者/编排者
User Query -> Supervisor -> [Specialist, Specialist] -> Aggregation -> OutputUse when: Clear decomposition, coordination needed, human oversight important.
The Telephone Game Problem: Supervisors paraphrase sub-agent responses incorrectly.
Fix: tool lets sub-agents respond directly:
forward_messagepython
def forward_message(message: str, to_user: bool = True):
"""Forward sub-agent response directly to user."""
if to_user:
return {"type": "direct_response", "content": message}用户查询 -> 监督者 -> [专家智能体, 专家智能体] -> 结果聚合 -> 输出适用场景:任务可清晰分解、需要协调、人工监督很重要的情况。
传话游戏问题:监督者可能会错误地转述子智能体的响应。
解决方法:使用工具让子智能体直接回复:
forward_messagepython
def forward_message(message: str, to_user: bool = True):
"""将子智能体的响应直接转发给用户。"""
if to_user:
return {"type": "direct_response", "content": message}Pattern 2: Peer-to-Peer/Swarm
模式2:对等/集群(Swarm)
python
def transfer_to_agent_b():
return agent_b # Handoff via function return
agent_a = Agent(name="Agent A", functions=[transfer_to_agent_b])Use when: Flexible exploration, rigid planning counterproductive, emergent requirements.
python
def transfer_to_agent_b():
return agent_b # 通过函数返回实现智能体移交
agent_a = Agent(name="Agent A", functions=[transfer_to_agent_b])适用场景:需要灵活探索、严格规划反而适得其反、需求会动态涌现的情况。
Pattern 3: Hierarchical
模式3:分层架构
Strategy Layer -> Planning Layer -> Execution LayerUse when: Large-scale projects, enterprise workflows, clear separation of concerns.
策略层 -> 规划层 -> 执行层适用场景:大型项目、企业级工作流、需要清晰关注点分离的情况。
Context Isolation
上下文隔离
Primary purpose of multi-agent: context isolation.
Mechanisms:
- Full context delegation: Complex tasks needing full understanding
- Instruction passing: Simple, well-defined subtasks
- File system memory: Shared state without context bloat
多智能体的主要目的:上下文隔离。
实现机制:
- 全上下文委托:需要完全理解的复杂任务
- 指令传递:简单、定义明确的子任务
- 文件系统内存:共享状态且不会导致上下文膨胀
Consensus and Coordination
共识与协调
Weighted Voting: Weight by confidence or expertise.
Debate Protocols: Agents critique each other's outputs. Adversarial critique often yields higher accuracy than collaborative consensus.
Trigger-Based Intervention:
- Stall triggers: No progress detection
- Sycophancy triggers: Mimicking without reasoning
加权投票:根据置信度或专业程度赋予权重。
辩论协议:智能体互相评判对方的输出。对抗性评判通常比协作式共识能产生更高的准确性。
基于触发条件的干预:
- 停滞触发:检测到无进展情况
- 趋同触发:无推理过程的模仿行为
Failure Modes
故障模式
| Failure | Mitigation |
|---|---|
| Supervisor Bottleneck | Output schema constraints, checkpointing |
| Coordination Overhead | Clear handoff protocols, batch results |
| Divergence | Objective boundaries, convergence checks |
| Error Propagation | Output validation, retry with circuit breakers |
| 故障类型 | 缓解措施 |
|---|---|
| 监督者瓶颈 | 输出 schema 约束、检查点机制 |
| 协调开销 | 明确的移交协议、批量处理结果 |
| 任务偏离 | 目标边界设定、收敛检查 |
| 错误传播 | 输出验证、带熔断机制的重试 |
Example: Research Team
示例:研究团队
text
Supervisor
├── Researcher (web search, document retrieval)
├── Analyzer (data analysis, statistics)
├── Fact-checker (verification, validation)
└── Writer (report generation)text
监督者
├── 研究员(网页搜索、文档检索)
├── 分析师(数据分析、统计)
├── 事实核查员(验证、确认)
└── 撰稿人(报告生成)Best Practices
最佳实践
- Design for context isolation as primary benefit
- Choose pattern based on coordination needs, not org metaphor
- Implement explicit handoff protocols with state passing
- Use weighted voting or debate for consensus
- Monitor for supervisor bottlenecks
- Validate outputs before passing between agents
- Set time-to-live limits to prevent infinite loops
- 以上下文隔离作为核心优势进行设计
- 根据协调需求选择模式,而非照搬组织隐喻
- 实现带有状态传递的明确移交协议
- 使用加权投票或辩论达成共识
- 监控监督者瓶颈情况
- 在智能体之间传递前验证输出
- 设置生存时间限制以防止无限循环