Agent Patterns Documentation
Welcome to the Agent Patterns documentation! This library provides 9 battle-tested AI agent workflow patterns implemented with LangGraph and LangChain.
Breaking Change in v0.2.0
This version is a complete rewrite from the ground up. The previous 0.1.x version used asyncio extensively, which caused significant reliability issues. Version 0.2.0+ uses a synchronous-only architecture for better reliability and easier debugging.
What is Agent Patterns?
Agent Patterns is a Python library that implements proven AI agent architectures as reusable, composable patterns. Each pattern represents a different approach to building intelligent agents that can reason, plan, reflect, and execute tasks.
Key Features
9 Production-Ready Patterns: ReAct, Reflection, Self-Discovery, STORM, and more
Enterprise-Grade Prompts: 150-300+ line comprehensive system prompts following industry best practices from Anthropic and OpenAI
Synchronous Design: Simple, debuggable code without async complexity
Flexible Customization: Multiple ways to customize prompts and behavior
Type-Safe: Full type hints throughout
Multi-Provider: Works with OpenAI, Anthropic, and other LLM providers
What Makes Agent Patterns Different?
Enterprise-Grade Prompt Engineering
Version 0.2.0 introduces a comprehensive prompt redesign that sets Agent Patterns apart:
9.4x More Detailed System Prompts
System prompts expanded from ~32 lines to 150-300+ lines
Each prompt includes 9 structured sections for maximum clarity and reliability
Comprehensive 9-Section Structure Every system prompt now includes:
Role and Identity: Clear definition of the agent’s purpose and capabilities
Core Capabilities: Explicit CAN/CANNOT boundaries to prevent hallucination
Process: Step-by-step workflow guidance for consistent execution
Output Format: Precise specifications for structured responses
Decision-Making Guidelines: Context-specific rules and best practices
Quality Standards: Clear criteria for excellent vs. poor outputs
Edge Cases: Built-in error handling and special situation guidance
Examples: 2-3 concrete examples demonstrating expected behavior
Critical Reminders: Key points emphasized for reliability
Benefits
Increased Reliability: Comprehensive guidance reduces errors and inconsistencies
Better Transparency: Clear role definitions and boundaries make agent behavior predictable
Improved Robustness: Edge case handling and quality standards prevent common failures
Professional Output: Industry best practices ensure production-ready results
Maintainability: Consistent structure across all patterns simplifies debugging and updates
Backward Compatible All improvements are transparent to existing code—no changes required. Your agents automatically benefit from enhanced prompts while maintaining the same simple API.
Quick Start
pip install agent-patterns
from agent_patterns.patterns import ReflectionAgent
agent = ReflectionAgent(
llm_configs={
"documentation": {"provider": "openai", "model": "gpt-4"},
"reflection": {"provider": "openai", "model": "gpt-4"}
}
)
result = agent.run("Write a blog post about AI agents")
print(result)
# Now benefits from enterprise-grade prompts automatically!
Your Learning Journey
1. Start Here: Understanding Patterns
Begin by understanding what agent patterns are and how they differ:
What Are Agent Patterns? - Core concepts
Choosing the Right Pattern - Decision guide
Pattern Comparison Matrix - Side-by-side comparison
2. Learn Individual Patterns
Dive deep into each pattern with theory, examples, and use cases:
Foundational Patterns (Start Here)
ReAct Agent - Reason + Act with tool use
Reflection Agent - Generate, critique, refine
Planning & Execution
Plan & Solve Agent - Structured decomposition
Self-Discovery Agent - Dynamic reasoning selection
REWOO Agent - Efficient planner-worker pattern
Advanced Reasoning
Reflexion Agent - Learning from failures
LATS Agent - Tree search over reasoning paths
LLM Compiler Agent - Parallel task execution
Research & Synthesis
STORM Agent - Multi-perspective research
3. Customize Your Agents
Learn how to tailor patterns to your specific needs:
Prompt Customization Guide - Complete customization reference
Custom Instructions - Add domain expertise
Prompt Overrides - Programmatic control
Setting Agent Goals - Configure objectives
4. Build Production Systems
Ready to deploy? Learn best practices:
API Reference - Complete API documentation
Configuration Guide - LLM setup and tuning
Error Handling - Robust error management
Testing Strategies - Test your agents
Deployment Guide - Production deployment
Pattern Overview
Quick reference for all patterns:
Pattern |
Best For |
Complexity |
When to Use |
|---|---|---|---|
ReAct |
Tool-using tasks |
Low |
Need to interact with external tools/APIs |
Reflection |
High-quality content |
Low |
Want iterative refinement of outputs |
Plan & Solve |
Structured problems |
Medium |
Clear decomposable tasks |
Self-Discovery |
Complex reasoning |
Medium |
Need adaptive reasoning strategies |
Reflexion |
Trial-and-error |
Medium |
Learning from failures is important |
REWOO |
Efficient planning |
Medium |
Cost-conscious tool usage |
LATS |
Exploration tasks |
High |
Need to explore multiple solution paths |
LLM Compiler |
Parallel execution |
High |
Independent subtasks that can run concurrently |
STORM |
Research synthesis |
High |
Multi-perspective research reports |
Use Case Quick Finder
Find the right pattern for your use case:
Content Generation
Blog posts, articles → Reflection
Research reports → STORM
Technical documentation → Plan & Solve
Problem Solving
Mathematical problems → Self-Discovery
Code debugging → Reflexion
Complex analysis → LATS
Task Execution
API interactions → ReAct
Multi-step workflows → LLM Compiler
Efficient automation → REWOO
Research & Analysis
Multi-source research → STORM
Comparative analysis → Self-Discovery
Exploratory research → LATS
See the full comparison matrix for detailed use case analysis.
Core Concepts
Agent Patterns
Customization Guides
- Prompt Customization Guide
- Custom Instructions Deep Dive
- Prompt Overrides Deep Dive
- Setting Agent Goals
- Configuration Guide
- Overview
- LLM Configuration Structure
- Provider Configuration
- Model Parameters
- Role-Based Configuration
- Pattern-Specific Parameters
- Environment Variables
- Cost Optimization
- Performance Optimization
- Quality Optimization
- Configuration Profiles
- Configuration Best Practices
- Troubleshooting
- Next Steps
- Reference
Advanced Topics
Support & Community
GitHub: osok/agent-patterns
Issues: Report bugs or request features
PyPI: agent-patterns
License
Agent Patterns is licensed under the MIT License. See LICENSE for details.