feat(agents): serialize inline AgentTasks from one turn - #2313
Merged
Merged
Conversation
🦋 Changeset detectedLatest commit: f6d3bbf The changes in this PR will be included in the next version bump. This PR includes changesets to release 39 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 |
u9g
force-pushed
the
unlearns-complain-twirls
branch
from
August 21, 2026 17:07
222d0c9 to
a0ed705
Compare
u9g
force-pushed
the
unlearns-complain-twirls
branch
from
August 21, 2026 17:35
a0ed705 to
bdc1481
Compare
u9g
approved these changes
Aug 21, 2026
u9g
force-pushed
the
unlearns-complain-twirls
branch
from
August 21, 2026 17:56
24a3cc7 to
f6d3bbf
Compare
Merged
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#6862 so parallel tool calls that await inline AgentTasks queue on the activity they pause instead of overwriting one another's handoffs. Interruption holds are counted across queued siblings, drain registration remains ahead of the queue, and RunResult watches begin only after a task acquires the slot.
The task lifecycle now also preserves the source close-race and onEnter behavior: skipped activities fail with ToolError, and onEnter runs are guarded without blocking nested tasks that need another user turn.
Source diff coverage
livekit-agents/livekit/agents/voice/agent.py: adapted toagents/src/voice/agent.ts. The Python await implementation maps toAgentTask.run(); the full handoff/result/resume lifecycle is wrapped in the old activity slot, with JS Task, Future, and RunResult semantics.livekit-agents/livekit/agents/voice/agent_activity.py: adapted toagents/src/voice/agent_activity.ts. Added a per-activity mutex and callback-based slot helper because TypeScript has no async context manager.livekit-agents/livekit/agents/voice/speech_handle.py: ported toagents/src/voice/speech_handle.ts. Added counted interruption holds with first-value restoration and forced-interrupt suppression.tests/test_nested_agent_task.py: adapted toagents/src/voice/agent.test.tsusing AgentSession, FakeLLM, and target tool APIs. Both added source regressions are ported: parallel dialogs serialize and later-turn nested tasks acquire their own activity slot.agents/src/voice/testing/fake_llm.tswas adapted so target-only context items with no model input are no-op generations, matching the source test harness behavior.Validation
pnpm buildpnpm lintpnpm format:checkpnpm throws:checkpnpm exec vitest run agents/src/voice/agent.test.ts(29 passed)cue-clitext-mode runtime smoke test: two parallel parent tools produced two sequential AgentTask handoffs and both successful outputspnpm test agents: 953 passed, 2 skipped, 11 pre-existing failures in untouchedagents/src/voice/amd.test.ts; running that file alone reproduces the same 11 failuresAdditional check:
pnpm --filter @livekit/agents api:checkis blocked by the existing API Extractor error forexport * asindist/index.d.ts.Ported from livekit/agents#6862
Original PR description
Inline
AgentTasks awaited from one turn's parallel tool calls now queue for a slot on the activity they pause and take it in turn, instead of overwriting each other's handoffs and leaving the session wedged until close times out; scoping the slot to the activity is what keeps a nested task, which pauses a different one, from waiting on its parent. Supersedes #6860.