Quick Start
1
Install Package
First, install the PraisonAI Agents package:
2
Set API Keys
Set your API keys as environment variables:
3
Create a file
Create a new file
model_router_example.py
:4
Run the Example
Execute your model router example:
Requirements
- Python 3.10 or higher
- API keys for the models you want to use
- Basic understanding of different LLM capabilities
Understanding Model Router
What is Model Router?
The Model Router:
- Automatically selects the best LLM for each task
- Considers task complexity, context length, and requirements
- Optimizes for performance and cost
- Supports fallback options if primary model fails
- Provides detailed routing history and analytics
Features
Intelligent Selection
Analyzes task requirements to choose the optimal model.
Cost Optimization
Balances performance needs with cost considerations.
Capability Matching
Matches task requirements with model capabilities.
Fallback Support
Automatically switches to backup models if needed.
Configuration Options
Advanced Usage
Custom Routing Logic
Routing Analytics
Model Selection Criteria
The router considers multiple factors when selecting models:Task Complexity
- Simple calculations → Cost-effective models
- Complex reasoning → Advanced models
- Creative tasks → Specialized creative models
Context Length
- Short context → Standard models
- Medium context → Enhanced context models
- Long context → Specialized long-context models
Response Time
- Real-time needs → Fast models
- Batch processing → Optimized for throughput
- Quality priority → Best performing models
Cost Constraints
- Budget limits → Cost-effective options
- Quality/cost balance → Optimal value models
- Premium requirements → Top-tier models
Best Practices
Define Clear Requirements
Define Clear Requirements
Provide specific task requirements to help the router make better decisions:
Monitor Performance
Monitor Performance
Regularly review routing decisions and performance:
Set Cost Limits
Set Cost Limits
Configure budget constraints to control costs:
Troubleshooting
Routing Issues
If wrong models are selected:
- Review task requirements
- Check routing rules configuration
- Enable verbose logging
- Verify model availability
Performance Problems
If performance is suboptimal:
- Analyze routing history
- Adjust selection criteria
- Update model capabilities
- Consider custom routing logic
Next Steps
Model Capabilities
Deep dive into model-specific capabilities and features
Router Agent
Learn about the RouterAgent for dynamic task routing
The Model Router System continuously learns from usage patterns to improve selection accuracy over time. Regular monitoring and adjustment of routing rules ensures optimal performance.