Failover
Automatic fallback to backup LLM providers
Failover automatically switches to backup providers when the primary fails.
Quick Start
- Create Failover-Ready Agent
rust use praisonai::Agent; // Primary agent with fast model let primary = Agent::new() .name("Primary Assistant") .model("gpt-4o") .build()?; // Backup agent with different provider let backup = Agent::new() .name("Backup Assistant") .model("claude-3-sonnet") .build()?; // Implement failover at application level async fn chat_with_failover(query: &str) -> Result<String> { match primary.chat(query).await { Ok(response) => Ok(response), Err(_) => backup.chat(query).await, } } - Local Fallback
rust use praisonai::Agent; // Cloud-first, local fallback let cloud = Agent::new() .name("Cloud Assistant") .model("gpt-4o") .build()?; let local = Agent::new() .name("Local Assistant") .model("ollama/llama3") .base_url("http://localhost:11434") .build()?; // Try cloud, fall back to local if unavailable
When Failover Triggers
| Trigger | Action |
|---|---|
| API timeout | Try next provider |
| Rate limit | Try next provider |
| Service down | Try next provider |
| All fail | Return error |
Best Practices
Order by preference
Put best provider first, cheapest backup last.
Include local fallback
Add Ollama as last resort for offline resilience.