Skip to content

Commit 34d0d62

Browse files
authored
fix gemini live tool execution interrupted by generation_complete event (#4699)
1 parent 1725929 commit 34d0d62

File tree

1 file changed

+9
-4
lines changed
  • livekit-plugins/livekit-plugins-google/livekit/plugins/google/realtime

1 file changed

+9
-4
lines changed

livekit-plugins/livekit-plugins-google/livekit/plugins/google/realtime/realtime_api.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1354,11 +1354,16 @@ def _is_new_generation(self, resp: types.LiveServerMessage) -> bool:
13541354

13551355
if (sc := resp.server_content) and (
13561356
sc.model_turn
1357-
or (sc.output_transcription and sc.output_transcription is not None)
1358-
or (sc.input_transcription and sc.input_transcription is not None)
1359-
or (sc.generation_complete is not None)
1360-
or (sc.turn_complete is not None)
1357+
or (
1358+
sc.output_transcription and sc.output_transcription and sc.output_transcription.text
1359+
)
1360+
or (sc.input_transcription and sc.input_transcription and sc.input_transcription.text)
1361+
# or (sc.generation_complete is not None)
1362+
# or (sc.turn_complete is not None)
13611363
):
1364+
# Some Gemini models send a `generation_complete` event after tool calls, but others do not.
1365+
# We mark the generation as done after a tool call and need to ignore any empty transcriptions or generation_complete events.
1366+
# This prevents new empty generations from starting and interrupting tool execution.
13621367
return True
13631368

13641369
return False

0 commit comments

Comments
 (0)