-
Notifications
You must be signed in to change notification settings - Fork 209
feat: Implemented FallbackAdapter for LLM #916
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
🦋 Changeset detectedLatest commit: fb99648 The changes in this PR will be included in the next version bump. This PR includes changesets to release 15 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
toubatbrian
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you tested fallback yet? Could you add a simple example ts file under examples showcasing the basic usage of this class. Thanks!
|
I won’t be able to do this today. I’ll test the fallback and add a simple example TS file under examples tomorrow. |
|
Thanks @KrishnaShuk! |
|
I need to test this further. I’ll provide an update shortly. |
|
@toubatbrian I have made changes in the fallback_adapter.ts file. Some behaviors were not in accordance with the Python implementation. Now the fallback adapter is in complete parity with the agents (Python) adapter. After searching in the agents repo, I didn't find any tests for the LLM adapter, whereas tests for STT and TTS adapters were present. I have made a test file fallback_adapter.test.ts for it, covering the following behaviors as per the Python implementation:
|
|
I changed .then() to .finally() in llm.ts to ensure the stream queue is properly closed even when the mainTask fails (eg. due to connection errors or timeouts). Using .finally() guarantees that queue.close() is called regardless of whether the task succeeds or fails, ensuring proper stream termination and error propagation. @yura2100 also raised this concern in this issue. Reference commit: fb99648 |
|
All the test cases are passing and i have also tested it with an example agent. |
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)