refactor: explicit kind=='final' check in async-tool routing (Gemini Live)

Mirrors the same change applied to AWSNovaSonicLLMService and
OpenAIRealtimeLLMService in #4441 / GrokRealtimeLLMService in #4447:
replaces the implicit "final happens last" pattern in
_process_completed_function_calls with an explicit
`if async_payload.kind == "final":` block, plus a trailing defensive
`continue` so async-tool messages with an unrecognized kind don't fall
through to the regular tool-result handling block.
This commit is contained in:
Paul Kompfner
2026-05-08 15:47:06 -04:00
parent 6faeffb884
commit 53922819ed

View File

@@ -926,15 +926,22 @@ class GeminiLiveLLMService(LLMService[GeminiLLMAdapter]):
error_msg="Gemini Live does not support streamed async tool results.", error_msg="Gemini Live does not support streamed async tool results.",
) )
continue continue
# kind == "final": deliver via the formal tool-response channel if async_payload.kind == "final":
# — same path as a synchronous tool result, just delayed. # Deliver via the formal tool-response channel — same
tool_name = self._tool_call_id_to_name.get( # path as a synchronous tool result, just delayed.
async_payload.tool_call_id, "tool_call_result" tool_name = self._tool_call_id_to_name.get(
) async_payload.tool_call_id, "tool_call_result"
response_dict = GeminiLLMAdapter.to_function_response_dict(async_payload.result) )
if send_new_results: response_dict = GeminiLLMAdapter.to_function_response_dict(async_payload.result)
await self._tool_result(async_payload.tool_call_id, tool_name, response_dict) if send_new_results:
self._completed_tool_calls.add(async_payload.tool_call_id) await self._tool_result(
async_payload.tool_call_id, tool_name, response_dict
)
self._completed_tool_calls.add(async_payload.tool_call_id)
continue
# Defensive: any async-tool message must not fall through
# to the regular tool-result block below, even if it
# carries a kind we don't recognize.
continue continue
# Look for newly-completed "regular" (as opposed to async-tool) results # Look for newly-completed "regular" (as opposed to async-tool) results