Anthropic《Building Effective Agents》:5 种 workflow + 1 种 agent

原文:anthropic.com/research/building-effective-agents 作者:Erik Schluntz, Barry Zhang(Anthropic 应用工程团队) 发布:2024-12-19
🔥 影响力卡片
- 被业内称为”agent 设计的事实标准参考文档”
- Simon Willison 在他的”2025 LLM 年度回顾”中专文盘点
- HuggingFace、AWS 等大厂的 agent 框架明文 build on it
- 它定义的”5 种 workflow + 1 种 agent”分类法,几乎所有后续 agent 文章都在引用
- Anthropic Cookbook 的 patterns/agents 目录给了完整可运行代码,持续更新到 2026
🎯 为什么必读
这是官方派、工程派、务实派的最强组合拳。如果说 Karpathy 给你坐标系,这篇给你设计图。
它的特别之处在于:
- 来自 Anthropic 一线工程团队,不是营销文,是他们自己跟数十个团队建 agent 后的总结
- 它故意反对”框架崇拜” —— 这在框架公司满天飞的时代极其稀缺
- 它给出了清晰的”什么时候不要用 agent” —— 比所有”agent 万能论”都珍贵
读完你会拿到一个任何 agent 项目都可用的设计 checklist。
一句话总结
不要建最复杂的系统,要建最适合需求的系统。 大多数情况下,单次优化的 LLM 调用就够了;再复杂一层,workflow 就够了;只有真正需要动态决策时,才升级到 agent。
💎 金句墙
★ “The most successful implementations weren’t using complex frameworks or specialized libraries. Instead, they were building with simple, composable patterns.” “最成功的实现都没用复杂框架或专门的库 —— 它们用的是简单、可组合的模式。”
★ “Agents are typically just LLMs using tools based on environmental feedback in a loop.” “Agent 通常就是 LLM 基于环境反馈在一个循环里使用工具。” —— 一句话祛魅。
★ “Success in the LLM space isn’t about building the most sophisticated system. It’s about building the right system for your needs.” “在 LLM 领域,成功不是建最精巧的系统,而是建对你需求最对的系统。”
★ “Think about how much effort goes into human-computer interfaces (HCI), and plan to invest just as much effort in creating good agent-computer interfaces (ACI).” “想想你为人机界面(HCI)投入了多少精力 —— agent-计算机界面(ACI)值得同等投入。” —— 这是一个会改变你思考方式的句子。
★ “We actually spent more time optimizing our tools than the overall prompt.” “我们(Anthropic 自己做 SWE-bench agent 时)花在优化工具上的时间比花在优化 prompt 上还多。” —— 这是大多数人完全反直觉的事实。
📋 核心精读
0. 关键定义:agent vs workflow
文章开篇划界线:
- Workflow:LLM 和工具被预定义的代码路径串起来
- Agent:LLM 动态决定自己的流程和工具使用
🟢 译者点评:这个区分极其重要。99% 的”AI agent” 项目其实是 workflow,这不是缺点,而是优点 —— 它更可控、更便宜、更可调试。
1. 何时用 agent,何时不用
Anthropic 的建议:
从最简单方案开始,只在简单方案不够时再加复杂度。 Agent 用更高的延迟和成本换更好的任务表现。
不要用 agent 的场景:
- 任务路径可预测 → 用 workflow
- 任务可一次完成 → 直接调一次 LLM
- 错误成本高且不可恢复 → workflow + 人工检查点
2. 基础积木:Augmented LLM
所有 agent 系统的最小单元是 被增强的 LLM —— 三件套:
- Retrieval(检索)
- Tools(工具)
- Memory(记忆)
关键洞察:通过 MCP(Model Context Protocol)接入第三方工具正成为标准。
3. 五种 Workflow Patterns(这是这篇文章的”核心知识”——必背)
| 模式 | 定义 | 何时用 |
|---|---|---|
| Prompt Chaining | 任务拆成顺序步骤,每步处理上一步输出 | 任务可分解、固定流程 |
| Routing | 分类输入,送到专门处理路径 | 多类输入需要区别对待 |
| Parallelization | 分块或多次投票,并行跑多个 LLM 调用 | 速度优先 / 置信度优先 |
| Orchestrator-workers | 一个中央 LLM 动态拆任务、分发、合并 | 子任务不可预知 |
| Evaluator-optimizer | 一个 LLM 生成,另一个评估反馈 | 有清晰评估标准 + 需要迭代 |
🟢 译者点评:这五种 workflow 是当前 agent 工程的词汇表。你跟人讨论 agent 设计时,如果不能用这五个词分类,你就还没入门。Evaluator-optimizer 是 Ralph Loop 的祖宗,Orchestrator-workers 是 Claude Code subagent 的祖宗。
4. Agents(真正的自主系统)
Agent 适合的特征:
- 任务结构开放
- 步骤数无法预定
- 需要环境反馈来决定下一步
- 你信任 LLM 的判断
关键工程要求:
- 沙箱环境(防止失控破坏)
- 人类检查点(高风险操作必须 confirm)
- 明确停止条件(否则会无限循环烧钱)
- 可受信环境部署
5. 工具设计 = ACI 工程
这是文章最被低估、但最实用的一部分。Anthropic 反复强调:
工具的命名、描述、参数、错误信息,值得像设计 UI 一样精心打磨。
具体建议:
- 想想”工程师需要思考多久才能用对这个工具” → LLM 也需要那么多上下文
- 用自然语言描述而不是只给 schema
- 给示例,尤其边界情况
- 错误信息要可操作,不要只说”failed”
- 避免”几乎相同”的工具 —— LLM 会困惑
🟢 译者点评:这一节是这篇文章里最反直觉、最有 ROI 的部分。大多数人花 80% 时间调 prompt,而 Anthropic 自己说”工具优化比 prompt 优化更重要”。如果你正在建 agent,从今天起把这个比例倒过来。
6. 三大原则(收尾)
- 保持简单:用最少的复杂度达成目标
- 保持透明:让 agent 的规划步骤显式可见
- 精心打磨 ACI:把工具文档、参数、错误信息当 UI 一样设计
🟢 译者总评
这篇文章是反 hype 的杰作。当所有人都在喊”AI agent 革命”时,Anthropic 自家工程师出来说:大多数你听到的”agent”,其实是 workflow,而且这没毛病。
如果你只从这篇带走三件东西:
- 能用单次 LLM 调用解决的,不要用 workflow;能用 workflow 解决的,不要用 agent
- Workflow 有 5 种 pattern,记住它们,这是入门的语言
- 优化工具(ACI)比优化 prompt 重要 —— 这一条值得纹身
这篇也解释了为什么 12-Factor Agents 会火 —— 它们是同一个工程派思潮的两面:Anthropic 给设计模式,Dex Horthy 给生产纪律。
🔗 延伸阅读
- Anthropic Cookbook - patterns/agents —— 五种 workflow 全都有可运行 Python 代码
- 进阶:Anthropic 《Effective context engineering for AI agents》
- 进阶:Anthropic 《Effective harnesses for long-running agents》
- 本系列内推荐配套阅读:
06-术语谱系-prompt-to-agentic-engineering.md—— 把这篇放到完整术语谱系里看
🔗 调研来源(可校验)
- 原文(主):anthropic.com/research/building-effective-agents
- 原文(次,工程版):anthropic.com/engineering/building-effective-agents
- Anthropic 资源页:resources.anthropic.com/building-effective-ai-agents
- Anthropic 工程博客主页:anthropic.com/engineering
- Anthropic Cookbook 代码示例:github.com/anthropics/anthropic-cookbook/tree/main/patterns/agents
- Hacker News 讨论:news.ycombinator.com/item?id=42470541
- Simon Willison 转译:simonwillison.net/2024/Dec/20/building-effective-agents
- 二手解读:MAA1 - Learning from Anthropic about building effective agents | Kenji - How to Build Effective AI Agents | aimultiple - 6 Composable Patterns
- HuggingFace 实现:Sri-Vigneshwar-DJ - smolagents based on Anthropic best practices
- Anthropic 续作:Effective context engineering for AI agents | Effective harnesses for long-running agents
- Anthropic 评估配套:Demystifying evals for AI agents