Skip to content

huangjia2019/agent-design-patterns

Repository files navigation

Agent Design Patterns

A 7×6 framework for agent architecture. 28 patterns, each placed at a coordinate, each with runnable code and a verified engineering slice from real production codebases.

The model spends. The harness budgets. This repo is the vocabulary you can put in your project tomorrow.

简体中文 README · Manning · Designing AI Agents · Paper · arXiv:2605.13850 · 极客时间专栏 · Newsletter · Author site

Looking for the full Argus running example as one evolving codebase, organized by book chapter? See the companion repo huangjia2019/designing-ai-agents — Argus grows module by module from Ch2 to Ch10, with each chapter's patterns/ + argus/ side by side. That repo follows the book's narrative; this repo is the standalone pattern catalog.


The book

Designing AI Agents — Manning

Designing AI Agents — the design-pattern catalogue for production AI agents. (Manning)


The framework comes from a paper

A Two-Dimensional Framework for AI Agent Design Patterns — arXiv:2605.13850

The two-axis framework, the 27 named patterns, and the five pattern-selection laws are introduced in A Two-Dimensional Framework for AI Agent Design Patterns: Cognitive Function × Execution Topology (Huang & Zhou, arXiv:2605.13850). This repository is the runnable companion to the paper.


Why this exists

Most "agent architecture" guides give you a flat list — Reflection, ReAct, Multi-Agent, Tree of Thoughts, Reflexive Metacognitive, and so on. A flat list answers what patterns exist. It does not answer where my problem sits, and which pattern lives at that coordinate.

A loan-evaluation agent crashes not because Reflection is missing but because Perception-stage budget allocation dropped the disqualifying document. A multi-agent code reviewer drifts not because ReAct is wrong but because two Reflection critics contradict each other and there is no governance gate to resolve it. These are not different patterns — they are patterns sitting at specific coordinates in a structured design space. Without the coordinates you can't see them.

This repo gives you the coordinates.


The two-axis framework

Every agent pattern sits at the intersection of two orthogonal axes.

  • Cognitive functionwhat the agent is doing ↳ perceive · remember · reason · act · reflect · collaborate · govern
  • Execution topologyhow the work is laid out at runtime ↳ single-step · sequential · parallel · loop · router · hierarchy

Seven × six = 42 cells. The 28 cells where interesting patterns live are the chapters of Designing AI Agents (Manning) and the lectures of the 极客时间 column.

The framework's claim is not that everything fits the matrix. The claim is that giving a pattern a coordinate forces an answer to "why is this pattern here and not somewhere else". A flat list lets you skip the question. A matrix does not.


The matrix — click into any pattern

Two-Axis Framework matrix: 7 cognitive functions × 6 execution topologies = 42 cells, 28 patterns

Every pattern below lives at one coordinate. Click any pattern name to enter that folder's code and README. Cells marked ✅ have runnable code; cells marked 🟡 are scaffolded.

Chain Parallel Route Loop Orchestrate Hierarchy
Perceive Semantic Compaction ✅ Multi-Modal Fusion ✅ Context Triage ✅ Progressive Discovery ✅
Remember RAG ✅ Hierarchical Retention ✅ Failure Journals ✅ Progress Tracking ✅
Reason Chain of Thought ✅ Parallel Exploration ✅ Complexity Routing ✅ Iterative Hypothesis ✅
Act Prompt Chaining ✅ Tool Dispatch ✅ Plan & Execute ✅ Guardrail Sandwich ✅
Reflect Generator-Critic 🟡 Skill Package 🟡 Self-Heal Loop 🟡 Experience Replay 🟡
Collaborate Handoff Chain 🟡 Fan-out & Gather 🟡 Adversarial Review 🟡 Hierarchical Delegation 🟡
Govern Progressive Commitment 🟡 Approval Gate 🟡 Observability Harness 🟡 Blast Radius 🟡

Composition (putting patterns together): Pattern Selection Card · Six-Step Methodology · Argus Full Case Study · Checklist Benchmark Case

The 14 empty cells mark either industry gaps no production harness has filled yet, or topology-function combinations whose patterns haven't crystallized.

