A collection of AI agent design patterns implemented from scratch using Python and Groq API. Learn how to build reasoning agents, multi-agent systems, and tool-augmented LLMs.
This project implements four fundamental agentic patterns:
Multi-Agent Pattern - Teams of specialized agents working together with dependency management
ReAct Pattern - Reasoning and acting with tool integration
Reflection Pattern - Self-improvement through iterative critique
Tool Pattern - Function calling with automatic schema generation
Built with pure Python - no frameworks, just clean implementations to understand how agents work under the hood.
- Python 3.10+
- Groq API key
# Clone repository
git clone https://github.com/yourusername/agentic-patterns.git
cd agentic-patterns
# Create virtual environment
python -m venv .venv
source .venv/bin/activate # Windows: .venv\Scripts\activate
# Install dependencies
pip install -r requirements.txt
# Configure API key
cp .env.exemple .env
# Add your GROQ_API_KEY to .envfrom multi_agent_pattern import Agent, Crew
with Crew("Research Team") as crew:
researcher = Agent(
name="Researcher",
backstory="Expert researcher",
task_description="Research AI in healthcare",
task_expected_output="List of 3-5 key applications"
)
writer = Agent(
name="Writer",
backstory="Technical writer",
task_description="Write an article about the research",
task_expected_output="2-3 paragraph article"
)
# Define workflow
researcher >> writer
# Execute
results = crew.run()from ReAct_pattern import ReactAgent
from tool_pattern.tool import tool
@tool
def search_web(query: str) -> str:
"""Search for information."""
return f"Results for: {query}"
agent = ReactAgent(tools=[search_web])
response = agent.run("What is the weather in Tokyo?")from reflection_pattern import ReflectionAgent
agent = ReflectionAgent()
result = agent.run(
user_message="Write a binary search function in Python",
generation_prompt="You are a Python expert",
reflection_prompt="Review and critique the code",
n_steps=3
)Coordinate multiple specialized agents with automatic dependency resolution.
Features:
- Topological execution ordering
- Context passing between agents
- Circular dependency detection
- Workflow visualization with graphviz
Use Cases: Content pipelines, research workflows, complex decision systems
Reasoning and Acting - agents think step-by-step and use tools.
Features:
- Explicit reasoning traces
- Dynamic tool calling
- Iterative problem solving
- Observation integration
Use Cases: Data analysis, API interactions, information retrieval
Iterative improvement through generation and critique cycles.
Features:
- Dual-agent system (generator + reflector)
- Multiple refinement iterations
- Automatic quality checking
- Progress tracking
Use Cases: Code generation, content editing, error correction
Extensible function calling with automatic schema generation.
Features:
@tooldecorator for easy integration- Auto-generated JSON schemas
- Runtime type validation
- Plug-and-play design
Use Cases: API wrappers, database operations, calculations
with Crew("Content Creation") as crew:
research = Agent(name="Research", ...)
analyze = Agent(name="Analyze", ...)
write = Agent(name="Write", ...)
research >> analyze >> writewith Crew("Product Dev") as crew:
market = Agent(name="Market", ...)
tech = Agent(name="Tech", ...)
pm = Agent(name="PM", ...)
market >> pm
tech >> pm # Both feed into PM@tool
def calculate(expr: str) -> float:
"""Evaluate math expression."""
return eval(expr)
agent = ReactAgent(tools=[calculate])
agent.run("What is 25 * 37 + 100?")agentic-patterns/
├── multi_agent_pattern/ # Multi-agent orchestration
│ ├── agent.py
│ └── crew.py
├── ReAct_pattern/ # Reasoning and acting
│ └── react_agent.py
├── reflection_pattern/ # Self-improvement
│ └── reflection_agent.py
├── tool_pattern/ # Tool integration
│ ├── tool.py
│ └── tool_agent.py
├── utils/ # Shared utilities
│ └── utils.py
└── tests/ # Examples and tests
├── multi_agent_test.py
├── simple_multi_agent.py
└── tool_agent.py
Run all tests:
python -m tests.multi_agent_testRun specific examples:
python -m tests.simple_multi_agent
python -m tests.tool_agent
python -m tests.reflection_agent_test┌─────────────────────────────┐
│ Agentic Patterns │
└──────────┬──────────────────┘
│
┌──────┼──────┐
│ │ │
┌───▼──┐ ┌─▼──┐ ┌▼────┐
│Multi │ │ReAct│ │Refl │
│Agent │ │ │ │ect │
└──┬───┘ └──┬──┘ └─────┘
│ │
└────►┌──▼──┐
│Tool │
└─────┘
Research Papers:
Related Projects:
MIT License - see LICENSE for details.
Made with Python & Groq
