#7481·agents

google realtime: hardcoded 5s generate_reply timeout fires on realistic prompts, raising RealtimeError for turns that succeed

Author: RastavoCreated Sep 26, 2026Updated Sep 28, 2026

Summary

generate_reply() on the Google realtime plugin uses a hardcoded 5.0 s timeout while waiting for the generation_created event. With a realistic system prompt, Gemini's time-to-first-audio is regularly longer than 5 s, so the timeout fires on nearly every turn and raises:

RealtimeError: generate_reply timed out waiting for generation_created event.

...even though the model's audio arrives moments later and plays normally. The handle reports failure for turns that actually succeeded.

Environment

  • livekit-agents 1.8.2
  • livekit-plugins-google 1.8.2
  • google-genai 2.18.1
  • Python 3.13.12, macOS (arm64)
  • model gemini-3.1-flash-live-preview, voice Enceladus, language="en-GB", thinking_level=MINIMAL
  • checked against livekit-plugins-google 1.8.3 — same behaviour

Relevant code

In livekit-plugins-google/livekit/plugins/google/realtime/realtime_api.py, the generate_reply path:

python
self._send_client_event(types.LiveClientContent(turns=turns, turn_complete=True))

def _on_timeout() -> None:
    if not fut.done():
        fut.set_exception(
            llm.RealtimeError(
                "generate_reply timed out waiting for generation_created event."
            )
        )
        ...

timeout_handle = asyncio.get_event_loop().call_later(5.0, _on_timeout)

5.0 is a fixed constant. It does not account for prompt size or model time-to-first-token, both of which vary a lot in practice.

Reproduction

One AgentSession, five sequential text turns, measuring wall-clock time from generate_reply() to the conversation_item_added event for the assistant message. Two variants of instructions, everything else identical, run in both orders to rule out warm-up effects.

instructions size replies median min max per-turn (s)
full persona prompt 14,630 chars (~3.7k tok) 5/5 8.89 s 7.14 10.74 8.9, 7.1, 10.6, 10.7, 8.7
one-line prompt 55 chars 5/5 2.43 s 1.76 3.18 3.2, 2.3, 3.0, 2.4, 1.8

Reproduced twice, with the variants in opposite order.

Note that all turns eventually produced a correct reply in both variants. The model is not dropping anything — it is just slower than the fixed 5 s budget, so:

  • the generate_reply handle resolves with RealtimeError for turns that in fact succeeded;
  • ~8.9 s median time-to-first-audio is a poor voice experience regardless;
  • anything gated on that handle (evals, tests, follow-up logic) fails intermittently, which is easy to misdiagnose as dropped or corrupted output.

Requested change

Either:

  1. make the generation_created timeout configurable per-model / per-session, or
  2. derive it from observed latency rather than hardcoding 5.0, or
  3. treat the timeout as "generation not yet started" and keep waiting / surface a retryable signal rather than a hard RealtimeError.

Option 1 is the least surprising for callers. The 5 s constant is short enough to fire on any prompt beyond a few hundred tokens with a preview model.