代理 AI 设计模式
用于已经投入生产的系统的代理 AI 设计模式 — 该交付什么,观察什么,预算什么,设置什么门槛。增强型 LLM,代理 RAG,监督者 + 协调者-工人,决策日志,步骤预算,沙箱隔离,审批队列。
代理 AI 设计模式是执行的 AI 系统的构建块 — 这些系统中 LLM 不是产品,而是决策循环的引擎。当你停止问“模型应该输出什么?”而开始问“代理接下来应该做什么,使用哪个工具,在谁的授权下,预算是多少?”时,这些就是你会使用的模式。
下面的选择偏向于生产:增强型 LLM 原语(模型 + 检索 + 工具 + 内存),将其包裹起来的循环(ReAct,计划与执行),使其可扩展的协调形状(监督者,协调者-工人),使其扎根的检索形状(代理 RAG),以及保持其问责的治理形状(决策日志,步骤预算,沙箱隔离)。它们共同回答“一旦你交付,代理 AI 系统实际上是什么样子?”
每个模式都以 GoF 风格进行分解:意图、上下文、问题、力量、因此、解决方案、后果(好处 + 负担)、约束(在强大生成器下保持模式一致的严格禁止),以及相关[] — 与其他模式的类型边缘。请参阅下面的相关指南以获取相邻框架 — 架构、代理设计模式更广泛、多代理协调、RAG 和安全性。
Field-tested patterns to start with
- Augmented LLM — Build the foundational agent block as an LLM augmented with retrieval, tools, and memory that the model actively chooses to use, rather than a bare-model call.
- ReAct — Interleave a single thought, a single tool call, and a single observation per step so the agent reasons over fresh evidence.
- Tool Use — Let the LLM produce typed calls against an external toolkit instead of producing free-form text the surrounding system has to parse.
- Plan-and-Execute — Plan all the steps once with a strong model, then execute each step with a cheaper model under the plan.
- Agentic RAG — Replace static retrieve-then-generate with autonomous agents that plan, choose sources, retrieve iteratively, reflect, and re-query.
- Supervisor — Place a coordinating agent above a set of specialised agents and route work to them.
- Orchestrator-Workers — An orchestrator dynamically breaks a task into subtasks at runtime and delegates each to a worker LLM, then synthesises results.
- Decision Log — Persist the agent's reasoning trace alongside its actions so post-hoc review can explain why.
- Step Budget — Cap the number of tool calls or loop iterations the agent is allowed within a single request.
- Sandbox Isolation — Run agent-emitted code or actions in a contained environment with restricted filesystem, network, and process privileges.
- Approval Queue — Queue agent-proposed actions for asynchronous human review while the agent continues other work.
- Reflection — Have the model review its own output and produce a revised version in one or more passes.
Recommended reading
- Planning & Control Flow — 45 patterns
- Tool Use & Environment — 46 patterns
- Retrieval & RAG — 23 patterns
- Governance & Observability — 40 patterns
- Safety & Control — 66 patterns
Or open the full contents for all 531 patterns in 14 books.
Related guides
- AI Agents Patterns — AI agents patterns: named, reusable shapes for building AI agents that reason, use tools, coordinate, and stay safe — single-agent loops an…
- AI Agents Patterns Catalog — The AI agents patterns catalog: a complete, GoF-formal pattern language for AI agents across reasoning, planning, tool use, retrieval, memo…
- LLM Agent Design Patterns — A GoF-formal catalog of LLM agent design patterns: ReAct, tool use, plan-and-execute, reflection, step budget, and more. Each pattern decom…
- Agentic Design Patterns — A GoF-formal catalog of agentic design patterns — named, reusable shapes for building autonomous AI agents: agent loops, tool use, planning…
- AI Agent Design Patterns — How to build an AI agent: the named shapes you reach for during design and implementation — reasoning (ReAct, plan-and-execute, reflection)…
- Agent Design Patterns — Agent design patterns treat the agent loop as a software-engineering primitive: an observe→reason→act cycle wrapped in tools, memory, super…
- Agentic Patterns — A complete pattern language for agentic systems, organised in Alexander-style books across reasoning, planning, tool use, retrieval, verifi…
- Agentic AI Architecture — How to structure agentic AI: the architectural patterns that hold an LLM-powered system together. Supervisor, orchestrator-workers, augment…
- RAG Agent Patterns — Patterns for building retrieval-augmented generation agents: naive RAG, agentic RAG, hybrid search, cross-encoder reranking, contextual ret…
- Multi-Agent Patterns — Patterns for coordinating multiple LLM agents: supervisor, orchestrator-workers, handoff, debate, hierarchical agents, swarm, role assignme…
- AI Agent Safety Patterns — Safety patterns for LLM agents: step budget, kill switch, constitutional charter, approval queue, sandbox isolation, input/output guardrail…
About this catalog
The Agent Patterns Catalog is an open, GoF-formal reference of 531 design patterns for building LLM agents. Each pattern is decomposed in the manner of Christopher Alexander (1977) and the Gang of Four (1994). Source of truth at github.com/agentpatternscatalog/patterns — CC BY 4.0.