代理设计模式
代理设计模式将代理循环视为软件工程原语:一个观察→推理→行动的循环,包裹在工具、记忆、监督和预算中。ReAct、计划与执行、增强型LLM、决策日志、代理恢复。
从AI炒作中退一步,"代理"成为一种软件原语:一个观察、决定下一步做什么、行动并记住的事物。代理设计模式是你在接受这一原语并开始围绕它设计时所写下的内容——循环如何终止、当现实与计划相矛盾时如何修订计划、状态如何在崩溃中存活、同级代理如何在不重新执行的情况下接收未完成的任务。
这些模式故意关注循环的*形状*,而不是驱动它的模型。早期代理文献中存在相同的模式(BDI、RL、对话系统),现在在增强型LLM的中心依然适用。该目录继承了GoF的学科:意图、上下文、问题、力量,因此,解决方案、后果、约束、相关[] — 与其他模式的类型边缘。
以下选择是代理循环的主干:ReAct(观察-思考-行动)、计划与执行(将规划与执行分开)、增强型LLM(模型 + 检索 + 工具 + 记忆)、反思(自我批评)、决策日志(可审计的轨迹)、监督者(可以停止子代理的父级)、移交(转移控制)、代理恢复(在崩溃中存活)。有关相邻框架,请参见相关指南。
Field-tested patterns to start with
- ReAct — Interleave a single thought, a single tool call, and a single observation per step so the agent reasons over fresh evidence.
- Plan-and-Execute — Plan all the steps once with a strong model, then execute each step with a cheaper model under the plan.
- 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.
- Tool Use — Let the LLM produce typed calls against an external toolkit instead of producing free-form text the surrounding system has to parse.
- Reflection — Have the model review its own output and produce a revised version in one or more passes.
- Decision Log — Persist the agent's reasoning trace alongside its actions so post-hoc review can explain why.
- Supervisor — Place a coordinating agent above a set of specialised agents and route work to them.
- Handoff — Transfer the active conversation from one agent to another, carrying context across the switch.
- Agent Resumption — Persist agent execution state so a long-running run survives restarts, deploys, or user disconnects.
- Agent-as-a-Judge — Evaluate an agent's full trajectory (steps, tool calls, intermediate states) by another agent rather than scoring only the final output.
- Subagent Isolation — Run subagents in isolated workspaces so their writes do not collide and parallelism is safe.
- Step Budget — Cap the number of tool calls or loop iterations the agent is allowed within a single request.
Recommended reading
- Planning & Control Flow — 45 patterns
- Tool Use & Environment — 46 patterns
- Multi-Agent — 46 patterns
- Verification & Reflection — 29 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…
- Agentic AI Design Patterns — Agentic AI design patterns for systems already in production — what to ship, what to observe, what to budget, what to gate. Augmented LLM,…
- 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)…
- 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.