fix(voice): agent and user state while a tool runs - #2311
Open
rosetta-livekit-bot[bot] wants to merge 1 commit into
Open
fix(voice): agent and user state while a tool runs#2311rosetta-livekit-bot[bot] wants to merge 1 commit into
rosetta-livekit-bot[bot] wants to merge 1 commit into
Conversation
🦋 Changeset detectedLatest commit: 21d6012 The changes in this PR will be included in the next version bump. This PR includes changesets to release 35 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Ports livekit/agents#6937.
Summary
thinkingafter preamble and filler speech finishesValidation
pnpm exec vitest run agents/src/voice/agent_tool_state.test.ts agents/src/voice/realtime_agent_state_during_tool.test.ts agents/src/voice/agent_activity.test.ts agents/src/voice/generation_tools.test.ts(29 passed)pnpm exec vitest run agents(1,062 passed, 2 skipped; 11 pre-existing failures inagents/src/voice/amd.test.ts, reproduced unchanged when that file runs alone)pnpm buildpnpm lint(passes with existing warnings)pnpm format:checkpnpm --filter @livekit/agents build:typescue-cli: slow tool with filler producedAS_SPEAKING -> AS_THINKING, remained thinking for the six-second tool, emitted noUS_AWAY, then delivered the tool replySource diff coverage
Source diff coverage
livekit-agents/livekit/agents/voice/agent_activity.py->agents/src/voice/agent_activity.ts. Preserves pipeline, filler/say, realtime, server-generated reply, and no-reply state transitions.livekit-agents/livekit/agents/voice/agent_session.py->agents/src/voice/agent_session.ts. Uses a session-scoped call ID set instead of Python weak-keyed_RunningTasks, and centralizes lifecycle event handling and away-window restart.livekit-agents/livekit/agents/voice/events.py->agents/src/voice/run_context.ts. JS ownsRunContext.update()in this file; updates now use the centralized session lifecycle hook.livekit-agents/livekit/agents/voice/tool_executor.py->agents/src/voice/generation.ts. JS executes tools inperformToolExecutions; started and ended updates now flow through the session hook.tests/fake_realtime.py-> the fake realtime model/session inagents/src/voice/realtime_agent_state_during_tool.test.ts, including controllable generation resolvers.tests/test_agent_session.py->agents/src/voice/agent_tool_state.test.ts. Ports all four blocking, silent, deferred-away, and no-reply scenarios with deterministic Vitest timers.tests/test_realtime_agent_state_during_tool.py->agents/src/voice/realtime_agent_state_during_tool.test.ts. Ports all three realtime state scenarios.tests/test_tools.py->agents/src/voice/generation_tools.test.ts. Mock sessions now expose the centralized lifecycle hook used by tool execution.Ported from livekit/agents#6937
Original PR description
Problem
A long tool call marks the user away, so the app asks "are you still there?" over the agent's own reply. The away timer arms whenever the agent and the user are both listening, and a tool call does not stop it. Filler speech ends in "listening" (livekit/agents#6904), and an async tool leaves the agent listening for its whole run (livekit/agents#6883). After the user is away, nothing restarts the window, so no further
user_state_changedevent fires in that session.Fix
The away timer no longer arms while a tool runs, and the last tool to land restarts the window in full. The user never enters "away" during a tool call, so the state cannot stick there and livekit/agents#6883 needs no new API. Agent state separates the two cases: a blocking tool holds "thinking", and an async tool stays "listening" because the user can still speak. The realtime path also gains the state resets the pipeline already had, so a tool that asks for no reply hands the state back.
Based on livekit/agents#6908 by @VihaanAgarwal, with the review comments folded in.
close #6904 and close #6883