Agent Patterns
Most “AI agent” problems are best solved by workflows — LLM calls composed in code you control — not by autonomous agents. These patterns run from the most predictable to the most autonomous. As always, prefer the simplest that works.
Workflows vs. agents
Section titled “Workflows vs. agents”The crucial distinction:
- A workflow has its control flow defined by you, in code. Predictable, testable, debuggable.
- An agent has its control flow defined by the LLM, at runtime. Flexible, but harder to predict, test, and bound.
Default to workflows. Use a true agent only when the steps genuinely cannot be known ahead of time. The patterns below make this concrete.
Pattern 1 — Prompt chaining
Section titled “Pattern 1 — Prompt chaining”Decompose a task into a fixed sequence of LLM calls, each consuming the last.
Use when: the task has clear, known sub-steps (outline → draft → edit). Strengths: each step is simple, testable, and debuggable. The most useful pattern there is.
Pattern 2 — Routing
Section titled “Pattern 2 — Routing”Classify the input, then dispatch to a specialized handler.
Use when: distinct input categories deserve distinct handling. Also the core of cost-saving model routing.
Pattern 3 — Parallelization
Section titled “Pattern 3 — Parallelization”Run independent LLM calls at once, then aggregate.
Two flavors: sectioning (split work into independent parts) and voting (run the same task several times for self-consistency). Use when: subtasks are independent — cuts latency and can raise quality.
Pattern 4 — Orchestrator-workers
Section titled “Pattern 4 — Orchestrator-workers”A coordinator LLM breaks a task into subtasks dynamically, delegates them to workers, and synthesizes the results.
Use when: the subtasks can’t be known in advance — unlike fixed parallelization. This is where genuine agency begins. More flexible, less predictable.
Pattern 5 — Evaluator-optimizer
Section titled “Pattern 5 — Evaluator-optimizer”One LLM produces; another evaluates and feeds back; loop until good enough.
Use when: there’s a clear quality signal — code that must pass tests, output that must satisfy a schema, criteria a critic can apply. Weak when “good” is purely subjective. Always cap the iterations.
Pattern 6 — Autonomous agent
Section titled “Pattern 6 — Autonomous agent”The full agent loop: the LLM plans, acts via tools, observes, and decides its own next step until done.
Use when: the path is genuinely open-ended and can’t be expressed as any workflow above. Cost: maximum flexibility, minimum predictability — hard limits and full tracing are mandatory. See Multi-Agent & Production.
Choosing a pattern
Section titled “Choosing a pattern”| The task… | Pattern |
|---|---|
| Has known, ordered sub-steps | Prompt chaining |
| Splits into distinct categories | Routing |
| Has independent parallel parts | Parallelization |
| Needs subtasks decided at runtime | Orchestrator-workers |
| Has a clear quality check to iterate against | Evaluator-optimizer |
| Is genuinely open-ended | Autonomous agent |
Key takeaways
Section titled “Key takeaways”Prefer workflows — control flow you define in code — over autonomous agents whose control flow the LLM decides. The patterns rise in autonomy: prompt chaining, routing, parallelization, orchestrator-workers, evaluator-optimizer, autonomous agent. Predictable workflow patterns solve most problems; the agentic ones add flexibility at the cost of predictability. Pick the simplest pattern that fits the task’s true shape.