AI代理设计模式
如何构建AI代理:在设计和实现过程中你所使用的命名形状 — 推理(ReAct、计划与执行、反思)、对世界的行动(工具使用、代理RAG、交接),以及保持循环足够安全以便发布(步骤预算、紧急停止开关)。
AI代理是一个包裹在决策循环中的LLM:观察、推理、行动、重复。AI代理设计模式命名了该循环的各个部分及其周围的重复形状 — 如何在不产生失控成本的情况下进行推理(ReAct、计划与执行、反思),如何在不失去责任的情况下对世界采取行动(工具使用、代理RAG、交接),以及如何保持循环足够安全以便发布(步骤预算、紧急停止开关、人工干预)。
这些模式不是框架特性。它们是关于行为的承诺,可以在特定基础上进行辩护 — 也可以在特定基础上拒绝。该目录以Christopher Alexander(1977年)和Gang of Four(1994年)的方式分解每个模式,并添加了LLM时代的约束槽(代理绝不能违反的严格禁止),以便每个模式在可以进行论证的生成器下保持其形状。
下面的选择是一个实用的入门集,适用于“我如何构建一个AI代理?”。打开相关指南以获取相邻的框架:更广泛的代理设计模式语言、代理AI架构、多代理协调、RAG和安全堆栈。
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.
- 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.
- Reflection — Have the model review its own output and produce a revised version in one or more passes.
- 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.
- 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.
- Handoff — Transfer the active conversation from one agent to another, carrying context across the switch.
- Step Budget — Cap the number of tool calls or loop iterations the agent is allowed within a single request.
- Kill Switch — Provide an out-of-band control plane to halt running agent instances without redeploy.
- Human-in-the-Loop — Require explicit human approval at defined points before the agent performs an action.
- Decision Log — Persist the agent's reasoning trace alongside its actions so post-hoc review can explain why.
Recommended reading
- Reasoning — 20 patterns
- Planning & Control Flow — 45 patterns
- Tool Use & Environment — 51 patterns
- Retrieval & RAG — 23 patterns
- Safety & Control — 72 patterns
Or open the full contents for all 562 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,…
- 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 562 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.