Skip to content

Design patterns

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
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
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
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
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

Lessons

Your reference

Each lesson above adds its takeaways and its example here once you finish it. Your reference lists every lesson you have finished.

Plan everything first or react step by step

Unlocks when you finish Plan everything first or react step by step.

Writing the plan before taking the steps

Unlocks when you finish Writing the plan before taking the steps.

Reasoning before each action

Unlocks when you finish Reasoning before each action.

A second pass that critiques the first

Unlocks when you finish A second pass that critiques the first.

Sources