fix(gemini realtime): preserve original setup config on follow-up session.update

Gemini Live treats a second BidiGenerateContentSetup as a full session
replacement, not a partial merge. The guardrail-driven turn_detection-only
session.update was emitting a setup containing only model + realtimeInputConfig,
which would silently drop tools, generationConfig, inputAudioTranscription, and
systemInstruction from the original setup. Carry forward the cached original
setup and only override realtimeInputConfig.

Co-authored-by: Yassin Kortam <yassin@berri.ai>
This commit is contained in:
Cursor Agent 2026-05-22 20:31:15 +00:00
parent 00cde9da7c
commit 50ef9c8c21
No known key found for this signature in database

View file

@ -346,7 +346,21 @@ class GeminiRealtimeConfig(BaseRealtimeConfig):
cast(OpenAIRealtimeTurnDetection, turn_detection)
)
if len(transformed_audio_activity_config) > 0:
# Gemini Live treats a subsequent BidiGenerateContentSetup as a
# full session replacement rather than a partial merge. Carry
# forward the original setup (tools, generationConfig,
# inputAudioTranscription, systemInstruction, ...) and only
# override realtimeInputConfig so the guardrail-driven VAD
# change doesn't silently drop tools or other config.
try:
original_setup = cast(
BidiGenerateContentSetup,
json.loads(session_configuration_request).get("setup", {}),
)
except (json.JSONDecodeError, AttributeError):
original_setup = {}
follow_up_setup: BidiGenerateContentSetup = {
**original_setup,
"model": f"models/{model}",
"realtimeInputConfig": BidiGenerateContentRealtimeInputConfig(
automaticActivityDetection=transformed_audio_activity_config