When using `tts.FallbackAdapter` with multiple TTS...
# agents
p
When using
tts.FallbackAdapter
with multiple TTS providers (e.g., ElevenLabs and Cartesia), does the availability state (which TTS instances are marked as unavailable) persist across different call sessions? Given that the typical entrypoint pattern creates a new
AgentSession
(and thus a new
FallbackAdapter
) for each incoming call, is there a way to share the availability state across calls so that if ElevenLabs failed in Call 1, Call 2 immediately uses Cartesia without first attempting ElevenLabs again. Edit - I meant in the same worker, the next call should be aware of the unavailability of TTS and NOT across all workers.
b
Hmm given that you can have workers in different instances I don't think you can reliably do this without setting your own external store (e.g., redis). So I'd doubt they have an implementation for this. Though it would still be possible to do a monkey patch to do it.
p
Thanks for catching the workers part. I missed it. I meant in the same worker for now. If a call is handled in the same worker - the worker should be aware to not send the requests to unavailable TTS.
l
Yes, for the same worker the behaviour should be: • mark the failed provider as unhealthy and stop sending requests to it • continue to use the backup providers until the primary provider recovers • periodically checks the primary provider’s status in the background
p
@lively-winter-88668 - do you want to me create a feature request on agents github repo?
l
I'm saying the documented behaviour of the fallback adapter matches what you were asking, across different call sessions (for the same worker)
p
From the code it doesn't seem that way - https://github.com/livekit/agents/blob/main/livekit-agents/livekit/agents/tts/fallback_adapter.py#L103C1-L106C1
_TTSStatus
is maintained in memory and is initialized each time for new
FallbackAdapter
initialization.
l
Interesting. I'll admit this is beyond me. AI is suggesting a module-level declaration, which sounds sensible, but I haven't tried it myself:
Copy code
from livekit.agents import tts  
from livekit.plugins import openai, deepgram  
  
# Module-level declaration - shared across all jobs  
SHARED_TTS_ADAPTER = tts.FallbackAdapter(  
    [  
        openai.TTS(voice="ash"),  
        deepgram.TTS(),  
    ]  
)  
  
async def entrypoint(ctx: JobContext):  
    # Use the shared adapter instance  
    session = AgentSession(  
        tts=SHARED_TTS_ADAPTER,  
        # ... other parameters  
    )  
    # ... rest of your code
👍 1
p
The TTS configs are obtained at runtime for us after entrypoint. But thanks, will check this more. I just wanted to confirm as that is what I see in code