Handbooks  /  Agent Patterns
Handbook~14 min readIntermediate
Deep Dive

The patterns
behind every agent.

Give a language model a loop and some tools and it stops being a chatbot and starts being an agent — something that pursues a goal over many steps. This is the field guide to the handful of patterns that agents are built from, and the failure modes that break them in production.

01

What makes something an agent

A plain language model does one thing: you give it text, it gives you text back. An agent wraps that model in a loop and hands it tools. Now, instead of answering in one shot, the model can reason about a goal, take an action in the world, look at what came back, and decide what to do next — over and over, until the job is done.

That shift — from "answer" to "act, observe, adjust" — is the whole idea. Everything in this handbook is a pattern for structuring that loop: how the model decides what to do (ReAct, plan-and-execute), how it acts (tool calling), how it remembers (memory), how many models cooperate (multi-agent), and how you stop it going off the rails (failure modes).

→ Mental model

An agent is not a smarter model. It's the same model, given the ability to take actions and see their results — the difference between a brilliant person answering from memory and the same person with a computer and a web browser.

02

ReAct — the core loop

The pattern almost every agent runs is ReAct: Reasoning + Acting. The model alternates between thinking about what to do and doing it, feeding each result back into the next thought. Reasoning decides the next action; the action's result grounds the next round of reasoning.

The Thought–Action–Observation loop
ThoughtReason about the goal and what to do next.
ActionCall a tool — search[…], query_db[…], calculate[…].
ObservationThe tool returns a real result. Read it…
↑ loop back to Thought until ready
AnswerEnough information gathered — produce the final response.
Each observation injects a fact from outside the model's memory, keeping the reasoning honest.

The magic is the synergy: reasoning makes acting smarter — the model plans which tool to call and recovers from dead ends — while acting makes reasoning honest, because every observation is a real fact from the world, so the chain of thought can't quietly drift into fiction. ReAct hallucinates far less than reasoning alone.

→ Worth knowing

The interleaved trace is human-readable, so you can see why an agent did what it did — and correct it mid-run. That legibility is a big reason ReAct became the default. See the ReAct paper breakdown for the full story.

03

Tool & function calling

An agent is only as capable as the tools it can reach. Tool calling (a.k.a. function calling) is how a model asks your code to do something: you describe each tool with a name, a plain-language description, and a typed argument schema; the model responds with a structured call — the tool name and JSON arguments — instead of prose.

The quality of your tool descriptions matters as much as the model. The model decides which tool to use by reasoning over those descriptions, so vague or overlapping ones cause wrong calls. Good tools are narrow, well-named, clearly documented, and validate their inputs.

Part of a toolWhat it doesFailure if it's weak
NameIdentifies the tool in the model's callAmbiguous names → wrong tool picked
DescriptionTells the model when to use itVague desc → tool ignored or misused
Argument schemaTypes and shape of the inputsLoose schema → malformed / hallucinated args
Return valueThe observation fed back to the modelNoisy return → wasted context, confusion

Design tool schemas the way you'd design an API — that's exactly what they are. The interactive Tool-Schema Designer lets you draft and pressure-test one.

04

ReAct vs plan-and-execute

ReAct decides one step at a time, re-reasoning after every observation. That's flexible but token-heavy, and on long tasks the agent can lose the thread. Plan-and-execute takes the opposite tack: first produce a full plan of steps, then execute them, re-planning only when reality diverges.

Two ways to structure the loop

ReAct — decide as you go

  • Re-reason after every observation
  • Adapts well to surprises
  • More tokens, can drift on long tasks
  • Best for open-ended, unpredictable goals

Plan-and-Execute — plan first

  • Draft the whole plan, then run it
  • Cheaper, more structured execution
  • Re-plans only when a step fails
  • Best for well-defined, multi-step tasks

These aren't rivals — mature agents combine them: a planner lays out the high-level steps, and each step runs a small ReAct loop to handle the messy details. Choosing where to draw that line is one of the real design decisions in building an agent.

05

Reflection & self-critique

Agents get noticeably better when they check their own work. Reflection adds a step where the model critiques its output — "is this actually correct? did I miss anything?" — and revises before finishing. It's the difference between a first draft and a proofread one.

Common forms: a critic pass that scores or flags the draft, a verifier that re-checks a result against the tools (re-run the query, re-read the source), and retry-with-feedback, where a failed step is fed back in with the error so the model can fix it. Reflection costs extra calls, so reserve it for steps where being wrong is expensive.

