# Design patterns

> Recurring shapes for how an agent thinks and acts. This topic covers reasoning interleaved with acting, reflection on one's own output, explicit planning, the trade-off between planning everything up front and reacting step by step, and breaking large goals into levels of plans.

Page: https://schubergphilis.github.io/ai-training/topics/building-agents/patterns/
License: CC BY-SA 4.0, https://creativecommons.org/licenses/by-sa/4.0/

*Building agents* · topic `building-agents/patterns`

Recurring shapes for how an agent thinks and acts. This topic covers reasoning interleaved with acting, reflection on one's own output, explicit planning, the trade-off between planning everything up front and reacting step by step, and breaking large goals into levels of plans.

## Concepts

- **ReAct**: A pattern where the model alternates a short written reasoning step with an action, observes the result and reasons again. Making the reasoning explicit before each tool call improves tool choice and leaves a readable trace of why the agent did what it did. Most tool-using agent loops are a form of this pattern, whether or not the reasoning is shown to the user. [glossary](https://schubergphilis.github.io/ai-training/glossary/#react)
- **Reflection**: Having the model critique its own output, or a second model call critique it, and then revise. Reflection catches errors a single pass misses, especially in code, arguments and formats with checkable rules. It costs extra calls and can loop on trivial edits, so bound the rounds and give the critic concrete criteria rather than asking whether the answer is good. [glossary](https://schubergphilis.github.io/ai-training/glossary/#reflection)
- **Planning**: Having the agent write out the steps to a goal before taking them, as a list it then works through and updates. A written plan improves multi-step tasks, makes progress visible and gives a human a moment to correct course cheaply. Plans go stale as steps reveal new facts, so the pattern includes revisiting the plan, not only following it. [glossary](https://schubergphilis.github.io/ai-training/glossary/#planning)
- **Plan-then-execute vs reactive**: Two ends of a spectrum. Plan-then-execute decides the whole sequence first and then runs it, which is predictable, cheap to review and brittle when a step surprises. Reactive decides one step at a time from the latest observation, which adapts well and is harder to predict or bound. Most agents mix the two: plan coarsely, react within a step. [glossary](https://schubergphilis.github.io/ai-training/glossary/#plan-then-execute-vs-reactive)
- **Hierarchical planning**: Breaking a large goal into subgoals, each with its own plan, often handled by its own agent call or subagent with a fresh context. The top level tracks subgoals and their status; lower levels handle detail. It keeps any one context small and focused and maps well onto decomposed specifications, at the cost of coordination and of information lost between levels. [glossary](https://schubergphilis.github.io/ai-training/glossary/#hierarchical-planning)
- **Workflow patterns**: Fixed arrangements of model calls that code controls, for tasks whose steps are known in advance. Chaining runs calls in order, each working on the output of the one before. Routing classifies an input and sends it to a specialized prompt. Parallel calls split a task into parts, or ask the same question several times and combine the answers. A draft-and-critique loop has one call write and another judge the draft against criteria until it passes. [glossary](https://schubergphilis.github.io/ai-training/glossary/#workflow-patterns)

## Links

- **Builds on:** [The agent loop and harness](https://schubergphilis.github.io/ai-training/topics/building-agents/agent-loop/)
- **Leads to:** [Orchestration and multi-agent](https://schubergphilis.github.io/ai-training/topics/building-agents/orchestration/)
- **Competencies drawing on it:** [Designs and orchestrates multi-agent systems](https://schubergphilis.github.io/ai-training/competencies/building-agents/orchestrates-agents/)

## Lessons

- [Plan everything first or react step by step](https://schubergphilis.github.io/ai-training/building-agents/plan-or-react/) (explanation)
- [Writing the plan before taking the steps](https://schubergphilis.github.io/ai-training/building-agents/planning/) (tutorial)
- [Reasoning before each action](https://schubergphilis.github.io/ai-training/building-agents/react/) (tutorial)
- [A second pass that critiques the first](https://schubergphilis.github.io/ai-training/building-agents/reflection/) (tutorial)
- [Workflows before agents](https://schubergphilis.github.io/ai-training/building-agents/workflows-before-agents/) (explanation)

## Sources

- `AEC-04` [Agentic design patterns: ReAct, reflection, tool use, planning](https://lsimons.github.io/agent-engineer-course/04-agentic-design-patterns/), Agent Engineer Course (course)
- `AEC-06` [Planning and reasoning: the loop, plan-then-execute, hierarchy](https://lsimons.github.io/agent-engineer-course/06-planning-and-reasoning/), Agent Engineer Course (course)
- `DLAI-11` [Agentic AI: M1 workflows and autonomy, M2 reflection, M4 evals and error analysis, M5 autonomous agents](https://www.deeplearning.ai/courses/agentic-ai), DeepLearning.AI (course)
- `Academy building-with-the-claude-api` [Building with the Claude API](https://academy.claude.com/courses/building-with-the-claude-api), Claude Academy (course)
- `Yao 2022` [ReAct: Synergizing Reasoning and Acting in Language Models](https://openreview.net/forum?id=WE_vluYUL-X), International Conference on Learning Representations (ICLR 2023), arXiv preprint 2210.03629 (paper)
- `Madaan 2023` [Self-Refine: Iterative Refinement with Self-Feedback](https://proceedings.neurips.cc/paper_files/paper/2023/hash/91edff07232fb1b55a505a9e9f6c0ff3-Abstract-Conference.html), Advances in Neural Information Processing Systems 36 (NeurIPS 2023), pages 46534 to 46594 (paper)
- `Huang 2023` [Large Language Models Cannot Self-Correct Reasoning Yet](https://openreview.net/forum?id=IkmD3fKBPQ), International Conference on Learning Representations (ICLR 2024), arXiv preprint 2310.01798 (paper)
- `Wang 2023` [Plan-and-Solve Prompting: Improving Zero-Shot Chain-of-Thought Reasoning by Large Language Models](https://aclanthology.org/2023.acl-long.147/), Proceedings of the 61st Annual Meeting of the Association for Computational Linguistics (Volume 1: Long Papers) (ACL 2023), 2609-2634 (paper)
- `Anthropic effective agents` [Building effective agents](https://www.anthropic.com/engineering/building-effective-agents), Anthropic Engineering (reference)
