When using generate_reply with google gemini live ...
# ask-ai
a
When using generate_reply with google gemini live model I get error:
Copy code
2025-11-13 14:45:20,074 - ERROR livekit.agents - Error in _realtime_reply_task
Traceback (most recent call last):
  File "/Users/malteholledig/Freja/freja-agent-python/venv/lib/python3.13/site-packages/livekit/agents/utils/log.py", line 16, in async_fn_logs
    return await fn(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/malteholledig/Freja/freja-agent-python/venv/lib/python3.13/site-packages/livekit/agents/voice/agent_activity.py", line 1942, in _realtime_reply_task
    generation_ev = await self._rt_session.generate_reply(
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        instructions=instructions or NOT_GIVEN
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
Assume its a bug as instructions should be able to be undefined?
t
Thanks for reaching out, Malte. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
I'm sorry to hear you're encountering an error in
_realtime_reply_task
when using
generate_reply
with the Google Gemini live model. This can happen for a few reasons, like session state issues, timeouts, or configuration mismatches. Let’s walk through some steps together to help resolve this: 1. First, please make sure your session is properly initialized and active before you call
generate_reply
. Here’s an example you might find helpful:
Copy code
session = AgentSession(
    llm=google.realtime.RealtimeModel(
        model="gemini-2.0-flash-live-001",
        voice="Puck",
        temperature=0.8,
    )
)
await session.start(room=ctx.room, agent=agent)
await session.generate_reply()
1. Double-check that your model configuration parameters like
voice
,
temperature
, and
modalities
are set correctly. 2. Look out for any session management hiccups, such as multiple concurrent
generate_reply
calls or the session being closed unexpectedly. 3. Keep an eye on your connection status and retry logic to ensure your network is properly connected to Google’s API endpoints. 4. If you’re still running into timeouts, it might help to increase the timeout duration or add some retry logic. If you try these steps and the problem continues, please don’t hesitate to reach out. I’m here to help you troubleshoot further or escalate the issue if needed. Your experience matters, and we’ll work through this together! Sources: livekit-plugins/livekit-plugins-google/livekit/plugins/google/realtime/real... | agents/src/voice/agent_activity.ts | Gemini Live API plugin | LiveKit docs | realtime/gemini_live_vision.py
a
I am using it in on_enter fn so session should be good.
t
It’s great that you’re using
generate_reply
within the
on_enter
function, which means the session should be initialized properly. Sometimes, though, timing or configuration hiccups can sneak in and cause errors. Let’s walk through some steps together to help you check and fix this: 1. First, make sure that
session.start()
has fully completed before you call
generate_reply
. Here’s a quick example:
Copy code
await session.start(
    room=ctx.room,
    agent=Assistant()
)
await session.generate_reply()
1. Next, it’s helpful to confirm that the session is correctly initialized inside
on_enter
. You can do this by checking the session state like so:
Copy code
if not hasattr(self.session, '_session') or self.session._session is None:
    logger.error("Session not properly initialized")
    return
1. Also, double-check that your model configuration matches the supported Gemini Live models—like `gemini-2.0-flash-live-001`—and that your authentication credentials are set up correctly. 2. If you’re still facing timeouts, try increasing the timeout duration or adding retry logic in your connection options:
Copy code
conn_options=APIConnectOptions(
    timeout=30.0,  # Increase timeout if needed
    retry_count=3
)
If after these steps the issue is still hanging around, please don’t hesitate to reach out. I’m here to help you troubleshoot further or escalate the matter so we can get it resolved together. Sources: realtime/gemini_realtime_api.py | livekit-plugins/livekit-plugins-google/README.md | plugins/google/src/beta/realtime/realtime_api.ts | Gemini Live API plugin | LiveKit docs | main.py
a
2025-11-13 152138,273 - WARNING livekit.plugins.google - received server content but no active generation. {"pid": 50575, "job_id": "AJ_HEkfFfN8GhhJ"} 2025-11-13 152138,273 - WARNING livekit.plugins.google - received server content but no active generation. {"pid": 50575, "job_id": "AJ_HEkfFfN8GhhJ"} 2025-11-13 152138,273 - WARNING livekit.plugins.google - no active generation to report metrics for {"pid": 50575, "job_id": "AJ_HEkfFfN8GhhJ"} 2025-11-13 152142,709 - ERROR livekit.agents - Error in _realtime_reply_task Traceback (most recent call last): File "/Users/malteholledig/Freja/freja-agent-python/venv/lib/python3.13/site-packages/livekit/agents/utils/log.py", line 16, in async_fn_logs return await fn(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/malteholledig/Freja/freja-agent-python/venv/lib/python3.13/site-packages/livekit/agents/voice/agent_activity.py", line 1942, in _realtime_reply_task generation_ev = await self._rt_session.generate_reply( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ instructions=instructions or NOT_GIVEN ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ) ^ livekit.agents.llm.realtime.RealtimeError: generate_reply timed out waiting for generation_created event. {"pid": 50575, "job_id": "AJ_HEkfFfN8GhhJ"} Also getting the warnings now see above
t
Thank you for reaching out! The warnings "received server content but no active generation" and "no active generation to report metrics for" usually happen when the system gets server responses (like text or audio data) but there isn’t an active generation session to handle them. This often comes down to timing quirks or session state mismatches. Let’s walk through some steps that can help resolve this: 1. Make sure
generate_reply()
is called before or during the audio input so a generation session starts properly. 2. Check your turn detection setup: • If you’re using server-side turn detection (which is the default), please confirm that
automatic_activity_detection
is enabled in your
realtime_input_config
. • If you’re handling manual activity detection, remember to call
start_user_activity()
before sending audio, and ensure
activity_end
is either sent or automatically detected afterward. 1. Try to avoid calling
interrupt()
or resetting the session while waiting for server responses, as this can cause issues. 2. Double-check that your
RealtimeSession
is active and not caught in a retry or restart loop due to connection problems. If you continue to see this issue after trying these steps, please don’t hesitate to let me know. I’m here to help and can assist further or escalate this for a deeper look. We want to make sure everything runs smoothly for you! Sources: livekit-plugins/livekit-plugins-google/livekit/plugins/google/llm.py | Real-time AI Models & Streaming | livekit/livekit_composite | DeepWiki