Transform your AI applications from simple prompts to sophisticated intelligent systems.
This repo is built around four commitments. They explain what stays in and what gets cut.
- Lean, not exhaustive. This is not a catalog of hundreds of patterns that no human will ever read, understand, or remember. It is a lean catalog meant to be understood and memorized. Long patterns lists are not features; they are noise.
- Hard cap: at most 24 patterns. If a pattern is not necessary, we remove it. If something new is added, something else gets dropped. The ceiling is a forcing function, not an aspiration. Status (2026-05): 29 patterns today; pruning is actively in progress toward the 24-cap, with each cut justified in
diff.md. - Demos must actually work. Every demo runs in an automated weekly smoke test, for both Python and TypeScript β and it must pass. (See
.github/workflows/weekly-smoke.yml.) Educational code that doesn't run is educational code that lies. - Concrete relevance, not just papers. For each pattern we measure how it shows up in real coding agents β currently Pi β and write it down in a
pi.mdinside each pattern folder, plus a repo-wide roll-up with a coverage heat map. We also maintaindiff.mdto disambiguate commonly-confused pattern pairs: if two patterns can't be cleanly told apart, one of them probably doesn't belong here. A pattern that only exists in a paper somewhere is a signal it may not belong either.
AI evolves too quickly for traditional books to stay current, especially in fast-moving areas like agentic systems. Thatβs why this is one of the best βliving booksβ on agentic AI: a comprehensive, hands-on collection of design patterns for building robust AI agents, continuously updated with real-world implementations, practical examples, and detailed architectural guidance for scalable, maintainable AI applications.
- π Academic Foundations
- ποΈ Repository Structure
- ποΈ Patterns at a Glance
- π Foundational Patterns
- π§ Advanced Reasoning Patterns
- π‘οΈ Reliability Patterns
- π― Orchestration Patterns
- π Observability Patterns
- π§© Memory Patterns
- π Learning Patterns
- π Quick Start
- πΊοΈ Pattern Selection Guide
- π Learning Path
- π οΈ Tech Stack
- π Resources
- ποΈ Standards & Compliance
- π How to Cite
- π Acknowledgments
New: Pi implementation analyses
This repository now includes implementation-focused analyses of how they map to Pi, grounded in the actual Pi codebase with package/module references, line-numbered excerpts, and notes on architectural tradeoffs or limitations.
Look for
pi.mdinside pattern folders. These writeups stay conservative: if Pi does not meaningfully implement a pattern, the analysis says so explicitly rather than forcing a match.See the Pi roll-up summary (
pi.md) for a coverage heat map and one-line verdicts across all 28 patterns.
Currently available Pi analyses:
- Foundational: Prompt Chaining, Routing, Parallelization, Reflection, Tool Use, Planning, Multi-Agent Collaboration, ReAct, HITL, Structured Outputs, Computer Use
- Reasoning: Tree of Thoughts, Graph of Thoughts, Exploration & Discovery, Deep Research
- Reliability: Error Recovery, Guardrails
- Orchestration: Goal Management, Subagents, Skills, Agent Communication, MCP, Prioritization
- Observability: Evaluation & Monitoring, Resource Optimization
- Memory: Memory Management, Context Management
- Learning: Adaptive Learning
This repository implements design patterns grounded in peer-reviewed research and industry best practices. Key academic contributions include:
- ReAct: Synergizing Reasoning and Acting in Language Models (Yao et al., 2022, ICLR 2023) Foundational paper demonstrating that interleaving reasoning traces with actions creates synergy superior to separate reasoning or acting approaches. Directly implemented in our ReAct pattern.
-
Tree of Thoughts: Deliberate Problem Solving with Large Language Models (Yao et al., 2023, NeurIPS 2023) Generalizes Chain-of-Thought by enabling exploration over coherent reasoning paths with self-evaluation and backtracking. Implemented in our Tree of Thoughts pattern.
-
Graph of Thoughts: Solving Elaborate Problems with Large Language Models (Besta et al., 2023) Extends reasoning to arbitrary graph structures, enabling thought merging and non-hierarchical connections. Achieves 62% quality improvement with 31% cost reduction. Implemented in our Graph of Thoughts pattern.
- Agentic Retrieval-Augmented Generation: A Survey on Agentic RAG (Singh et al., 2025) Comprehensive survey of autonomous AI agents managing retrieval strategies through reflection, planning, tool use, and multi-agent collaborationβtranscending static RAG limitations. Informs our RAG and Multi-Agent patterns.
These patterns represent the evolution from:
- Chain-of-Thought (linear reasoning) β Tree of Thoughts (branching exploration) β Graph of Thoughts (networked reasoning)
- Static RAG (fixed retrieval) β Agentic RAG (autonomous, adaptive retrieval)
- Single-agent systems β Multi-agent collaboration with specialized roles and communication protocols
agentic_design_patterns/
βββ foundational_design_patterns/
β βββ 1_prompt_chain/ # Sequential task decomposition
β βββ 2_routing/ # Intelligent query routing
β βββ 3_parallelization/ # Concurrent execution
β βββ 4_reflection/ # Iterative refinement
β βββ 5_tool_use/ # External system integration
β βββ 6_planning/ # Strategic task planning
β βββ 7_multi_agent_collaboration/ # Coordinated agents
β βββ 8_react/ # Reasoning and acting
β βββ 9_rag/ # Retrieval-augmented generation
β βββ 10_hitl/ # Human-in-the-loop
β βββ 11_structured_outputs/ # Schema-constrained outputs
β βββ 12_computer_use/ # Browser/UI automation
β
βββ reasoning/ # Advanced reasoning patterns
β βββ tree_of_thoughts/ # Systematic exploration
β βββ graph_of_thoughts/ # Non-hierarchical reasoning
β βββ exploration_discovery/ # Novel solution discovery
β βββ deep_research/ # Iterative research loops
β
βββ reliability/ # Safety and resilience
β βββ error_recovery/ # Failure handling
β βββ guardrails/ # Safety constraints
β
βββ orchestration/ # Multi-agent coordination
β βββ goal_management/ # Objective decomposition
β βββ subagents/ # Orchestrator-worker topology
β βββ skills/ # Agent-loadable capability packages
β βββ agent_communication/ # Inter-agent messaging
β βββ mcp/ # Model Context Protocol
β βββ prioritization/ # Task ranking
β
βββ observability/ # Monitoring and optimization
β βββ evaluation_monitoring/ # Metrics and quality
β βββ resource_optimization/ # Cost and performance
β
βββ memory/ # Context and history
β βββ memory_management/ # Long-term memory
β βββ context_management/ # Context optimization
β
βββ learning/ # Continuous improvement
β βββ adaptive_learning/ # Learning from feedback
β
βββ tests/ # Repo-level reliability smoke tests
βββ .github/workflows/ # CI workflows
βββ repo_support.py # Shared runtime/bootstrap helper
βββ .env # Environment variables
βββ LICENSE # MIT License
βββ README.md # This file
One-row-per-pattern index for fast navigation. Each row links to the pattern's deep-dive directory; the Pi column links to its pi.md implementation analysis where available; the TS column marks patterns with a Bun/TypeScript port under <pattern>/typescript/.
| # | Pattern | Category | Pi Analysis | TypeScript |
|---|---|---|---|---|
| 1 | Prompt Chaining | Foundational | pi | β |
| 2 | Routing | Foundational | pi | β |
| 3 | Parallelization | Foundational | pi | β |
| 4 | Reflection | Foundational | pi | β |
| 5 | Tool Use | Foundational | pi | β |
| 6 | Planning | Foundational | pi | β |
| 7 | Multi-Agent Collaboration | Foundational | pi | β |
| 8 | ReAct | Foundational | pi | β |
| 9 | RAG | Foundational | β | β |
| 10 | Human-in-the-Loop (HITL) | Foundational | pi | β |
| 11 | Structured Outputs | Foundational | pi | β |
| 12 | Computer Use | Foundational | pi | β |
| 13 | Tree of Thoughts | Reasoning | pi | β |
| 14 | Graph of Thoughts | Reasoning | pi | β |
| 15 | Exploration & Discovery | Reasoning | pi | β |
| 16 | Deep Research | Reasoning | pi | β |
| 17 | Error Recovery | Reliability | pi | β |
| 18 | Guardrails | Reliability | pi | β |
| 19 | Goal Management | Orchestration | pi | β |
| 20 | Subagents | Orchestration | pi | β |
| 21 | Skills | Orchestration | pi | β |
| 22 | Agent Communication | Orchestration | pi | β |
| 23 | MCP | Orchestration | pi | β |
| 24 | Prioritization | Orchestration | pi | β |
| 25 | Evaluation & Monitoring | Observability | pi | β |
| 26 | Resource Optimization | Observability | pi | β |
| 27 | Memory Management | Memory | pi | β |
| 28 | Context Management | Memory | pi | β |
| 29 | Adaptive Learning | Learning | pi | β |
1οΈβ£ Prompt Chaining
Break complex tasks into sequential, manageable steps
# Transform a monolithic prompt into a chain of specialized prompts
input β extract_data β transform β validate β final_outputWhen to use:
- Multi-step transformations (data extraction β analysis β formatting)
- Tasks requiring intermediate validation
- Complex workflows that benefit from decomposition
Key benefits:
- π― Better accuracy through focused prompts
- π Easier debugging with visible intermediate steps
- π Reusable components across workflows
π Learn More β Β· π Pi Analysis β
2οΈβ£ Routing
Intelligently direct queries to specialized handlers
# Dynamic routing based on query classification
user_query β classifier β [technical_expert | sales_agent | support_bot]When to use:
- Multi-domain applications (support, sales, technical)
- Specialized model selection (fast/cheap vs. slow/accurate)
- Intent-based workflows requiring different processing paths
Key benefits:
- π° Cost optimization (use expensive models only when needed)
- β‘ Performance gains (route simple queries to fast handlers)
- π¨ Specialized handling (domain experts for domain queries)
π Learn More β Β· π Pi Analysis β
3οΈβ£ Parallelization
Execute independent operations simultaneously for dramatic speedups
# Sequential: 15 seconds # Parallel: 5 seconds
task_a(5s) β task_a(5s) β
task_b(5s) β vs. task_b(5s) β combine β output
task_c(5s) β output task_c(5s) βWhen to use:
- Multiple API calls (search engines, databases, external services)
- Parallel data processing (analyze multiple documents)
- Multi-source research or content generation
Key benefits:
- β‘ 2-10x faster execution for I/O-bound tasks
- π Better resource utilization
- π Improved user experience through reduced latency
π Learn More β Β· π Pi Analysis β
4οΈβ£ Reflection
Iteratively improve outputs through systematic critique and refinement
One of the four core agentic design patterns (Ng, 2024), reflection enables AI to systematically critique and improve its own outputs.
# Single-shot: 5/10 quality # With reflection: 8.5/10 quality
input β generate β done input β generate β critique β
refine β critique β finalWhen to use:
- High-stakes content (code, legal docs, published articles)
- Complex reasoning tasks (logic puzzles, strategic planning)
- Quality-critical applications where "good enough" isn't enough
Key benefits:
- π― 50-70% higher quality scores
- π Systematic error detection and correction
- π§ Self-improving outputs without human intervention
Trade-offs:
β οΈ 3-5x higher token costs- β±οΈ 4-8x longer execution time
π Learn More β Β· π Pi Analysis β
5οΈβ£ Tool Use
Enable LLMs to interact with external systems and APIs
Essential for grounding LLM outputs in real-world data and actions, tool use is a foundational capability of modern agentic systems (Ng, 2024; Yao et al., 2022).
# Without tools: Limited to training data
# With tools: Access real-time data and take actions
user_query β LLM decides β call_weather_api(location) β integrate_result β responseWhen to use:
- Real-time data retrieval (weather, stock prices, news)
- Private/proprietary data access (databases, CRM systems)
- Precise calculations or code execution
- External actions (send emails, update records, control devices)
Key benefits:
- π Access to live, dynamic information
- π― Precise calculations and data validation
- π§ Integration with existing enterprise systems
- π° Reduced token costs (fetch vs. embed in prompts)
Trade-offs:
β οΈ Added latency per tool call- π Security considerations (authentication, validation)
π Learn More β Β· π Pi Analysis β
6οΈβ£ Planning
Decompose complex goals into structured, executable action plans
A fundamental capability for agentic systems (Ng, 2024), enabling AI to decompose complex objectives strategically rather than responding reactively.
# Without planning: Reactive, incomplete execution
# With planning: Strategic breakdown and systematic execution
complex_goal β analyze β decompose β plan_steps β execute_sequentially β final_resultWhen to use:
- Multi-step workflows requiring orchestration (research reports, data pipelines)
- Tasks with interdependent operations
- Complex problem-solving requiring strategic thinking
- Workflow automation (onboarding, procurement, project setup)
Key benefits:
- π― Structured approach to complex objectives
- π§ Strategic thinking vs. reactive responses
- π Adaptability through dynamic replanning
- π Transparency into execution strategy
Trade-offs:
β οΈ Planning overhead (+20-40% tokens, 5-15s latency)- π οΈ Requires sophisticated state management
π Learn More β Β· π Pi Analysis β
7οΈβ£ Multi-Agent Collaboration
Coordinate multiple specialized agents to solve complex tasks
Multi-agent systems, highlighted in both the Agentic RAG survey (Singh et al., 2025) and production deployments (LangChain, 2024), enable sophisticated task distribution and specialized expertise.
# Agents as a team: specialize roles + coordinate communication
user_goal β manager/planner β [researcher | coder | designer | writer | reviewer] β synthesize β final_outputWhen to use:
- Complex tasks requiring diverse expertise (research + writing + QA)
- Workflows with distinct stages (research β draft β edit β package)
- Tool-specialized roles (web search, code execution, image generation)
- Quality-critical pipelines (critic/reviewer loops)
Key benefits:
- π§© Modularity: build and improve one role at a time
- π‘οΈ Robustness: reviewers catch errors / reduce hallucinations
- β‘ Parallelism: split independent workstreams for speed
- β»οΈ Reuse: agents can be reused across multiple products
Common collaboration models:
- Sequential handoffs (linear pipeline)
- Supervisor/manager orchestration (hierarchical)
- Parallel workstreams (merge results)
- Debate/consensus (evaluate options)
- Criticβreviewer (quality enforcement)
- Network/all-to-all (exploratory, less predictable)
- Custom hybrids (fit domain constraints)
π Learn More β Β· π Pi Analysis β
8οΈβ£ ReAct (Reasoning and Acting) (Yao et al., 2022)
Interleave reasoning traces with tool execution for adaptive problem-solving
Originally introduced by Yao et al. (2022) in the paper "ReAct: Synergizing Reasoning and Acting in Language Models," this pattern demonstrates that interleaving reasoning traces with task-specific actions creates superior synergy compared to treating reasoning and acting as separate capabilities.
# Traditional: Direct action without explicit reasoning
user_query β tool_call β response
# ReAct: Explicit reasoning + grounded actions
user_query β Thought (reason) β Action (tool) β Observation (result) β
Thought (adapt) β Action β Observation β Final AnswerWhen to use:
- Multi-step research requiring information lookup and verification
- Complex problem-solving where the solution path isn't predetermined
- Tasks requiring adaptation based on intermediate results
- Debugging and exploratory analysis
- Need transparent reasoning for interpretability
Key benefits:
- π§ Explicit reasoning traces improve decision quality
- π― Grounded actions reduce hallucinations
- π Dynamic adaptation based on observations
- π Transparent and debuggable decision-making
- β Self-correction and error recovery
Trade-offs:
β οΈ Higher latency (multiple reasoning + action cycles)- π° Increased token costs (reasoning traces + tool calls)
- π Risk of unproductive loops without iteration limits
π Learn More β Β· π Pi Analysis β
Ground LLM responses with relevant external knowledge
This approach, enhanced by agentic capabilities as described in the recent survey by Singh et al. (2025), enables autonomous AI agents to dynamically manage retrieval strategies through reflection, planning, and tool useβtranscending the limitations of static RAG workflows.
# Without RAG: Limited to training data
user_query β LLM β response (may hallucinate)
# With RAG: Knowledge-grounded responses
user_query β retrieve_relevant_docs β augment_context β LLM β grounded_responseWhen to use:
- Dynamic or frequently updated information (documentation, product catalogs)
- Private/proprietary knowledge bases
- Domain-specific expertise beyond LLM training
- Reducing hallucinations with factual grounding
Key benefits:
- π Access to current and proprietary information
- π― Reduced hallucinations through grounding
- π° No retraining needed for knowledge updates
- π Source attribution and transparency
Integrate human oversight and approval into AI workflows
The Human-in-the-Loop (HITL) pattern represents a pivotal strategy in agentic AI systems, deliberately interweaving the unique strengths of human cognitionβsuch as judgment, creativity, and nuanced understandingβwith the computational power and efficiency of AI. This strategic integration ensures that AI operates within ethical boundaries, adheres to safety protocols, and achieves its objectives with optimal effectiveness.
# Without HITL: Fully automated
agent_action β execute β result
# With HITL: Human checkpoint
agent_proposal β human_review β [approve|reject|modify] β execute β resultWhen to use:
- High-stakes decisions (financial transactions, legal actions, sentencing)
- Quality-critical content (publications, customer communications)
- Compliance and regulatory requirements
- Complex scenarios requiring nuanced judgment
- Learning from human expertise for continuous improvement
- Tasks involving ambiguity beyond reliable LLM capabilities
Key aspects:
- Human Oversight: Monitoring AI performance via dashboards/logs to ensure guideline adherence
- Intervention & Correction: Human operators rectify errors or guide agents in ambiguous scenarios
- Feedback for Learning: Human preferences inform agent learning (e.g., RLHF)
- Decision Augmentation: AI provides analysis/recommendations; humans make final decisions
- Human-Agent Collaboration: Cooperative interaction leveraging respective strengths
- Escalation Policies: Protocols dictating when agents escalate tasks to humans
Key benefits:
- π‘οΈ Safety and risk mitigation in critical domains
- β Quality assurance and compliance
- π Continuous learning from human feedback
- π€ Building user trust through transparency
- π― Nuanced judgment in complex scenarios
- π Feedback loops for ongoing improvement
Practical applications:
- Content Moderation: AI filters at scale; humans review ambiguous cases
- Autonomous Driving: AI handles most tasks; humans take control in complex situations
- Financial Fraud Detection: AI flags patterns; human analysts investigate high-risk alerts
- Legal Document Review: AI scans/categorizes; lawyers review for accuracy and implications
- Customer Support: Chatbots handle routine queries; complex/emotional cases escalate to humans
- Data Labeling: Humans provide ground truth labels for training datasets
- Generative AI Refinement: Human editors review/refine LLM outputs for quality and brand alignment
- Autonomous Networks: AI analyzes KPIs; humans approve critical network changes
Trade-offs & caveats:
β οΈ Scalability limitations: Human oversight cannot handle millions of tasks- π₯ Expertise dependency: Effectiveness relies on skilled domain experts
- π Privacy concerns: Sensitive information requires anonymization
- π° Cost considerations: Human review adds operational overhead
"Human-on-the-loop" variation: In this approach, human experts define overarching policies, while AI handles immediate actions to ensure compliance (e.g., automated trading within human-defined rules, call center routing based on manager-set policies).
π Learn More β Β· π Pi Analysis β
1οΈβ£1οΈβ£ Structured Outputs
Enforce schema-valid LLM outputs for reliable downstream automation
# Naive parsing (brittle)
text β prompt_json_request β parse_string_json β runtime_fail
# Structured outputs (reliable)
text β response_schema(Pydantic/JSON Schema) β validated_object β safe_automationKey benefits: Schema guarantees, lower parsing failures, safer agent loops
π Learn More β Β· π Pi Analysis β
1οΈβ£2οΈβ£ Computer Use
Automate browser/UI workflows with explicit safety controls
# Observe β Think β Act loop for UI tasks
screenshot/state β reasoning β ui_action(click/type/navigate) β observation β iterateKey benefits: Legacy-system automation, UI QA workflows, non-API task coverage
π Learn More β Β· π Pi Analysis β
Tree of Thoughts (Yao et al., 2023)
Explore multiple reasoning paths systematically
Introduced at NeurIPS 2023, Tree of Thoughts (ToT) generalizes Chain-of-Thought prompting by enabling LLMs to explore multiple reasoning paths, self-evaluate choices, and backtrack when necessaryβenabling deliberate problem solving for complex tasks.
# Chain of Thought: Linear reasoning
input β step1 β step2 β step3 β answer
# Tree of Thoughts: Branching exploration
input β [thought1, thought2, thought3] β evaluate β expand_best β
[refined_thoughts] β evaluate β solutionKey benefits: Better solutions through systematic exploration, backtracking capability, transparent decision trees
π Learn More β Β· π Pi Analysis β
Graph of Thoughts (Besta et al., 2023)
Enable non-hierarchical thought connections and merging
Building on ToT, Graph of Thoughts extends the reasoning paradigm from hierarchical trees to arbitrary graphs, enabling non-linear thought connections and aggregationβachieving 62% better quality on sorting tasks while reducing costs by 31% (Besta et al., 2023).
# Thoughts can reference and build on ANY other thought (not just parent-child)
input β generate_perspectives β connect_thoughts β aggregate β synthesisKey benefits: Multi-perspective analysis, thought merging, flexible reasoning paths
π Learn More β Β· π Pi Analysis β
Discover novel solutions through guided exploration
# Epsilon-greedy: Balance exploration vs. exploitation
query β [explore_new | exploit_best] β evaluate β update_strategy β iterateKey benefits: Novel solution discovery, avoiding premature convergence, adaptive exploration
π Learn More β Β· π Pi Analysis β
Run iterative research loops with gap-driven follow-up queries
# Plan β Search β Read β Reflect β Follow-up β Synthesize
question β sub_queries β retrieve_sources β identify_gaps β refine_queries β cited_outputKey benefits: Better coverage, fewer blind spots, stronger citation quality
π Learn More β Β· π Pi Analysis β
Gracefully handle failures and self-correct
# Detect β Diagnose β Recover β Verify
operation β [success | failure] β classify_error β [retry | fallback | self_correct] β verifyKey benefits: Resilience, graceful degradation, automatic self-healing, reduced downtime
π Learn More β Β· π Pi Analysis β
Enforce safety constraints and compliance
# Multi-layer validation
input β validate β process β validate_output β [pass | block] β logKey benefits: Safety assurance, compliance, brand protection, risk reduction
π Learn More β Β· π Pi Analysis β
Decompose and track complex objectives
# Hierarchical decomposition with progress tracking
complex_goal β decompose β [subgoal1, subgoal2, subgoal3] β
track_dependencies β execute β monitor β replanKey benefits: Structured execution, progress visibility, adaptive planning, resource optimization
π Learn More β Β· π Pi Analysis β
Spawn focused subagents with isolated context and structured summaries
lead_agent β decompose_task β spawn_workers_parallel β structured_summaries β synthesizeKey benefits: Context isolation, parallel throughput, cleaner synthesis
π Learn More β Β· π Pi Analysis β
Load capability packages on demand via metadata-first discovery
skill_catalog(metadata) β select_relevant_skill β load_SKILL_body β executeKey benefits: Tool-scaling beyond flat lists, lower prompt load, modular capabilities
π Learn More β Β· π Pi Analysis β
Enable agents to coordinate through message passing
# Direct messaging, pub-sub, negotiation protocols
agent1 β message β agent2 β response β agent1Key benefits: Loose coupling, dynamic discovery, scalability, fault tolerance
π Learn More β Β· π Pi Analysis β
Standardized tool and resource integration
# USB for AI: Standard interface for tools/data
LLM β discover_tools β invoke_tool(params) β receive_result β integrateKey benefits: Standardization, reusability, interoperability, composability
π Learn More β Β· π Pi Analysis β
Optimize task ordering and resource allocation
# Multi-criteria scoring with dynamic rebalancing
tasks β score(urgency, impact, effort) β rank β schedule β executeKey benefits: Resource optimization, deadline adherence, fairness, efficiency
π Learn More β Β· π Pi Analysis β
Track performance and quality metrics
# Quantitative + qualitative metrics
operation β collect_metrics β evaluate_quality β aggregate β alert β visualizeKey benefits: Visibility, early detection, data-driven decisions, continuous improvement
π Learn More β Β· π Pi Analysis β
Reduce costs and improve performance
# Caching, batching, model routing
request β [cache_hit | cache_miss] β [cheap_model | expensive_model] β optimizeKey benefits: 65-80% cost reduction, faster responses, better UX
π Learn More β Β· π Pi Analysis β
Maintain conversation history and long-term memory
# Buffer + semantic memory
interaction β store β [buffer_memory | vector_memory] β retrieve_relevant β useKey benefits: Context retention, personalization, learning from history
π Learn More β Β· π Pi Analysis β
Optimize context window usage
# Dynamic selection and compression
content β score_relevance β compress β fit_window β optimizeKey benefits: 70-90% cost reduction, focused responses, better performance
π Learn More β Β· π Pi Analysis β
Improve through feedback and continuous learning
# Learn from outcomes
action β feedback β analyze_patterns β adapt_strategy β improveKey benefits: Continuous improvement, personalization, domain adaptation
π Learn More β Β· π Pi Analysis β
# Python 3.11 or higher
python --version
# Install uv
curl -LsSf https://astral.sh/uv/install.sh | sh# Clone the repository
git clone https://github.com/gtesei/agentic_design_patterns.git
cd agentic_design_patterns
# Set up shared environment
echo "OPENAI_API_KEY=your_api_key_here" > .env- The repository requires Python 3.11+.
- Each pattern folder has its own
pyproject.toml, so runuv syncinside the pattern you want to execute. - Example scripts now use a shared bootstrap helper in
repo_support.pyto:- locate the repo root
- load the root
.env - make the repo importable from any pattern folder
- Set
OPENAI_MODELin your environment if you want to override the default example model:
export OPENAI_MODEL=gpt-4o-mini- If you are behind a corporate SSL interception proxy, SSL bypass is now opt-in:
export AGENTIC_DISABLE_SSL=1Python remains the canonical track. All current foundational patterns also include a Bun/TypeScript port under <pattern>/typescript/.
# Python
cd foundational_design_patterns/3_parallelization
[uv sync]
uv run python src/parallelization.py
# TypeScript
cd foundational_design_patterns/3_parallelization/typescript
[bun install]
bash run.shFoundational patterns with both Python and TypeScript implementations currently live under:
foundational_design_patterns/1_prompt_chainfoundational_design_patterns/2_routingfoundational_design_patterns/3_parallelizationfoundational_design_patterns/4_reflectionfoundational_design_patterns/5_tool_usefoundational_design_patterns/6_planningfoundational_design_patterns/7_multi_agent_collaborationfoundational_design_patterns/8_reactfoundational_design_patterns/9_ragfoundational_design_patterns/10_hitlfoundational_design_patterns/11_structured_outputsfoundational_design_patterns/12_computer_use
For TypeScript workspace conventions, coverage, and runtime details, see typescript_base/TYPESCRIPT.md.
Use these from the repo root:
# Python foundational offline smoke
bash scripts/run_demos_smoke.sh --mode basic
# TypeScript foundational offline smoke
bash scripts/run_demos_smoke_typescript.sh --mode basicGitHub Actions runs the reliability gate on pushes and pull requests:
.github/workflows/reliability-gate.yml- Python shared-runtime smoke via
unittest - foundational TypeScript type-checks via
bun --bun tsc --noEmit - foundational TypeScript offline smoke via
scripts/run_demos_smoke_typescript.sh --mode basic
Need speed? β Routing + Parallelization + Resource Optimization (caching, batching)
Need quality? β Reflection + RAG (grounded knowledge) + Evaluation & Monitoring
Need cost optimization? β Routing + Resource Optimization (65-80% savings) + Context Management
Need both speed AND quality? β Parallelization + Prompt Chaining + RAG
Complex multi-step workflow? β Prompt Chaining + Planning + Goal Management
Independent concurrent tasks? β Parallelization will give you massive speedups
High-stakes output? β Reflection + HITL (human approval) + Guardrails (safety)
External system integration? β Tool Use + MCP (standardized protocols)
Multi-step automation? β Planning + Goal Management + Agent Communication
Multiple roles working together? β Multi-Agent Collaboration + Agent Communication (A2A)
Exploratory multi-step tasks? β ReAct (reasoning + actions) or Tree of Thoughts (exploration)
Need transparent decision-making? β ReAct (explicit reasoning) + Evaluation & Monitoring
Need strict machine-readable outputs? β Structured Outputs + Guardrails
Need UI/browser automation? β Computer Use + HITL
Need iterative cited synthesis? β Deep Research + RAG
Need scalable multi-capability agents? β Subagents + Skills
Knowledge-grounded responses? β RAG retrieves relevant documents before generation
Complex reasoning tasks? β Tree of Thoughts (systematic) or Graph of Thoughts (multi-perspective)
Production reliability? β Error Recovery + Guardrails + Evaluation & Monitoring
Long conversations? β Memory Management + Context Management (optimize windows)
Continuous improvement? β Adaptive Learning + Evaluation & Monitoring (feedback loops)
Resource constraints? β Prioritization + Resource Optimization + Context Management
Phase 1: Foundations (Start Here)
- Prompt Chaining - Foundation for everything
- Routing - Learn to optimize model selection
- Parallelization - Scale your applications
- Reflection - Master quality optimization
- Tool Use - Connect to external systems
Phase 2: Core Patterns 6. RAG - Knowledge-grounded responses 7. ReAct - Reasoning + acting 8. Planning - Strategic decomposition 9. HITL - Human oversight 10. Multi-Agent - Agent coordination
Phase 3: Advanced Reasoning 11. Tree of Thoughts - Systematic exploration 12. Graph of Thoughts - Multi-perspective reasoning 13. Exploration & Discovery - Novel solutions
Phase 4: Production Patterns 14. Error Recovery - Resilience 15. Guardrails - Safety 16. Evaluation & Monitoring - Metrics 17. Resource Optimization - Cost/performance
Phase 5: Orchestration & Memory 18. Goal Management - Objective tracking 19. Agent Communication - Messaging 20. MCP - Standardized integration 21. Prioritization - Task ranking 22. Memory Management - Context retention 23. Context Management - Optimization
Phase 6: Continuous Improvement 24. Adaptive Learning - Learning from feedback 25. Structured Outputs - Schema reliability 26. Computer Use - Browser/UI automation 27. Subagents - Orchestrator-worker topology 28. Skills - Capability packages 29. Deep Research - Iterative research loops
Each pattern builds on concepts from previous ones. Start with Phase 1, then explore other phases based on your needs.
- LangChain - Comprehensive framework for LLM applications
- LangGraph - Stateful workflows and multi-agent orchestration
- LangSmith - LLM application monitoring and evaluation
- OpenAI Models - Primary provider used throughout the examples, configured via environment variables
- Anthropic Claude - Alternative frontier-model family with strong long-context support
- Other LLM Providers - Fully compatible through LangChain abstractions
- Pydantic - Data validation and structured outputs
- Python 3.11+ - Modern Python features (match/case, typing)
- uv - Fast Python package manager
Reasoning & Planning:
- ReAct: Synergizing Reasoning and Acting in Language Models (Yao et al., 2022) - ICLR 2023
- Tree of Thoughts: Deliberate Problem Solving with Large Language Models (Yao et al., 2023) - NeurIPS 2023
- Graph of Thoughts: Solving Elaborate Problems with Large Language Models (Besta et al., 2023)
Retrieval-Augmented Generation:
- Agentic Retrieval-Augmented Generation: A Survey on Agentic RAG (Singh et al., 2025)
- Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks (Lewis et al., 2020)
- Agentic Design Patterns: A Hands-On Guide to Building Intelligent Systems - Antonio GullΓ (Springer Nature, 2024) - Primary inspiration for this repository
- Building LLM Powered Applications - Valentina Alto (Packt/O'Reilly, 2024)
- Hands-On Large Language Models - Jay Alammar & Maarten Grootendorst (O'Reilly, 2024)
Foundational Courses:
- Agentic AI with Andrew Ng (DeepLearning.AI, 2024) - Covers reflection, tool use, planning, and multi-agent collaboration
Framework-Specific:
- LangChain Academy - Official LangChain courses
- LangGraph Tutorials - Stateful agent workflows
- OpenAI Cookbook - Function calling and agent patterns
- Anthropic Prompt Engineering Interactive Tutorial
Official Framework Documentation:
- LangChain Documentation
- LangGraph Documentation
- Microsoft AutoGen
- OpenAI Function Calling Guide
- OpenAI Agents Platform
- Anthropic Prompt Engineering Guide
Production Best Practices:
- LangChain: Top 5 LangGraph Agents in Production 2024 - Real-world deployments
- Weights & Biases: Agentic RAG Guide
Curated Collections:
- Awesome-LangGraph - Comprehensive LangGraph ecosystem index
- Prompt Engineering Guide - Comprehensive guide covering latest papers and techniques
- Learn Prompting - Free generative AI guide
Related Projects:
- Papers with Code: Agents - Latest research with implementations
- arXiv: Artificial Intelligence - Recent AI papers
- Hugging Face Papers - Trending ML research
Organizations deploying agentic AI systems should consider the NIST AI Risk Management Framework and associated guidance:
- NIST AI Risk Management Framework (AI RMF 1.0) (January 2023) Voluntary framework to manage AI risks based on four core functions: Govern, Map, Measure, and Manage.
- NIST AI RMF: Generative AI Profile (NIST.AI.600-1) (July 2024) Addresses risks unique to Generative AI, including governance, content provenance, pre-deployment testing, and incident disclosure. Includes catalog of 400+ mitigation actions.
| NIST AI RMF Function | Relevant Patterns |
|---|---|
| Govern | Human-in-the-Loop, Guardrails |
| Map | Planning, Goal Management |
| Measure | Evaluation & Monitoring, Adaptive Learning |
| Manage | Error Recovery, Guardrails |
- Transparency: ReAct pattern provides explicit reasoning traces for auditability
- Human Oversight: HITL pattern enables approval workflows
- Safety Constraints: Guardrails pattern enforces compliance boundaries
- Evaluation: Monitoring pattern tracks quality and bias metrics
- Error Recovery: Graceful degradation and incident response
- AI Executive Order 14110
- EU AI Act
- ISO/IEC 42001:2023 - AI Management System standard
This project is licensed under the MIT License - see the LICENSE file for details.
If you reference this catalog in academic or professional work, please cite:
@misc{tesei_agentic_design_patterns,
author = {Tesei, Gino},
title = {Agentic Design Patterns: A Hands-On Catalog for Building Intelligent Systems},
year = {2024},
publisher = {GitHub},
howpublished = {\url{https://github.com/gtesei/agentic_design_patterns}},
note = {MIT License}
}This repository's structure and approach were inspired by:
GullΓ, Antonio, Agentic Design Patterns: A Hands-On Guide to Building Intelligent Systems, Springer Nature Switzerland, 2024.
Ng, Andrew, Agentic AI, DeepLearning.AI, 2024.
We gratefully acknowledge the research contributions that ground these patterns:
- Yao, Shunyu et al. - ReAct and Tree of Thoughts frameworks
- Singh, Aditi et al. - Agentic RAG survey and taxonomy
- Besta, Maciej et al. - Graph of Thoughts methodology
- Lewis, Patrick et al. - Foundational RAG research
Special thanks to:
- The LangChain and LangGraph teams for building production-grade agentic frameworks
- The open-source AI community for advancing the state of the art
- NIST for providing guidance on trustworthy AI development
- Claude Code for assistance in developing and refining the implementations in this repository
- All contributors who help improve these patterns
If you find this repository helpful, please consider giving it a star! It helps others discover these patterns.
Built with β€οΈ for the AI developer community