Each pattern folder follows the same shape: pattern.py (the minimal honest reference, 50–250 lines), example.py (a real-scenario case that runs without API keys), test_pattern.py (the invariants the pattern must hold), and bilingual README.md / README.zh-CN.md.


Engineering slices — verified, not hallucinated

Every pattern's README cites real production code. Citations are file-and-line in upstream open-source projects, verified at the time of writing. If you find a citation that no longer matches the upstream code, open an issue — that's a bug, not a documentation choice.

Pattern Upstream slices cited
Context Triage Aider's RepoMap, Claude Code memory hierarchy, DeerFlow schema-driven triage
Semantic Compaction OpenHands condenser_config, Aider history.py, Manus Context Engineering blog
Hierarchical Retention Claude Code 4-layer memory, MemGPT virtual memory hierarchy (arxiv:2310.08560)
RAG Anthropic Contextual Retrieval, Reciprocal Rank Fusion (Cormack 2009), agentic-search vs. RAG decomposition
Progress Tracking Claude Code TodoWrite (three fields), DeepAgents TodoListMiddleware, DeerFlow context-loss detection, Anthropic effective-context-engineering (U-shaped attention)
Failure Journals Hermes Agent error_classifier (13 FailoverReason), Aider self-heal loop, Manus Context Engineering, arxiv:2509.25370 Where LLM Agents Fail
Chain of Thought Claude Code thinking three iron rules (query.ts:151-163), Hermes _strip_reasoning_tags, Anthropic Think-as-Tool (Tau-bench +20pp), OpenAI 2026 CoT controllability + monitorability
Complexity Routing Claude Code FallbackTriggeredError, Hermes 6-tier ReasoningEffort, Aider --model + --weak-model, Anthropic Building Effective Agents
Parallel Exploration Wang 2022 Self-Consistency, Yao 2023 Tree of Thoughts, CoT-PoT N=2 → 90% of N=10 lift, DeerFlow isolated event-loop
Iterative Hypothesis Anthropic 2026 three-agent harness (Planner/Generator/Evaluator), ReAct (Yao 2022), ReWOO (Xu 2023), Self-Refine (Madaan 2023), Karl Popper falsificationism
Tool Dispatch Claude Code Tool.ts 14-field schema, Anthropic Programmatic Tool Calling, Codex CLI execpolicy crate, arxiv:2602.14878 MCP Tool Descriptions Are Smelly, OWASP Top 10 for Agentic Apps 2026 A2, Manus 32-tool ceiling
Plan-and-Execute Aider architect_coder.py (9-line core), Claude Code ExitPlanMode (plan-as-file), LangGraph 1.0 BSP/Pregel, Manus todo.md, Anthropic Adaptive Replanning
Prompt Chaining Aider history.py 49-line recursive chain, Claude Code PRA loop + Skills + slash commands, Anthropic Building Effective Agents, Anthropic prompt best practices (XML structure), Doug McIlroy Unix philosophy
Guardrail Sandwich Claude Code Hooks Pipeline (12 lifecycle events; PreToolUse blocks), OWASP Top 10 for Agentic Apps 2026 A1/A2/A3, NVIDIA NeMo Guardrails (Colang 4-rail), GuardrailsAI (RAIL spec), Microsoft Guidance (grammar-level), arxiv:2509.23994 Policy-as-Prompt Synthesis

The eight production harnesses the framework tracks: Claude Code, Codex CLI, Aider, OpenCode, OpenClaw, Hermes Agent, DeepAgents, DeerFlow, OpenHands. Each pattern's README pulls from at least one of these to show the pattern in real production form, not toy form.


What this repo is not

  • Not a framework. Use LangGraph, agno, DeerFlow, or OpenHands for a production runtime. This repo is the design vocabulary you apply on top of any of them. Switching frameworks does not change the matrix.
  • Not a flat catalog. A list answers what patterns exist. The matrix answers where a problem sits and which patterns are wrong for that position.
  • Not toy code. Every pattern.py is small (50–250 lines) on purpose, but it is honest code with real invariants and tests. Each example.py runs on data shaped like production. Engineering slices in the READMEs cite verified upstream files.

