This repository contains complete, production-ready implementations of all 21 design patterns from the Agentic Design Patterns book. Each project demonstrates a specific pattern with a practical, runnable application.
Note: This is an educational resource for learning AI agent design patterns. All code is MIT licensed and ready for experimentation.
- π All 21 Patterns Implemented
- π οΈ Quick Start
- ποΈ Project Structure
- π Pattern Categories
- π¦ Requirements
- π» Usage Examples
- π Learning Path
- π§ Integration
- π Status
- π€ Contributing
- π License
| # | Pattern | Project | Description |
|---|---|---|---|
| 1 | Prompt Chainingprompt_chaining/ |
Document Analysis Pipeline | Sequential multi-step processing π Extract β Entities β Summary β JSON |
| 2 | Routingrouting/ |
Smart Request Router | Request classification and delegation π Route to specialized handlers |
| 3 | Parallelizationparallelization/ |
Parallel Document Processor | Concurrent task execution β‘ 5 parallel analysis tasks with synthesis |
| 4 | Reflectionreflection/ |
Self-Improving Content Generator | Generate β Critique β Refine π Iterative content improvement |
| 5 | Tool Usetool_use/ |
Research Assistant with Tools | Function calling and tool integration π οΈ Search, calculate, analyze with tools |
| 6 | Planningplanning/ |
Task Planning System | Goal decomposition and execution π Break goals into actionable tasks |
| 7 | Multi-Agentmulti_agent/ |
Collaborative Team System | Multiple specialized agents working together π₯ Research β Write β Edit β Coordinate |
| 8 | Memorymemory/ |
Conversation Memory System | State persistence and context management π§ Maintain conversation history |
| # | Pattern | Project | Description |
|---|---|---|---|
| 9 | Adaptationadaptation/ |
Adaptive Agent | Learning from feedback π Improve over time based on experience |
| 10 | MCPmcp/ |
Model Context Protocol Integration | Standardized agent communication π Tool sharing and resource access |
| 11 | Goal Settinggoal_setting/ |
Goal-Oriented Agent | Goal breakdown and progress tracking π― Set goals, track progress, achieve objectives |
| 12 | Exception Handlingexception_handling/ |
Robust Agent with Fallback | Error handling and recovery π‘οΈ Graceful failure handling |
| 13 | Human-in-the-Loophuman_in_loop/ |
Interactive Agent | Human escalation and feedback π€ Customer support with escalation |
| 14 | RAGrag/ |
Knowledge Retrieval System | Retrieval-Augmented Generation π Document-based Q&A |
| # | Pattern | Project | Description |
|---|---|---|---|
| 15 | Inter-Agent Communicationinter_agent/ |
Agent Communication System | Agent-to-agent messaging π¬ Agents collaborating via messages |
| 16 | Resource Optimizationresource_optimization/ |
Resource Optimizer | Efficient resource usage β‘ Caching, batching, cost optimization |
| 17 | Reasoningreasoning/ |
Chain-of-Thought Agent | Step-by-step reasoning π§ Complex problem solving |
| 18 | Guardrailsguardrails/ |
Safety Agent | Content validation and filtering π Safety and compliance checking |
| 19 | Evaluationevaluation/ |
Agent Evaluation System | LLM-as-a-Judge π Quality assessment and monitoring |
| 20 | Prioritizationprioritization/ |
Task Prioritization System | Priority-based task management π Rank and order tasks |
| 21 | Explorationexploration/ |
Exploration Agent | Experimental discovery π Multiple approach testing |
Getting started with any project is straightforward:
# 1. Navigate to the project you want to explore
cd agentic_patterns_projects/prompt_chaining/
# 2. Install the dependencies
pip install -r requirements.txt
# 3. Set up your environment variables
cp .env.example .env
# Edit .env and add your GEMINI_API_KEY
# 4. Run the example
python example.py # Note: Use example.py, not main_file.pyEach project follows a consistent structure that makes it easy to understand and extend:
π prompt_chaining/
βββ π§ document_analyzer.py # Core implementation
βββ π example.py # Usage examples
βββ π README.md # Project documentation
βββ π¦ requirements.txt # Python dependencies
βββ βοΈ .env.example # Environment template
I've organized the patterns into categories to help you understand how they relate:
| Category | Patterns | Description |
|---|---|---|
| π Sequential Patterns | Prompt Chaining, Planning | Linear workflows and goal decomposition |
| β‘ Parallel Patterns | Parallelization | Concurrent task execution |
| π― Decision Patterns | Routing, Reflection, Prioritization | Request routing and iterative improvement |
| π Integration Patterns | Tool Use, Multi-Agent, Inter-Agent Communication, MCP | Agent coordination and tool integration |
| π§ State Patterns | Memory Management, Goal Setting | State persistence and goal tracking |
| π‘οΈ Quality Patterns | Exception Handling, Guardrails, Evaluation | Error handling and quality assurance |
| π Advanced Patterns | Adaptation, RAG, Reasoning, Human-in-the-Loop, Resource Optimization, Exploration | Cutting-edge agent capabilities |
Most projects share similar requirements:
- π Python 3.8 or higher
- π Gemini API key (set in your
.envfile) - π LangChain libraries (installed via requirements.txt)
To get started, install the common dependencies:
# Install common dependencies
pip install langchain langchain-google-genai langchain-community python-dotenv
# For specific projects, check their requirements.txt for any additional packagesNote: Make sure you have a valid Gemini API key. You can get one from Google AI Studio.
Here are some quick examples to get you started:
from document_analyzer import DocumentAnalyzer
analyzer = DocumentAnalyzer()
result = analyzer.analyze("Your document text...")
print(result) # Returns structured JSON with extracted entities and summaryfrom smart_router import SmartRouter
router = SmartRouter()
result = router.route("Book me a flight to Paris next week")
print(result) # Routes to travel booking handlerfrom collaborative_team import CollaborativeTeam
team = CollaborativeTeam()
result = team.collaborate("Create a blog post", "Requirements...")
print(result) # Coordinated output from research, writing, and editing agentsIf you're new to agentic design patterns, here's a suggested learning path:
Focus: Fundamentals of agent workflows
- Learn sequential and parallel processing
- Understand basic agent coordination
- Build foundation for advanced patterns
Focus: Production-ready capabilities
- Master adaptation and memory systems
- Implement RAG and human interaction
- Build on core concepts with real-world features
Focus: Enterprise-grade agent systems
- Resource optimization and cost management
- Safety, evaluation, and quality assurance
- Advanced techniques for production deployment
One of the coolest things about these patterns is that you can combine them:
| Pattern Combination | Use Case |
|---|---|
| Routing + Multi-Agent | Complex workflow orchestration |
| RAG + Tool Use | Enhanced knowledge retrieval with external tools |
| Guardrails + Any Agent | Safety and compliance across all systems |
| Evaluation + Planning | Quality monitoring of goal execution |
| Memory + Adaptation | Learning systems with persistent state |
Feel free to experiment and mix patterns to solve your specific problems!
β All 21 patterns are complete and ready to use
Every pattern has been implemented as a production-ready project with:
- Comprehensive documentation and examples
- Proper error handling and type hints
- Architecture diagrams and explanations
- Ready-to-run code with minimal setup
We welcome contributions! Each project is self-contained and can be extended independently.
- π Add more examples and use cases
- π§ Integrate with your own systems
- π Combine patterns in new ways
- π Extend functionality and add new features
- π Report bugs and suggest improvements
- π Improve documentation
- Fork the repository
- Create a feature branch:
git checkout -b feature/amazing-feature - Make your changes and test thoroughly
- Submit a pull request with a clear description
These are educational examples, so feel free to experiment and build on them!
This project is licensed under the MIT License - see the LICENSE file for details.
These projects are educational examples demonstrating agentic design patterns. Use them to learn, experiment, and build your own systems.
- π Issues: Report bugs or request features
- π¬ Discussions: Join community discussions
- π§ Questions: Open an issue with the "question" label
Happy building! π