Gemini realtime: generate_reply is refused on models without a mutable chat context
Bug Description
RealtimeSession.generate_reply() in livekit-plugins-google refuses outright whenever the
model does not advertise mutable_chat_context:
if not self._realtime_model.capabilities.mutable_chat_context:
logger.warning(
f"generate_reply is not compatible with '{self._opts.model}' and will be ignored."
)
fut = asyncio.Future[llm.GenerationCreatedEvent]()
fut.set_exception(
llm.RealtimeError(f"generate_reply is not compatible with '{self._opts.model}'")
)
return fut
mutable_chat_context is computed as "3.1" not in model, so every Gemini 3.1 Live model
lands here. That leaves those models with no way to open an agent-initiated turn at all —
greetings, replies after a handoff, and prompts issued after a tool result all go through
generate_reply(), and each of them raises instead.
The two properties are not the same thing. mutable_chat_context describes whether the
client may append to the conversation mid-session, and the plugin already acts on exactly
that when it connects:
history_config=types.HistoryConfig(initial_history_in_client_content=True)
if not self._realtime_model.capabilities.mutable_chat_context
else None,
A session configured that way keeps its own history and rejects the placeholder user turn
generate_reply() sends to trigger a generation. That is a reason to send a different
trigger, not a reason to refuse: the same session does accept realtime text input, which
starts a generation without touching the context.
Nothing in agent_activity gates generate_reply() on mutable_chat_context — its uses
there are agent handoff reuse, chat context reset, and the interrupted-tool commit — so the
refusal is specific to this plugin.
Expected Behavior
generate_reply() starts a generation on Gemini Live models that do not support a mutable
chat context, using a trigger those models accept, instead of raising RealtimeError.
Reproduction Steps
1. Create an AgentSession with a Gemini 3.1 Live realtime model:
from livekit.plugins import google
model = google.beta.realtime.RealtimeModel(model="gemini-3.1-flash-live-preview")
2. Have the agent open the conversation, e.g. in the entrypoint:
await session.generate_reply(instructions="Greet the caller.")
3. Observe the warning
"generate_reply is not compatible with 'gemini-3.1-flash-live-preview' and will be ignored."
and the returned future raising
RealtimeError: generate_reply is not compatible with 'gemini-3.1-flash-live-preview'
The agent never speaks first. The same happens after an agent handoff and after a tool
result, wherever generate_reply() is used.
Operating System
macOS
Models Used
gemini-3.1-flash-live-preview (RealtimeModel); any Gemini Live model whose id contains
"3.1" takes the same path
Package Versions
livekit-agents==1.8.0
livekit-plugins-google==1.8.0
google-genai==2.20.0
Session/Room/Call IDs
No response
Proposed Solution
# drop the refusal, and pick the trigger the session accepts
if self._realtime_model.capabilities.mutable_chat_context:
# Gemini requires the last message to end with user's turn
# so we need to add a placeholder user turn in order to trigger a new generation
turns = []
if is_given(instructions):
turns.append(types.Content(parts=[types.Part(text=instructions)], role="model"))
turns.append(types.Content(parts=[types.Part(text=".")], role="user"))
self._send_client_event(types.LiveClientContent(turns=turns, turn_complete=True))
else:
# the session keeps its own history (see history_config in _build_connect_config)
# and rejects client turns, so the placeholder above is not accepted. realtime
# text input starts a generation without appending to the context.
self._send_client_event(
types.LiveClientRealtimeInput(text=instructions if is_given(instructions) else ".")
)
instructions is frequently NOT_GIVEN (agent_activity passes instructions or NOT_GIVEN),
so the realtime-input path falls back to the same "." nudge the other path already uses.
Additional Context
The refusal was added in #5286 as a warning for gemini-3.1-flash-live-preview and later
became an exception keyed on the capability. _send_task already routes
LiveClientRealtimeInput.text to session.send_realtime_input(text=...), so no change is
needed on the send path.
hi @Darshak03, thanks for creating this issue! gemini-3.1 live models now support generate_reply, please feel free to try it out and let us know any feedback you may have 🎉