Quickstart

git clone https://github.com/huangjia2019/agent-design-patterns.git
cd agent-design-patterns
python -m venv .venv && source .venv/bin/activate
pip install -e ".[dev]"

# Run a pattern's case
python perception/a-context-triage/example.py
python perception/b-semantic-compaction/example.py

# Run all invariant tests
pytest

Each pattern folder is self-contained. No central framework, no plugin system to learn. Read the folder's README, look at pattern.py, run example.py, read the tests.


How to read a pattern folder

<pattern-folder>/
  README.md                # The why — what failure mode this pattern catches
  README.zh-CN.md          # 中文版
  pattern.py               # The minimal honest implementation
  example.py               # A runnable case on production-shaped data
  test_pattern.py          # The invariants the pattern must hold

Read the README first — it's the why and the upstream slice. Then read pattern.py to see the smallest amount of code that solves it. Run example.py to see it work on data with shape. Tests pin the invariants you must not break when adapting.


The thesis behind the framework

Three lines from the book:

  • Designing an agent is solving a constrained allocation problem.
  • A fixed token budget must be distributed across competing cognitive demands under non-deterministic execution paths.
  • The model is the spender. The harness is the budgeter. The patterns are the strategies.

Every pattern in the matrix is a strategy for one of those three roles — how the harness budgets, how the patterns allocate, how the model is positioned to spend. The matrix is what makes the strategies discussable as a system rather than as a flat list.


Book · Column · Newsletter

Manning · Designing AI Agents The design-pattern catalogue for production AI agents. 27 patterns across 7 cognitive functions and 6 topologies.
极客时间 · 《Agent 设计模式之美》 Chinese-language video column. Pattern-by-pattern walkthrough with engineering slices from real production harnesses.
Substack · Agent Design Patterns Free English newsletter, one essay every 1–2 weeks. Structural observation, not hype.
极客时间 · Claude Code 工程化实战 Published Chinese-language video column on the engineering practice of building agents on Claude Code.

The book gives you the theory. The column gives you the lectures. This repo gives you runnable code.


Author

Jia Huang (黄佳) — Lead Research Engineer at A*STAR Singapore, formerly senior consultant at Accenture Singapore. Twenty years across NLP, LLMs, and AI applications in MedTech and FinTech. Author of two forthcoming English-language books (Designing AI Agents with Manning, RAG from First Principles with Packt) and six Chinese-language books on machine learning, GPT, AI agents, RAG, and data analysis with cumulative readers in the hundreds of thousands.

The two-axis framework is the author's original contribution; the constituent elements (seven cognitive functions, six execution topologies) are not new — the contribution is the orthogonal organization.

kage-ai.com · LinkedIn · Substack · tohuangjia@gmail.com


Contributing

Issues welcome. Particularly useful:

  • Citation drift — a verified engineering slice in a README points at a file or line that no longer matches upstream
  • Invariant violations — a test misses a case that you've seen the pattern fail in production
  • New language ports — TypeScript / Go ports of any pattern, opened as a separate top-level folder
  • New engineering slices — a production harness you've worked with shows the pattern in a form not yet documented in the README

Pull requests for new patterns: please open an issue first to discuss where the pattern sits in the matrix.


Citation

If this framework is useful in your work, please cite the paper:

@misc{huang_zhou_2026_dual_axis,
  author        = {Huang, Jia and Zhou, Joey Tianyi},
  title         = {A Two-Dimensional Framework for AI Agent Design Patterns:
                   Cognitive Function and Execution Topology},
  year          = {2026},
  eprint        = {2605.13850},
  archivePrefix = {arXiv},
  primaryClass  = {cs.AI},
  doi           = {10.5281/zenodo.19036557},
  url           = {https://arxiv.org/abs/2605.13850}
}

License

MIT. See LICENSE.

About

A 7×6 framework for agent architecture. 28 patterns, each placed at a coordinate, runnable Python code with verified engineering slices from Claude Code, Aider, OpenHands, DeerFlow. Companion to Designing AI Agents (Manning) by Jia Huang.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors