---
title: "FallbackAgent | Micdrop"
description: "The FallbackAgent class provides automatic failover between multiple LLM agents for improved reliability."
url: "https://micdrop.dev/docs/ai-integration/fallback-strategies/agent-fallback"
---

*   [Getting Started](/docs/getting-started)
*   [Client (Browser)](/docs/client)
    
    *   [Installation](/docs/client/installation)
    *   [React Hooks](/docs/client/react-hooks)
    *   [Start/Stop Call](/docs/client/start-stop-call)
    *   [Pause/Resume Call](/docs/client/pause-resume-call)
    *   [Mute/Unmute Call](/docs/client/mute-unmute-call)
    *   [Call State](/docs/client/call-state)
    *   [Display Conversation Messages](/docs/client/display-conversation-messages)
    *   [Handling Tool Calls](/docs/client/handling-tool-calls)
    *   [Device Management](/docs/client/devices-management)
    *   [Voice Activity Detection (VAD)](/docs/client/vad)
    *   [Turn Detection](/docs/client/turn-detection)
    *   [Reducing Latency](/docs/client/latency)
    *   [Error Handling](/docs/client/error-handling)
    *   Utility Classes
        
        *   [Mic](/docs/client/utility-classes/mic)
        *   [MicdropClient](/docs/client/utility-classes/micdrop-client)
        *   [MicRecorder](/docs/client/utility-classes/mic-recorder)
        *   [Speaker](/docs/client/utility-classes/speaker)
        
    
*   [Client (React Native)](/docs/react-native)
    
    *   [Installation](/docs/react-native/installation)
    *   [Hooks and Call State](/docs/react-native/hooks)
    *   [Audio Output and Devices](/docs/react-native/audio-output)
    *   [Voice Activity Detection (VAD)](/docs/react-native/vad)
    *   [Turn Detection](/docs/react-native/turn-detection)
    *   [Using Another Audio Library](/docs/react-native/custom-audio)
    
*   [Server (Node.js)](/docs/server)
    
    *   [Installation](/docs/server/installation)
    *   [With Fastify](/docs/server/with-fastify)
    *   [With NestJS](/docs/server/with-nestjs)
    *   [Auth and Parameters](/docs/server/auth-and-parameters)
    *   [First Message](/docs/server/first-message)
    *   [Dictation and Text-Only Calls](/docs/server/dictation)
    *   [Partial Messages](/docs/server/partial-messages)
    *   [Save Messages](/docs/server/save-messages)
    *   [Resume a Conversation](/docs/server/resume-conversation)
    *   [Recording Audio](/docs/server/recording-audio)
    *   [Error Handling](/docs/server/error-handling)
    *   [Tools](/docs/server/tools)
    *   [Extract Value from Answer](/docs/server/extract)
    *   [Auto End Call](/docs/server/auto-end-call)
    *   [Semantic Turn Detection](/docs/server/semantic-turn-detection)
    *   [Noise Filtering](/docs/server/noise-filtering)
    *   [Micdrop Protocol](/docs/server/protocol)
    
*   [AI Integrations](/docs/ai-integration)
    
    *   Provided Integrations
        
        *   [AI SDK](/docs/ai-integration/provided-integrations/ai-sdk)
        *   [Cartesia](/docs/ai-integration/provided-integrations/cartesia)
        *   [ElevenLabs](/docs/ai-integration/provided-integrations/elevenlabs)
        *   [Gladia](/docs/ai-integration/provided-integrations/gladia)
        *   [Gradium](/docs/ai-integration/provided-integrations/gradium)
        *   [Kokoro](/docs/ai-integration/provided-integrations/kokoro)
        *   [Mistral](/docs/ai-integration/provided-integrations/mistral)
        *   [OpenAI](/docs/ai-integration/provided-integrations/openai)
        *   [Piper](/docs/ai-integration/provided-integrations/piper)
        *   [Pocket TTS](/docs/ai-integration/provided-integrations/pocket-tts)
        *   [Qwen3-TTS](/docs/ai-integration/provided-integrations/qwen-tts)
        *   [Whisper](/docs/ai-integration/provided-integrations/whisper)
        
    *   Custom Integrations
        
        *   [Agent (LLM)](/docs/ai-integration/custom-integrations/custom-agent)
        *   [Speech-to-Text (STT)](/docs/ai-integration/custom-integrations/custom-stt)
        *   [Text-to-Speech (TTS)](/docs/ai-integration/custom-integrations/custom-tts)
        
    *   Fallback Strategies
        
        *   [FallbackAgent](/docs/ai-integration/fallback-strategies/agent-fallback)
        *   [FallbackSTT](/docs/ai-integration/fallback-strategies/stt-fallback)
        *   [FallbackTTS](/docs/ai-integration/fallback-strategies/tts-fallback)
        
    *   [Local Models](/docs/ai-integration/local-models)
        
        *   [Local LLM](/docs/ai-integration/local-models/agent)
        *   [Local STT](/docs/ai-integration/local-models/speech-to-text)
        *   [Local TTS](/docs/ai-integration/local-models/text-to-speech)
        *   [Latency and Memory](/docs/ai-integration/local-models/performance)
        *   [Explorations](/docs/ai-integration/local-models/explorations)
            
            *   [MiniCPM5-2B](/docs/ai-integration/local-models/explorations/minicpm)
            *   [Mistral 7B](/docs/ai-integration/local-models/explorations/mistral-7b)
            *   [Voxtral Mini 3B](/docs/ai-integration/local-models/explorations/voxtral-stt)
            *   [Voxtral TTS 4B](/docs/ai-integration/local-models/explorations/voxtral-tts)
            *   [AuK and AuK-Flash](/docs/ai-integration/local-models/explorations/auk)
            
        
    *   [IA Vocale Souveraine 🇫🇷🇪🇺](/docs/ai-integration/sovereign-voice-ai)
    
