Failover

Automatic fallback to backup LLM providers

Failover automatically switches to backup providers when the primary fails.

Diagram

Failover

Fails

Fails

🤖 Agent

🟢 Primary

🟡 Backup

🔴 Fallback

Quick Start

  1. 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,
        }
    }
  2. 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

TriggerAction
API timeoutTry next provider
Rate limitTry next provider
Service downTry next provider
All failReturn error

Best Practices

Order by preference

Put best provider first, cheapest backup last.

Include local fallback

Add Ollama as last resort for offline resilience.


Related