Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions livekit-agents/livekit/agents/voice/agent_activity.py
Original file line number Diff line number Diff line change
Expand Up @@ -1424,14 +1424,22 @@ async def _wait_for_inactive(
) -> None:
agent_active = True
user_active = True

async def _wait_for_eou() -> None:
# eou is part of the user turn and may spawn a new speech handle,
# so an in-flight eou keeps both the user and the agent active.
nonlocal user_active
if (
self._audio_recognition
and (eou_task := self._audio_recognition._end_of_turn_task)
and not eou_task.done()
):
user_active = True
await eou_task

while (wait_for_agent and agent_active) or (wait_for_user and user_active):
if wait_for_agent:
if (
self._audio_recognition
and (eou_task := self._audio_recognition._end_of_turn_task)
and not eou_task.done()
):
await eou_task
await _wait_for_eou()

if self._current_speech is None and not self._speech_q:
agent_active = False
Expand All @@ -1448,6 +1456,8 @@ async def _wait_for_inactive(
user_active = True
await self._user_silence_event.wait()

await _wait_for_eou()

# -- Realtime Session events --

def _on_metrics_collected(
Expand Down
Loading