fix(gemini realtime): mirror modalities/temperature/max_output_tokens on tool-call response.created

The audio/text response.created preamble includes modalities, temperature,
and max_output_tokens on the response object so spec-compliant clients can
initialise per-response state. The tool-call response.created was missing
these fields, leaving clients without consistent response metadata when a
response starts with a tool call instead of content. Read them from the
cached session_configuration_request the same way the audio/text path
does.
This commit is contained in:
mateo-berri 2026-05-22 21:44:43 +00:00
parent 615a7da9ba
commit b60cc950f3
No known key found for this signature in database
2 changed files with 38 additions and 1 deletions

View file

@ -1251,7 +1251,31 @@ class GeminiRealtimeConfig(BaseRealtimeConfig):
current_response_id = f"resp_{uuid.uuid4()}"
current_output_item_id = f"item_{uuid.uuid4()}"
# Emit response.created
# Mirror the audio/text path: include modalities,
# temperature, and max_output_tokens on response.created so
# spec-compliant clients see consistent response metadata
# regardless of whether the response starts with content or
# a tool call.
session_setup: BidiGenerateContentSetup = {}
if session_configuration_request is not None:
try:
session_setup = json.loads(
session_configuration_request
).get("setup", {})
except (json.JSONDecodeError, TypeError):
session_setup = {}
tool_call_generation_config = (
session_setup.get("generationConfig", {}) or {}
)
tool_call_modalities = [
modality.lower()
for modality in cast(
List[str],
tool_call_generation_config.get(
"responseModalities", ["AUDIO"]
),
)
]
returned_message.append(
{
"type": "response.created",
@ -1262,6 +1286,13 @@ class GeminiRealtimeConfig(BaseRealtimeConfig):
"status": "in_progress",
"output": [],
"conversation_id": current_conversation_id,
"modalities": tool_call_modalities,
"temperature": tool_call_generation_config.get(
"temperature"
),
"max_output_tokens": tool_call_generation_config.get(
"maxOutputTokens"
),
},
}
)

View file

@ -715,6 +715,12 @@ def test_gemini_tool_call_emits_response_created_preamble():
assert responses[0]["type"] == "response.created"
assert "response" in responses[0]
assert responses[0]["response"]["status"] == "in_progress"
# response.created on the tool-call path mirrors the audio/text preamble:
# modalities/temperature/max_output_tokens are present so spec-compliant
# clients see consistent response metadata regardless of payload type.
assert "modalities" in responses[0]["response"]
assert "temperature" in responses[0]["response"]
assert "max_output_tokens" in responses[0]["response"]
assert responses[1]["type"] == "response.output_item.added"
assert responses[1]["item"]["type"] == "function_call"
assert responses[1]["item"]["status"] == "in_progress"