AgentFlow
基于 LangGraph 的多 Agent 协作设计模式实战库,提供 10+ 种经过验证的模式,每个模式都有完整代码、架构图、适用场景分析和性能对比。
Quick Decision Tree
flowchart TD
Start(["What does your use case need?"])
Q1{Does it require<br/>human approval?}
Q1-- Yes --> Hitl["👤 Human-in-the-Loop"]
Q1-- No --> Q2{Is the task<br/>complex multi-faceted?}
Q2-- Simple task --> Q3{Does it need<br/>RAG?}
Q2-- Complex task --> Q4{Any safety or<br/>compliance needs?}
Q3-- Yes --> RAG["📚 RAG-Agent"]
Q3-- No --> Q5{Does it need<br/>quality improvement?}
Q5-- Yes --> Refl["🔄 Reflection"]
Q5-- No --> Q6{Does it need a<br/>chain of experts?}
Q6-- Yes --> CoE["🔗 Chain-of-Experts"]
Q6-- No --> Single["✓ Single Agent<br/>No pattern needed"]
Q4-- Yes --> Guard["🛡️ GuardRail"]
Q4-- No --> Q7{Any hierarchical<br/>management structure?}
Q7-- Yes --> Hier["📊 Hierarchical"]
Q7-- No --> Q8{Does it need<br/>parallel processing?}
Q8-- Yes --> MR["🗂️ MapReduce"]
Q8-- No --> Q9{Any competing<br/>viewpoints to weigh?}
Q9-- Yes --> Deb["⚔️ Debate"]
Q9-- No --> Q10{Does it need<br/>voting/coordination?}
Q10-- Yes --> Vot["🗳️ Voting"]
Q10-- No --> Swarm["🐝 Swarm"]
class Start terminal
class Q1,Q2,Q3,Q4,Q5,Q6,Q7,Q8,Q9,Q10 decision
class Hitl,RAG,Refl,CoE,Single,Hier,MR,Deb,Vot,Swarm,Guard pattern
click Hitl href "/patterns/human_in_the_loop/"
click RAG href "/patterns/rag_agent/"
click Refl href "/patterns/reflection/"
click CoE href "/patterns/chain_of_experts/"
click Hier href "/patterns/hierarchical/"
click MR href "/patterns/map_reduce/"
click Deb href "/patterns/debate/"
click Vot href "/patterns/voting/"
click Swarm href "/patterns/swarm/"
click Guard href "/patterns/guardrail/"
Click a pattern name to jump to its documentation
Patterns
Quick Start
# 1. 安装
pip install agentflow
# 2. 配置 API Key
echo "OPENAI_API_KEY=sk-..." > .env
# 3. 运行示例
python -m agentflow.patterns.reflection.example
Compare Patterns
| 场景 | 推荐模式 |
|---|---|
| 需要迭代优化质量 | 反思循环 |
| 需要多角度辩论 | 辩论模式 |
| 需要并行处理大量数据 | MapReduce |
| 需要层级管理 | 层级委派 |
| 需要多 Agent 投票决策 | 投票决策 |
| 需要安全过滤 | 风控守门 |
| 需要知识检索增强 | RAG-Agent |
| 需要专家链式处理 | 专家链 |
| 需要人类介入确认 | 人机协作 |
| 需要去中心化协作 | 群体智能 |