Skip to main content
While basic multi-provider support lets you assign different LLMs to different agents, ModelRouter and RouterAgent add dynamic switching, cost optimisation, and resilience.
The user submits a task; the router picks a provider based on policy, cost, and availability.

How It Works

PR #2122: A model string like my-custom-model no longer defaults to the OpenAI provider — it raises ValueError. Use the provider/model form, e.g. ollama/llama3, bedrock/anthropic.claude-3-sonnet.Non-built-in prefixes (bedrock/, deepseek/, any custom name) work when either LiteLLM natively supports them or you have registered a provider for them via register_llm_provider(...). The wrapper resolves registered providers before falling through to the LiteLLM ladder (PR #3011).

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

Pass model_profiles with cost, strengths, and context window so routing decisions reflect real capabilities.
Use get_usage_summary() and set cost_threshold or daily budgets before production traffic.
Provide fallback_model so a single provider outage does not halt the agent.
Prefer ollama/llama3 over ambiguous bare model names to avoid provider inference errors.

Memory Management

Stateful multi-provider agents with persistent memory.

Fail-Loud Defaults

Provider inference rules and migration guidance.