21 essential patterns for building agentic AI systems. Each one comes with a diagram, a written discussion, a runnable implementation, and a real captured run.
Browse the Patterns · Run the Code · Why the Failing Runs Matter
Every pattern is documented four ways, so you can pick whichever gets the idea across fastest.
| Format | Location | Good for |
|---|---|---|
| Mermaid Diagrams | /mermaid-diagrams |
Seeing the flow at a glance, in plain English |
| Pattern Discussions | /pattern-discussion |
When to use it, where it fits, pros, cons, real examples |
| ASCII Art | /ascii-art |
Pasting into Miro, terminals, or anywhere without rich graphics |
| Runnable Code | /code |
Actually seeing it work, plus a saved run for every pattern |
Each code example lives in its own folder with the run it produced:
code/
├── resources/ # shared LLM client, output helpers, requirements
└── prompt_chaining/
├── code.py # the pattern, commented
└── result.txt # a real captured run, readable without an API key
| # | Pattern | What it does | Links |
|---|---|---|---|
| 1 | Prompt Chaining | Break a complex task into sequential steps | ASCII · Diagram · Discussion · Code · Run |
| 2 | Routing | Direct each request to the right handler | ASCII · Diagram · Discussion · Code · Run |
| 3 | Parallelization | Run independent work concurrently, then merge | ASCII · Diagram · Discussion · Code · Run |
| 4 | Reflection | Critique and revise its own output | ASCII · Diagram · Discussion · Code · Run |
| 5 | Tool Use | Call real functions instead of guessing | ASCII · Diagram · Discussion · Code · Run |
| # | Pattern | What it does | Links |
|---|---|---|---|
| 6 | Planning | Design the whole step list before executing any of it | ASCII · Diagram · Discussion · Code · Run |
| 7 | Multi-Agent Collaboration | Separate roles handing work to each other | ASCII · Diagram · Discussion · Code · Run |
| 8 | Memory Management | Decide what to keep verbatim, summarize, or never drop | ASCII · Diagram · Discussion · Code · Run |
| 9 | Learning and Adaptation | Turn mistakes into rules, without retraining | ASCII · Diagram · Discussion · Code · Run |
| 10 | Model Context Protocol | Reach tools through a contract, not an import | ASCII · Diagram · Discussion · Code · Run |
| # | Pattern | What it does | Links |
|---|---|---|---|
| 11 | Goal Setting and Monitoring | Define "done" up front, then measure against it | ASCII · Diagram · Discussion · Code · Run |
| 12 | Exception Handling and Recovery | Retry, repair, or fall back, depending on the failure | ASCII · Diagram · Discussion · Code · Run |
| 13 | Human-in-the-Loop | Pause for approval on the actions that deserve it | ASCII · Diagram · Discussion · Code · Run |
| 14 | Knowledge Retrieval (RAG) | Answer from fetched documents, not from memory | ASCII · Diagram · Discussion · Code · Run |
| 15 | Inter-Agent Communication | Address agents by capability over a message bus | ASCII · Diagram · Discussion · Code · Run |
| # | Pattern | What it does | Links |
|---|---|---|---|
| 16 | Resource-Aware Optimization | Spend tokens in proportion to the work | ASCII · Diagram · Discussion · Code · Run |
| 17 | Reasoning Techniques | CoT, self-consistency, decomposition, and their cost | ASCII · Diagram · Discussion · Code · Run |
| 18 | Guardrails / Safety | Screen the input, then screen the output separately | ASCII · Diagram · Discussion · Code · Run |
| 19 | Evaluation and Monitoring | Measure quality offline, watch proxies online | ASCII · Diagram · Discussion · Code · Run |
| # | Pattern | What it does | Links |
|---|---|---|---|
| 20 | Prioritization | Order work by score, dependencies, and age | ASCII · Diagram · Discussion · Code · Run |
| 21 | Exploration and Discovery | Search a space of approaches instead of answering once | ASCII · Diagram · Discussion · Code · Run |
Examples use LangChain with NVIDIA NIM endpoints.
1. Install from the code/ directory:
cd code
python -m venv .venv
.venv\Scripts\activate # Windows
source .venv/bin/activate # macOS/Linux
pip install -r resources/requirements.txt2. Add your key to code/resources/.env:
API_KEY=your_nvidia_api_key3. Run any pattern as a module, from inside code/:
python -m prompt_chaining.codeWhy -m, and why underscored folders?
Running python prompt_chaining/code.py directly fails with ModuleNotFoundError: resources, because Python puts the script's folder on the import path rather than code/. The module form keeps code/ on the path, so every example can share resources/.
That is also why the folders use underscores. python -m prompt-chaining.code is not a valid module name.
To save a run alongside the code, the way every committed result.txt was made:
python -m prompt_chaining.code | Tee-Object prompt_chaining\result.txtpython -m prompt_chaining.code | tee prompt_chaining/result.txtPiping makes stdout a non-tty, so rich drops colour and falls back to ASCII table borders. The content is identical.
See code/README.md for the full module list and setup detail.
Every result.txt is real output from the committed code, not a hand-written illustration. Several of them record the pattern failing, plateauing, or costing more than it saved. Those runs were kept deliberately, because they teach more than a clean one does.
| Pattern | What its run actually shows |
|---|---|
| Evaluation and Monitoring | The scoreboard's verdict is wrong. The grader marked 1 incorrect against an answer key saying one. A broken eval doesn't look broken, it looks like a result. |
| Reasoning Techniques | All four techniques tie, including the "direct" baseline. Decomposition spent 4 calls to reach what 1 call already had. |
| Goal Setting and Monitoring | Ends in recorded failure. Fixing the missing specs breaks the word limit, because constraint satisfaction isn't monotonic. |
| Human-in-the-Loop | The risk assessor gates a routine receipt email as irreversible. Over-gating, live. |
| Reflection | Never converges. The critic spends three rounds on progressively more marginal objections. |
| Exploration and Discovery | An earlier run produced no child that beat its parent. Refinement plateaus fast. |
Each pattern's discussion doc explains what its run revealed and what to do about it.
Note:
temperatureis0.7and several examples depend on model judgement, so your output will differ in wording and token counts. The structure and conclusions should hold.
These patterns are distilled from research on agentic AI systems, made accessible through simple visual representations and clear explanations.
Agentic Design Patterns (full book, PDF)
Improvements and additional patterns are welcome. Open an issue or a pull request.
MIT, so use these patterns freely in your projects.
21 patterns · 21 runnable examples · 21 captured runs