→ Real-world use

Coding agents lean on reflection hard: write code → run it → read the error → fix it. The test suite is the verifier, and the loop repeats until it goes green. Reflection with a real signal beats reflection on vibes alone.

06

Memory — short-term and long-term

Agents have two kinds of memory, and confusing them is a classic bug.

Two memories, two jobs

Short-term — the context window

  • The running transcript of thoughts, actions, observations
  • Everything the model "sees" this turn
  • Finite — fills up on long runs
  • Managed by summarizing or trimming old steps

Long-term — an external store

  • Facts written out to a database (often a vector DB)
  • Survives across sessions
  • Retrieved on demand, like RAG
  • Lets the agent "remember" you next time

Short-term memory is the context window — powerful but bounded, so as a run grows you must summarize earlier steps to keep the important bits without blowing the budget. Long-term memory is an external store the agent writes to and retrieves from, so knowledge persists beyond one conversation. Retrieving from it is exactly RAG, pointed inward at the agent's own notes.

07

Routing & multi-agent orchestration

One agent with fifty tools becomes confused and slow. A cleaner pattern is to route: a lightweight classifier or small agent decides which specialised agent or tool should handle a request, then hands off. Push this further and you get multi-agent orchestration — several agents, each good at one thing, cooperating.

Planner / worker orchestration
PlannerDecomposes the goal into sub-tasks and assigns them.
WorkersSpecialised agents (researcher, coder, writer) each execute a sub-task.
HandoffResults flow back; the planner integrates or re-assigns.
ResultPlanner assembles the final answer once sub-tasks complete.
Coordination — routing, shared state, and clean handoffs — is the hard part, not the agents themselves.

Multi-agent shines when sub-tasks are genuinely different (research vs. writing vs. code) or need isolation (one agent's mistake shouldn't corrupt another's context). But every extra agent adds coordination cost and new failure surfaces, so reach for it only when a single agent is genuinely struggling. The full architecture — message flow, shared state, termination — is covered in Multi-Agent Orchestration.

08

Failure modes & guardrails

Most of the engineering in a real agent is not the happy path — it's keeping the loop from destroying itself.

The four ways agents break — and how to guard each

Infinite loops

The agent repeats the same action forever, or oscillates between two.

Guard: hard step/time limits, loop detection, budget caps.

Hallucinated tool calls

Invents a tool that doesn't exist, or fills arguments with plausible nonsense.

Guard: strict schema validation; reject and re-prompt on bad calls.

Error cascades

One failed or misread observation derails every step after it.

Guard: catch tool errors, feed them back, allow retries with backoff.

Silent wrong answers

The agent finishes confidently with a wrong result and no error.

Guard: verifier/reflection step; human-in-the-loop for high stakes.

The single most important guardrail is the step limit — a hard cap on how many loops an agent may run before it must stop or ask for help. After that: validate every tool call against its schema, wrap tools in error handling so a failure becomes an observation rather than a crash, and put a human in the loop for any irreversible or high-stakes action (spending money, deleting data, sending messages).

→ Key insight

You cannot fix these by prompting alone — they're engineering problems. And you can't fix what you can't see: log the full Thought–Action–Observation trace of every run. Evaluating that trajectory is its own discipline, covered in the Agent Evals handbook.

Frequently asked

Quick answers

What is an AI agent?

A language model wrapped in a loop with tools, so it can reason about a goal, take an action, observe the result, and repeat until done — not just answer once.

What is the ReAct pattern?

Interleaving reasoning with actions: Thought → Action → Observation, looping until the agent can answer. Reasoning guides actions; observations keep reasoning grounded.

ReAct vs plan-and-execute?

ReAct decides one step at a time (flexible, token-heavy); plan-and-execute plans all steps up front then runs them (structured, cheaper). Many agents combine both.

How does agent memory work?

Short-term memory is the finite context window (the running transcript); long-term memory is an external store — often a vector DB — the agent writes to and retrieves from across sessions.

What are the main agent failure modes?

Infinite loops, hallucinated tool calls, error cascades, and silent wrong answers — guarded by step limits, schema validation, error handling, and human-in-the-loop.

The Agent Patterns Handbook · Vibe Engines · 2026
Finished this one? 0 / 29 Handbooks done

Explore the topic

See this alongside everything else on the same subject — handbooks, system designs, challenges and tools, in one place.