ModelRouter and RouterAgent add dynamic switching, cost optimisation, and resilience.
How It Works
Model string format
Use either a recognised prefix (gpt-, claude-, gemini-) or explicit provider/model form:
See Fail-Loud Defaults for migration guidance.
Quick Start
1
Simple Usage
2
With Configuration
Overview
The advanced multi-provider system enables:- Dynamic model selection based on task requirements
- Automatic fallback when providers fail
- Cost-optimised routing for different task complexities
- Performance-based routing for critical operations
- Load balancing across providers
- Circuit breaker patterns for provider health
Routing Strategies
Automatic Routing (“auto”)
Analyses task complexity and requirements to select the best model:Cost-Optimized Routing
Prioritises cheaper models while ensuring task completion:Performance-Optimized Routing
Prioritises capability and reliability for critical tasks:Advanced Patterns
Fallback Mechanism
Task-Based Routing
Provider Health Monitoring
Load Balancing
Circuit Breaker Pattern
Integration with AutoAgents
Best Practices
Configure accurate model profiles
Configure accurate model profiles
Pass
model_profiles with cost, strengths, and context window so routing decisions reflect real capabilities.Monitor and cap costs
Monitor and cap costs
Use
get_usage_summary() and set cost_threshold or daily budgets before production traffic.Always set a fallback model
Always set a fallback model
Provide
fallback_model so a single provider outage does not halt the agent.Use explicit provider/model strings
Use explicit provider/model strings
Prefer
ollama/llama3 over ambiguous bare model names to avoid provider inference errors.Related
Memory Management
Stateful multi-provider agents with persistent memory.
Fail-Loud Defaults
Provider inference rules and migration guidance.

