Skip to main content

Cookbook Overview

Welcome to the AgentRouter Cookbook! This collection provides ready-to-use examples demonstrating how to build multi-agent systems for various use cases.

What You'll Find Here​

Our cookbook contains practical examples that you can adapt for your own projects. Each example includes:

  • 📋 Complete Overview: Problem statement and solution approach
  • 🔄 How It Works: Step-by-step workflow explanation
  • 🏗️ Architecture Diagram: Visual representation of the agent hierarchy
  • 💻 Runnable Code: Complete, working code examples
  • 🎯 Best Practices: Tips and patterns for production use

Available Examples​

1. Customer Service Multi-Agent System​

Build a comprehensive customer service system with specialized agents for technical support, billing, and general inquiries. This example demonstrates multiple worker agents, shared tools, and escalation workflows.

Key Features:

  • Manager coordinating multiple specialized workers
  • Knowledge base integration
  • Ticket creation and routing
  • Sub-workers for specific domains
  • Complete implementation with all tools

Perfect for: Customer support platforms, help desk systems, and automated service centers.


2. Healthcare Diagnosis Assistant​

Create an AI-powered medical diagnosis system with specialized agents for symptom analysis, medical history review, and treatment recommendations.

Key Features:

  • Intelligent triage and urgency assessment
  • Medical history integration
  • Evidence-based diagnosis suggestions
  • Laboratory test recommendations
  • HIPAA-compliant design patterns
  • Emergency escalation protocols

Perfect for: Telemedicine platforms, healthcare clinics, medical triage systems, and patient support applications.


3. Investment Portfolio Management​

Build an intelligent portfolio management system with specialized agents for market analysis, risk assessment, and investment recommendations.

Key Features:

  • Real-time market analysis across asset classes
  • Portfolio risk assessment and optimization
  • Automated trade recommendations
  • Regulatory compliance checking
  • Multi-level trader hierarchy
  • Performance tracking and reporting

Perfect for: Investment firms, robo-advisors, wealth management platforms, and personal finance applications.


4. Personalized Learning Platform​

Develop an AI-powered educational system with specialized agents for curriculum design, student assessment, content recommendation, and adaptive tutoring.

Key Features:

  • Learning style assessment and adaptation
  • Personalized curriculum generation
  • Adaptive content recommendation
  • Interactive tutoring with subject specialists
  • Progress tracking and analytics
  • Parent communication system

Perfect for: E-learning platforms, educational institutions, tutoring services, and corporate training systems.


5. Manufacturing Supply Chain Optimization​

Create an intelligent supply chain management system with specialized agents for production planning, inventory optimization, logistics coordination, and quality control.

Key Features:

  • Production capacity analysis and scheduling
  • Inventory management with reorder automation
  • Quality control and compliance monitoring
  • Logistics and shipping coordination
  • Demand forecasting and planning
  • Supplier relationship management
  • Real-time KPI tracking

Perfect for: Manufacturing companies, factories, supply chain management firms, and industrial IoT platforms.

How to Use These Examples​

Running Locally​

To run examples on your local machine:

# Install AgentRouter
pip install agentrouter

# Navigate to examples directory
cd examples/

# Run any example
python customer_service_example.py
python medical_diagnosis_example.py
python finance_portfolio_example.py
python education_learning_example.py
python manufacturing_supply_chain_example.py

Adapting for Your Use Case​

Each example can be customized:

  1. Modify Agent Roles: Change backstories and goals to fit your domain
  2. Add New Tools: Register additional functions for specific capabilities
  3. Adjust Hierarchy: Add or remove worker levels based on complexity
  4. Configure Parameters: Tune timeouts, retries, and model settings
  5. Integrate APIs: Connect to your existing systems and databases

Common Patterns​

Pattern 1: Hierarchical Delegation​

manager → worker_l1 → worker_l2 → worker_l3
↘ tools ↘ tools ↘ tools

Best for: Complex workflows requiring multiple levels of specialization

Pattern 2: Shared Workers​

manager_1 ↘
shared_worker → tools
manager_2 ↗

Best for: Resource optimization across multiple departments

Pattern 3: Tool Chains​

agent → tool_1 → tool_2 → tool_3 → result

Best for: Sequential processing with data transformation

Pattern 4: Parallel Processing​

manager → worker_1 (async)
→ worker_2 (async)
→ worker_3 (async)
→ aggregate results

Best for: High-throughput scenarios with independent tasks

Pattern 5: Specialist Routing​

triage_agent → specialist_1
→ specialist_2
→ specialist_3

Best for: Domain-specific expertise requirement

Best Practices from Examples​

1. Agent Design​

  • Keep agent roles focused and specific
  • Use clear, detailed backstories that define expertise
  • Provide comprehensive instructions for complex tasks
  • Set appropriate temperature values (0.3-0.5 for precision tasks, 0.6-0.8 for creative tasks)

2. Tool Implementation​

  • Validate all inputs thoroughly
  • Return structured, consistent data formats
  • Handle errors gracefully with fallback options
  • Include metadata (timestamps, IDs, status codes)
  • Implement idempotent operations where possible

3. Workflow Optimization​

  • Minimize unnecessary tool calls through smart routing
  • Use appropriate iteration limits (15-30 based on complexity)
  • Configure timeouts based on task complexity
  • Implement caching for frequently accessed data
  • Use parallel processing for independent tasks

4. Error Handling​

  • Implement retry logic with exponential backoff
  • Provide meaningful fallback responses
  • Log errors with context for debugging
  • Use circuit breakers for external services
  • Implement graceful degradation strategies

5. Production Readiness​

  • Add comprehensive logging and monitoring
  • Implement rate limiting and throttling
  • Use environment variables for configuration
  • Add health checks and readiness probes
  • Implement proper secret management

Prerequisites​

Before running examples, ensure you have:

  • Python 3.8 or higher
  • AgentRouter installed (pip install agentrouter)
  • API key for your LLM provider (OpenAI, Anthropic, etc.)
  • Basic understanding of async Python (for local execution)
  • Sufficient API credits for your chosen provider

Performance Considerations​

Resource Usage​

  • Small Systems (1-5 agents): ~100-500 API calls per complex request
  • Medium Systems (5-15 agents): ~500-2000 API calls per complex request
  • Large Systems (15+ agents): ~2000+ API calls per complex request

Optimization Tips​

  1. Use caching for repeated queries
  2. Implement request batching where possible
  3. Set appropriate max_iterations to prevent runaway loops
  4. Use lower-cost models for simple tasks
  5. Implement circuit breakers for external dependencies

Example Template Structure​

my_example/
├── README.md # Overview and instructions
├── agents.py # Agent definitions
├── tools.py # Tool implementations
├── main.py # Main execution script
└── tests/ # Unit tests
└── test_tools.py

Ready to explore? Choose an example that matches your use case:

Each example includes complete, runnable code that you can deploy immediately or customize for your specific needs!