Failover

Automatic backup when things fail

Agents can failover to backup models when the primary fails.

Diagram

Automatic Failover

Fails

📤 Request

🤖 Primary

🤖 Backup

✅ Success

Quick Start

  1. Simple Usage
    typescript
    import { Agent } from 'praisonai';
    
    const agent = new Agent({
      llm: 'gpt-4o',
      fallback: ['gpt-4-turbo', 'gpt-3.5-turbo']
    });
    
    await agent.chat('Hello');
    // Uses gpt-4o, falls back if unavailable
  2. With Configuration
    typescript
    const agent = new Agent({
      llm: 'gpt-4o',
      fallback: [
        'anthropic/claude-3',
        'google/gemini-pro'
      ]
    });

User Interaction Flow

Diagram
BackupGPT-4oAgentUserBackupGPT-4oAgentUserRequestTry primaryFailTry backupSuccessResponse

Configuration Levels

typescript
// Level 1: Array - Simple fallback list
const agent = new Agent({
  llm: 'gpt-4o',
  fallback: ['gpt-4-turbo', 'gpt-3.5-turbo']
});

// Level 2: Dict - With options
const agent = new Agent({
  llm: 'gpt-4o',
  fallback: {
    models: ['gpt-4-turbo', 'gpt-3.5-turbo'],
    retries: 2
  }
});

// Level 3: Instance - Full control
const agent = new Agent({
  failover: {
    primary: 'gpt-4o',
    fallbacks: ['gpt-4-turbo', 'claude-3'],
    strategy: 'round-robin',  // or 'priority'
    healthCheck: true
  }
});

Failover Options

OptionDescription
fallbackBackup models list
retriesAttempts per model
strategyHow to select backup
healthCheckSkip known-down models

API Reference

FailoverConfig

Complete configuration options

FailoverManager

Manager class documentation


Best Practices

Include cheaper fallbacks

Use lower-cost models as last resort.

Mix providers

Different providers have different outages.

Test fallback paths

Verify backups work before production.


Related