WARNING livekit.plugins.google - no candidates in ...
# ask-ai
f
WARNING livekit.plugins.google - no candidates in the response can I catch this LLM warning in the agent session code and fallback to backup LLM for retry?
t
Thanks for reaching out, Taras. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
I understand that encountering the warning "no candidates in the response" can be a bit confusing, but don’t worry! You can gracefully handle this in your agent session code by using the
FallbackAdapter
. This handy adapter lets you set up multiple LLMs and will automatically switch to a backup LLM if the primary one doesn’t return a valid response. It’s like having a safety net to keep things running smoothly. Here’s a quick overview of how it works: • The warning appears when no candidates come back from the LLM, but it doesn’t throw an exception. The
FallbackAdapter
sees this as a signal to try the next LLM in your list. • You have control over its behavior with parameters like
attempt_timeout
,
max_retry_per_llm
, and
retry_on_chunk_sent
. • If all LLMs happen to fail, an
APIConnectionError
will be raised, which you can catch and handle using the
ErrorEvent
in the
AgentSession
. To make it clearer, here’s an example configuration you can use:
Copy code
from livekit.agents import llm
from livekit.plugins import openai, google

session = AgentSession(
    llm=llm.FallbackAdapter(
        [
            google.LLM(model="gemini-1.5-pro"),
            openai.LLM(model="gpt-4o"),
        ],
        attempt_timeout=10.0,
        max_retry_per_llm=0,
        retry_on_chunk_sent=True,
    ),
)
This setup helps ensure that if your primary LLM doesn’t respond as expected, the system will seamlessly try the backup LLM, keeping things running without a hitch. If you have any questions or want to explore this further, feel free to ask—I’m here to help! Sources: livekit-agents/livekit/agents/inference/llm.py | LLM Integrations | livekit/livekit_composite | DeepWiki | Events and error handling | LiveKit Docs
f
It doesn't throw error, only warning, so no fallback is happening
t
I'd love to help you get to the bottom of this! Could you share a bit more about how the warning is being logged in your setup? For instance, are you using a particular logging method or maybe some custom logic that might be skipping the fallback mechanism? Also, are you including the
FallbackAdapter
in your configuration? Understanding these details will really help us find the best solution together.