Part I: Foundations

Chapter 02

Core Design Patterns

The universal agent loop and seven reusable production patterns: chaining, routing, parallelization, orchestrator-workers, evaluator-optimizer, ReAct, and reflection.

Seven patterns cover nearly every production agent. Learn them once, recognize them everywhere, and compose them instead of inventing architecture from scratch.

The agent loop

Underneath every framework is the same loop. The model observes the goal and the current state, plans the next step, acts by calling a tool or producing output, and evaluates the result, then repeats until the goal is met or a budget runs out. Frameworks differ in how this loop is expressed (a graph, a crew, a while-loop), not in what it does. If you internalize the loop, no framework will ever feel foreign.

Observe
read goal, context, results
Plan
choose the next step
repeat until goal met
or budget / step limit hit
Act
call a tool / produce output
Evaluate
done? correct? retry?

Figure 2.1. The universal agent loop. Every framework is a wrapper around this.

THE LOOP IN TEN LINES

while not done and steps < budget:
thought = llm(context + goal + observations)
if thought.tool_call:
observations += execute(thought.tool_call) # act
else:
done = validate(thought.answer) # evaluate

The seven patterns

In their influential 'Building Effective Agents' guidance, Anthropic's engineers catalogued the small set of compositions that successful teams actually ship. Five are structured workflows with LLM steps; two add genuine autonomy. Production systems are almost always combinations of these, so they are worth knowing by name.

1 - Prompt chaining
Step 1 - draft
Gate - check
Step 2 - refine
2 - Routing
Router
Billing Tech Sales
3 - Parallelization
Split
A B C
Aggregate
4 - Orchestrator + workers
Orchestrator
5 - Evaluator + optimizer
draft
Generator Evaluator
critique + score
Worker 1 Worker 2 Worker 3
loop until quality bar met
dynamic task split, results merged
then release

Figure 2.2. The five workflow patterns. Each box is one model call or sub-agent.

  • 1. Prompt chaining, decompose a task into fixed sequential steps, optionally with programmatic gates between them. Use when the decomposition is known. Example: draft an outreach email, check it against brand rules, then localize it.
  • 2. Routing, classify the input, then dispatch to a specialized prompt, model, or sub-agent. Use when inputs cluster into distinct categories. Example: a support gateway sending billing, technical, and sales queries down different paths, often to differently priced models.
  • 3. Parallelization, run independent subtasks simultaneously and aggregate, or run the same task several times and vote. Use for speed or for confidence on high-stakes judgments.
  • 4. Orchestrator-workers, a lead model decomposes an unpredictable task at runtime and delegates to workers, then merges results. The backbone of research agents and multi-file coding agents.
  • 5. Evaluator-optimizer, one model generates, another critiques against explicit criteria, and the loop repeats until the bar is met. Use when you can articulate what 'good' looks like, translation nuance, code that must pass tests, brand-safe copy.
  • 6. ReAct (reason + act), the canonical autonomous loop from Figure 2.1: interleave a reasoning step with a tool call, feeding each observation back in. This is the default 'agent' in most frameworks.
  • 7. Reflection, after producing an answer, the agent critiques its own work, or a second pass does, and revises. Cheap insurance on long outputs; pairs naturally with ReAct.

Choosing a pattern

If the task... Reach for Why
Has known, fixed steps Prompt chaining Cheapest, most testable, fully predictable
Has distinct input types Routing Specialized prompts beat one mega-prompt;
enables cost tiering
If the task... Reach for Why
Splits into independent
parts
Can't be decomposed in
advance
Parallelization Latency drops; voting adds reliability
Orchestrator-workers Runtime planning handles variable structure
Has a checkable quality bar Evaluator-optimizer Iteration converges on the bar you defined
Needs open-ended tool use ReAct + reflection Full autonomy, bounded by budgets and
guardrails

Find the simplest pattern that solves the task. Every notch of autonomy you add must pay for itself in outcomes, never add it for elegance.

Worked example: one support desk, four patterns

A telecom support desk routes incoming chats (pattern 2) to three lanes. Password resets
run as a chained workflow (1). Plan-change requests run ReAct with CRM and billing tools
(6), every action logged. Complaint replies pass through an evaluator that checks tone and
policy before sending (5). Four patterns, one product — and only one lane carries real
autonomy, which is exactly where the engineering attention goes.