feat: Implemented FallbackAdapter for LLM #916
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
#868
This PR implements the
FallbackAdapterfor LLMs, bringing feature parity with the Python SDK. This component allows agents to automatically switch to backup LLM providers if the primary provider fails, times out, or becomes unavailable, ensuring high availability for production agents.Python(agents) SDK code for fallback adapter: https://github.com/livekit/agents/blob/main/livekit-agents/livekit/agents/llm/fallback_adapter.py
Changes Made
packages/agents/src/llm/FallbackAdapter.tsimplementing theFallbackAdapterandFallbackLLMStreamclasses.ChatContextto verify when a failed provider has recovered (instead of a simple timer).llm_availability_changedevents when providers go down or recover.retryOnChunkSentto prevent the agent from repeating partial sentences if a stream fails mid-generation.packages/agents/src/llm/index.ts.Pre-Review Checklist
Testing
restaurant_agent.tsandrealtime_agent.tswork properly (This change is additive/opt-in and does not affect existing agents unless configured to use the adapter)