Most production AI systems are not one giant prompt. They are small, composable patterns wired together. This guide catalogs the patterns that show up again and again in real deployments.
TL;DR
Agent patterns are reusable control-flow templates built on top of LLM calls. The core set is: prompt chaining, routing, parallelization, orchestrator-workers, and the evaluator-optimizer loop. Pick the simplest pattern that solves the problem and only escalate when you need to.
Workflows vs agents
Anthropic's engineering guidance draws a useful line: a workflow is a system where the LLM calls follow a predefined path, while an agent is a system where the LLM dynamically directs its own process and tool use. Workflows are predictable and easier to test; agents are flexible and harder to control. Start with a workflow and add agency only where the problem genuinely needs it.
The core patterns
Prompt chaining decomposes a task into sequential steps where each step's output feeds the next, with optional validation gates between them. It is ideal when a task can be cleanly broken into fixed stages, like classify, then extract, then generate.
Routing classifies an input and sends it to the right specialist. Use it when distinct categories need distinct handling, such as routing a support message to billing versus technical support.
Parallelization fans a task out to multiple LLM calls and aggregates the results. Use it when subtasks are independent, or when running the same task several times and voting on the result improves reliability.
Orchestrator-workers has a central orchestrator decompose a task, delegate subtasks to specialist workers, and synthesize their results. It is the right fit for tasks where you cannot know the subtasks ahead of time, like a research request that spans sources.
Evaluator-optimizer loops a generator against an evaluator, iterating until the output passes a quality bar. Use it when there is a clear evaluation criterion and iterative refinement measurably helps, such as drafting then critiquing copy.
Memory and state
Agents that span multiple turns need somewhere to put state. A practical split is working memory (the current context), session memory (this conversation or task), and long-term memory (knowledge persisted across sessions). The cookbook's memory-tiering pattern and its Squish-backed recipe describe this in detail.
When to use which
- Fixed sequence of steps: prompt chaining.
- One input, one of several handlers: routing.
- Independent subtasks or need for voting: parallelization.
- Unknown subtasks discovered at runtime: orchestrator-workers.
- Clear pass/fail bar with room to improve: evaluator-optimizer.
- Dynamic tool use and planning: a full ReAct-style agent.
References
- Anthropic, Building effective agents: https://www.anthropic.com/engineering/building-effective-agents
- AI Cookbook patterns: https://cookbook.4mlabs.io/patterns
- AI Cookbook agent memory: https://cookbook.4mlabs.io/recipes/agent-memory-squish