agents/prod
03
Foundations · Chapter 3

Reasoning patterns — how an agent thinks

Chapter 2 gave the agent a loop. But what happens inside each turn — how the model plans, checks itself, and recovers — is the difference between an agent that works and one that confidently does the wrong thing. Each pattern here is a published technique with real benchmark numbers, and each gets its own visual so you feel the mechanism, not just read the name.

1 · Chain-of-Thought: think in tokens

The simplest, most surprising result in the field: ask a model to show its work step by step before answering, and accuracy on multi-step problems jumps. Why? Generating intermediate reasoning tokens literally gives the model more compute — each step conditions the next, so it's no longer forced to leap straight to an answer. The catch: it's an emergent ability of scale — it helps large models and does little for small ones. The landmark result: a 540B model given just 8 worked examples reached state-of-the-art on the GSM8K math benchmark, beating fine-tuned models that used answer verifiers. No training — just "let's think step by step."

Direct answer~18%
+ Chain-of-Thought~57%
Same model, same question — just asked to reason step-by-step. (Illustrative of the large accuracy jump CoT produces on multi-step math like GSM8K.)

2 · ReAct: interleave reasoning and acting

Chain-of-Thought reasons in a vacuum — it never checks reality, so it can reason its way, fluently, to a wrong answer. ReAct fixes that by cycling Thought → Action → Observation: reason, take an action (a tool call), observe the real result, reason again. Grounding each step in a real observation cuts the hallucination and error-cascade that pure CoT suffers — which is why it's the backbone of nearly every production agent. Original results: +34 points on ALFWorld and +10 on WebShop, from one or two examples.

Thought Action Observe
The loop that grounds reasoning: reason → act in the world → see what actually happened → reason again.

3 · Reflection: learn from your own mistakes

Reflection (the "Reflexion" framework) has the agent critique its own output and retry, storing the verbal self-feedback in memory so the next attempt is better — improvement without touching model weights. On the HumanEval coding benchmark it reached 91% pass@1, beating GPT-4's 80%.

Attempt Self-critique Revise
Try → critique yourself → revise → try again. The reflection is stored, so each pass improves — no retraining.

See all three solve the same problem

Interactive · same task, three reasoning patterns
Task: "A shop has 23 apples, sells 8, then receives 2 crates of 6. How many now?" Switch patterns: CoT reasons in its head, ReAct grounds the arithmetic with a calculator tool, and Reflection catches its own mistake and fixes it. Same task — very different reliability.

4 · Tree-of-Thoughts: explore, evaluate, backtrack

Ordinary generation is left-to-right — commit to a bad first step and you're stuck. Tree-of-Thoughts (ToT) lets the model branch into several candidate "thoughts," score each one itself, and search — expanding promising branches, pruning dead ends, backtracking. On the "Game of 24" puzzle this lifted GPT-4 from 4% (CoT) to 74%. The cost is real (many branches = many tokens), so reach for it when the space is wide and you can cheaply check a branch.

Interactive · watch a search over reasoning branches
Three candidate first moves for reaching 24 from 4, 9, 10, 13. Hit the button: the model scores each branch, prunes the losers, and keeps the one that solves it. That self-evaluation + backtracking is the whole idea.

5 · Plan-and-Execute: decide the whole plan first

Instead of deciding one step at a time, a planner lays out the entire plan up front and an executor works through it. It trades adaptability for predictability and auditability — which is exactly why LinkedIn's Hiring Assistant chose it over ReAct for a well-understood recruiting workflow (Chapter 11).

Plannerdecomposes the goal the plan1 · source candidates2 · screen & rank3 · draft outreach Executorruns each step
Plan first, then execute in order — predictable and auditable, at the cost of on-the-fly adaptability.

6 · Which pattern should you use?

You rarely need the fanciest option. Tell the demo what your task looks like and it recommends the pattern most teams reach for:

Interactive · pick your task → get the pattern

Recap

  • CoT spends compute as reasoning tokens (scale-dependent).
  • ReAct grounds reasoning in real observations — the workhorse.
  • Reflection self-corrects across attempts, no retraining.
  • ToT trades tokens for search when the space is wide; Plan-and-Execute trades adaptability for predictability.
Carry into Chapter 4

These patterns all run inside the context window. Next: how you curate that window every turn — the highest-leverage skill in agent engineering — and when to split work across multiple agents.