Skip to content

Commit

Permalink
fix nested speech done future (#1355)
Browse files Browse the repository at this point in the history
  • Loading branch information
longcw authored Jan 12, 2025
1 parent 04181a0 commit b7688ae
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
2 changes: 2 additions & 0 deletions livekit-agents/livekit/agents/pipeline/pipeline_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -870,6 +870,7 @@ def _commit_user_question_if_needed() -> None:
},
)

@utils.log_exceptions(logger=logger)
async def _execute_function_calls() -> None:
nonlocal interrupted, collected_text

Expand Down Expand Up @@ -995,6 +996,7 @@ async def _execute_function_calls() -> None:
speech_handle._set_done()
return

speech_handle._nested_speech_done_fut = asyncio.Future[None]()
fnc_task = asyncio.create_task(_execute_function_calls())
while not speech_handle.nested_speech_done:
nesting_changed = asyncio.create_task(
Expand Down
9 changes: 6 additions & 3 deletions livekit-agents/livekit/agents/pipeline/speech_handle.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def __init__(

self._nested_speech_handles: list[SpeechHandle] = []
self._nested_speech_changed = asyncio.Event()
self._nested_speech_done_fut = asyncio.Future[None]()
self._nested_speech_done_fut: asyncio.Future[None] | None = None

@staticmethod
def create_assistant_reply(
Expand Down Expand Up @@ -227,9 +227,12 @@ def nested_speech_changed(self) -> asyncio.Event:

@property
def nested_speech_done(self) -> bool:
return self._nested_speech_done_fut.done()
# True if not started or done
return (
self._nested_speech_done_fut is None or self._nested_speech_done_fut.done()
)

def mark_nested_speech_done(self) -> None:
if self._nested_speech_done_fut.done():
if self._nested_speech_done_fut is None or self._nested_speech_done_fut.done():
return
self._nested_speech_done_fut.set_result(None)

0 comments on commit b7688ae

Please sign in to comment.