Are you the author? Sign in to claim
20 runnable LLM agent design patterns in Python, benchmarked, traced, offline-compatible. ReAct, multi-agent, constituti
20 production-ready LLM agent design patterns in Python, each runnable offline, benchmarked against the others, and traced step by step. From simple Prompt Chaining to multi-agent orchestration, ReAct loops, and constitutional AI. No API key required.

If this helps you compare agent patterns, a ⭐ helps others find it too.
Also by the author:
- RAG Interview System — Retrieval-Augmented Generation pipeline for technical interview prep
- AI System Design Interview — Structured guides and patterns for AI/ML system design interviews
Most LLM agent design pattern repositories give you isolated tutorials with no way to compare them. They don't tell you which pattern to reach for, and they won't run without an API key and 30 minutes of setup.
This repo answers the question you actually have: which agentic AI pattern fits my task, and why? It runs the same four tasks through all 20 patterns in offline mock mode and prints a single tradeoff table, cost, latency, and reliability side by side. Every run is traced: you can watch each reasoning step, tool call, and observation as it happens.
No API key needed — every pattern runs against a deterministic offline mock:
make install # install the package and dev deps
make demo # run ReAct in mock mode — prints the trace tree
make bench # run all 20 patterns on 4 tasks — prints the tradeoff table
To run against a live model:
cp .env.example .env # fill in ANTHROPIC_API_KEY
python patterns/07-react/example.py
Run any individual pattern offline:
make routing-demo # Routing
make memory-demo # Memory-Augmented
make debate-demo # Debate
# … see Makefile for all per-pattern targets
Every pattern imports from shared/ and stays provider-agnostic. Setting USE_MOCK=1 (or leaving ANTHROPIC_API_KEY unset) swaps AnthropicClient for MockClient transparently — the pattern code is identical in both modes.
┌────────────────────────────────────┐ ┌──────────────────────┐
│ patterns/NN-name/ │ │ bench/ │
│ pattern.py · example.py · tests │ │ compare.py │
└──────────────┬─────────────────────┘ └──────────┬───────────┘
│ imports │ imports
└──────────────┬────────────────────┘
┌──────────▼───────────┐
│ shared/ │
│ LLMClient protocol │
│ ToolRegistry │
│ Trace / timed_step │
│ Config · Types │
│ Errors · Loader │
└─────┬──────────┬─────┘
│ │
┌────────────▼───┐ ┌───▼────────────────┐
│ AnthropicClient│ │ MockClient │
│ (live mode) │ │ (offline / tests) │
└────────────────┘ └────────────────────┘
| # | Pattern | Status | One-liner |
|---|---|---|---|
| 01 | Prompt Chaining | ✅ | Sequential pipeline of LLM calls; each output feeds the next. |
| 02 | Routing | ✅ | Classify input, dispatch to a specialized handler. |
| 03 | Parallelization | ✅ | Fan out to N independent branches, fan in to one aggregate. |
| 04 | Orchestrator-Workers | ✅ | Orchestrator plans subtasks; workers execute; orchestrator synthesizes. |
| 05 | Evaluator-Optimizer | ✅ | Generate a draft, evaluate against criteria, refine until passing. |
| 06 | Code Execution | ✅ | LLM writes code; a sandbox runs it; result feeds back in a loop. |
| 07 | ReAct | ✅ | Interleave reasoning and acting in a bounded loop. |
| 08 | Reflection | ✅ | Single model critiques its own draft and revises until satisfied. |
| 09 | Plan-and-Execute | ✅ | Model builds a full plan upfront, then executes each step. |
| 10 | Multi-Agent | ✅ | Supervisor selects specialized agents by role and synthesizes results. |
| 11 | Memory | ✅ | ReAct loop augmented with episodic remember / recall / forget tools. |
| 12 | Self-Ask | ✅ | Decompose a question into sub-questions, answer each, then synthesize. |
| 13 | Human-in-the-Loop | ✅ | Pause for human approval before executing checkpointed tools. |
| 14 | State Machine | ✅ | Route an agent through an explicit FSM; LLM picks transitions. |
| 15 | Debate | ✅ | Two agents argue for and against; a neutral judge synthesizes. |
| 16 | Constitutional | ✅ | Generate a draft, critique it against principles, revise until compliant. |
| 17 | Mixture-of-Experts | ✅ | Router selects the best specialist experts; their answers are synthesized. |
| 18 | Speculative | ✅ | Generate N candidate answers, score each, pick the best. |
| 19 | Event-Driven | ✅ | Stateful reactive agent processes a stream of events. |
| 20 | Least-to-Most | ✅ | Decompose a hard problem into sub-problems ordered easy to hard. |
The cheapest and most predictable patterns. Reach for these first.
USE_MOCK=1 python patterns/01-prompt-chaining/example.py
make routing-demo
USE_MOCK=1 python patterns/03-parallelization/example.py
make self-ask-demo
make least-to-most-demo
Improve output quality through loops. Pay in latency; gain in quality.
USE_MOCK=1 python patterns/05-evaluator-optimizer/example.py
USE_MOCK=1 python patterns/08-reflection/example.py
make constitutional-demo
Patterns that call external APIs, run code, or query databases. Use when the model alone isn't enough.
USE_MOCK=1 python patterns/06-code-execution/example.py
make demo
USE_MOCK=1 python patterns/09-plan-and-execute/example.py
make memory-demo
Multiple specialized agents working together. Use when different roles or perspectives add value.
USE_MOCK=1 python patterns/04-orchestrator-workers/example.py
USE_MOCK=1 python patterns/10-multi-agent/example.py
make debate-demo
make moe-demo
Patterns with explicit state, human gates, or structured execution strategies.
make human-loop-demo
make state-machine-demo
make speculative-demo
make event-driven-demo
Every pattern directory includes an interview.md file with 8 questions and answers covering:
INTERVIEW_PREP.md at the repo root is a master index with a recommended study path, organized from foundational to advanced, plus 8 cross-pattern comparison questions that interviewers often ask (e.g., ReAct vs. Plan-and-Execute, Reflection vs. Evaluator-Optimizer, when to use Debate vs. Constitutional).
make bench loads all 20 patterns via load_pattern_module, runs the same four customer-support tasks through each in offline mock mode, and prints a single Rich table.
make bench
The table columns — Pattern, Avg Steps, Avg Tokens, Avg ms, Success Rate — let you compare cost/latency/reliability tradeoffs across every pattern on the same workload. Simple patterns like Routing score the lowest step and token counts; iterative patterns like Debate and Constitutional score higher counts in exchange for more thorough outputs.
Switch to live mode for real latency and token numbers:
cp .env.example .env # set ANTHROPIC_API_KEY
python -m bench.compare
ai-agents-design-patterns/
├── INTERVIEW_PREP.md # master interview index — study path + cross-pattern questions
├── patterns/
│ └── NN-name/
│ ├── pattern.py # implementation — one run_* function + result dataclass
│ ├── example.py # runnable demo with deterministic mock_planner
│ ├── test_pattern.py # pytest tests via load_pattern_module
│ ├── diagram.md # Mermaid flowchart + tradeoff prose
│ └── interview.md # 8 Q&A pairs for interview preparation
├── shared/
│ ├── llm_client.py # LLMClient protocol · AnthropicClient · MockClient · build_client()
│ ├── tools.py # Tool dataclass · ToolRegistry with JSON Schema validation
│ ├── trace.py # Trace / Step · timed_step context manager
│ ├── config.py # Config.from_env() — resolves mock/live mode and all overrides
│ ├── types.py # Message · LLMResponse · ToolCall · ToolResult · Usage
│ ├── loader.py # load_pattern_module("NN-name") — file-path import
│ ├── errors.py # MaxStepsExceeded · ToolValidationError · AgentError
│ └── observability.py # structured JSON logging (AGENT_LOG) + @timed decorator
├── bench/
│ └── compare.py # cross-pattern comparison harness
├── docs/ # static assets (banner image, etc.)
├── Makefile # install · demo · bench · test · per-pattern demo targets
└── pyproject.toml
See CONTRIBUTING.md for the full walkthrough. Short version: duplicate patterns/07-react/, rewrite pattern.py, update example.py and test_pattern.py, write diagram.md and interview.md, then add a row to the pattern table above. The shared client, tool registry, tracing, config, and test style carry over unchanged — adding a pattern is typically a ~50-line diff to pattern.py.
| Variable | Default | Effect |
|---|---|---|
ANTHROPIC_API_KEY | unset | Set to enable live mode |
USE_MOCK | unset | 1/true/yes/on forces mock mode even with a key set |
AGENT_MODEL | claude-opus-4-8 | Model for live calls |
AGENT_MAX_STEPS | 6 | Loop bound passed to patterns |
AGENT_TIMEOUT | 60 | HTTP timeout in seconds |
AGENT_MAX_TOKENS | 1024 | Max tokens per completion |
AGENT_LOG | unset | info/debug for structured JSON logs |
MIT.
⚠️ Experimentelle Skill-Sammlung für deutsches Recht (Arbeits-, Gesellschafts-, Insolvenz-, Datenschutz-, Prozessrecht u
Manage multiple Claude Code agents from TUI or Web with tmux and git worktrees
Project management using GitHub Issues + Git worktrees for parallel agent execution
Core skills library for Claude Code with 20+ battle-tested skills including TDD, debugging, and brainstorming