*   [Migration](/docs/migration)
    
    *   [Upgrade to v3](/docs/migration/v3)
    

[Micdrop](/) › [Documentation](/docs/getting-started) › [AI Integrations](/docs/ai-integration) › Fallback Strategies

# FallbackAgent

The `FallbackAgent` class provides automatic failover between multiple LLM agents for improved reliability. When one agent fails to produce an answer after exhausting its retries, it automatically switches to the next agent in the list and lets it answer from the same conversation.

## Features

*   **Automatic failover**: Seamlessly switches between agents when failures occur
*   **Shared conversation**: The conversation history is shared between agents, so the next agent answers from the exact same context
*   **Circular rotation**: Cycles through agents until one answers (one full rotation per answer)
*   **Per-agent configuration**: Each agent keeps its own system prompt, tools and options
*   **Event forwarding**: Forwards `Message`, `ToolCall`, `EndCall`, `SkipAnswer` and `CancelLastUserMessage` events from the active agent
*   **Cancellation support**: Properly forwards `cancel()` calls to the active agent

## Usage

```
import { FallbackAgent } from '@micdrop/server'import { OpenaiAgent } from '@micdrop/openai'import { MistralAgent } from '@micdrop/mistral'
const systemPrompt = 'You are a helpful assistant'
// Create a fallback agent with multiple providersconst agent = new FallbackAgent({  factories: [    // Primary provider: OpenAI with a low retry count    () =>      new OpenaiAgent({        apiKey: process.env.OPENAI_API_KEY || '',        systemPrompt,        maxRetry: 2, // Fail faster to switch to backup      }),    // Backup provider: Mistral    () =>      new MistralAgent({        apiKey: process.env.MISTRAL_API_KEY || '',        systemPrompt,        maxRetry: 3,      }),  ],})
// Use with MicdropServerconst server = new MicdropServer(socket, {  agent,  // ... other options})
```

## Options

Option

Type

Description

`factories`

`Array<() => Agent>`

Array of factory functions that create `Agent` instances

## Configuration

Unlike a regular agent, `FallbackAgent` does not take a `systemPrompt` or tool options directly. Each child agent is fully configured inside its own factory function. This lets you tailor options (system prompt, tools, `autoEndCall`, `extract`, `onBeforeAnswer`, etc.) per provider.

To make providers behave consistently, give them the same `systemPrompt` and tools. You can also use slightly different prompts per provider if a given model needs specific instructions.

## How It Works

1.  **Initialization**: Starts with the first agent in the list and adopts its conversation
2.  **Normal operation**: Forwards the answer of the current agent and re-emits its events
3.  **On failure**: When an agent emits the `Failed` event (after exhausting its retries):
    *   Switches to the next agent (wraps around to the first if at the end)
    *   Swaps in the new agent’s system prompt while keeping the accumulated history
    *   Lets the new agent answer from the shared conversation
    *   Destroys the failed agent
4.  **Giving up**: If every agent fails within a single answer (one full rotation), the answer is skipped
5.  **Logging**: Inherits logger configuration and applies it to child agents

ℹ️ Note

The fallback is triggered by the `Failed` event, which an agent emits once it has exhausted its own retries. Text already streamed before a failure may have been sent downstream, so failover is most seamless when an agent fails before producing any output (for example on a connection error).

[Previous← Text-to-Speech (TTS)](/docs/ai-integration/custom-integrations/custom-tts)[NextFallbackSTT →](/docs/ai-integration/fallback-strategies/stt-fallback)

On this page

*   [Features](#features)
*   [Usage](#usage)
*   [Options](#options)
*   [Configuration](#configuration)
*   [How It Works](#how-it-works)
