hundreds-lamp-38428
11/01/2025, 7:57 AMfrom livekit.agents.llm import FallbackAdapter can you take me to a valid exampletall-airline-16756
11/01/2025, 7:58 AMtall-airline-16756
11/01/2025, 7:58 AMFallbackAdapter, which is a useful part of the LiveKit Agents framework. Here’s a friendly example to help you see how it works:
from livekit.agents.llm import FallbackAdapter
from livekit.plugins import openai, anthropic
# Initialize primary and backup LLMs
primary_llm = openai.LLM(model="gpt-4o")
backup_llm = anthropic.LLM(model="claude-3-opus-20240307")
# Create the FallbackAdapter with automatic failover
fallback_llm = FallbackAdapter(
llm=[primary_llm, backup_llm], # Ordered list: primary first, then fallbacks
attempt_timeout=10.0, # Timeout per request attempt
max_retry_per_llm=1, # Retry once per LLM before failing over
retry_interval=0.5, # Delay between retry attempts
retry_on_chunk_sent=False, # Do not retry if partial response was already sent
)
# Use the fallback-enabled LLM in a chat context
stream = fallback_llm.chat(chat_ctx=my_chat_context, tools=my_tools)
This configuration helps by automatically switching between LLMs if needed, monitoring their health, and recovering smoothly. If you have any questions or want to explore this further, just let me know—I’m here to help!
Sources: livekit-agents/livekit/agents/tts/__init__.py | Events and error handling | LiveKit docs