Skip to content

feat(agents): serialize inline AgentTasks from one turn - #2313

Merged
u9g merged 1 commit into
prickled-ghettoes-tacosfrom
unlearns-complain-twirls
Aug 21, 2026
Merged

u9g merged 1 commit into
prickled-ghettoes-tacosfrom
unlearns-complain-twirls

Conversation

@rosetta-livekit-bot

@rosetta-livekit-bot rosetta-livekit-bot Bot commented Aug 21, 2026 •

Copy link
Copy Markdown
Contributor

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 to agents/src/voice/agent.ts. The Python await implementation maps to AgentTask.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 to agents/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 to agents/src/voice/speech_handle.ts. Added counted interruption holds with first-value restoration and forced-interrupt suppression.
  • tests/test_nested_agent_task.py: adapted to agents/src/voice/agent.test.ts using 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.ts was adapted so target-only context items with no model input are no-op generations, matching the source test harness behavior.
  • Not applicable: none.

Validation

  • pnpm build
  • pnpm lint
  • pnpm format:check
  • pnpm throws:check
  • pnpm exec vitest run agents/src/voice/agent.test.ts (29 passed)
  • cue-cli text-mode runtime smoke test: two parallel parent tools produced two sequential AgentTask handoffs and both successful outputs
  • pnpm test agents: 953 passed, 2 skipped, 11 pre-existing failures in untouched agents/src/voice/amd.test.ts; running that file alone reproduces the same 11 failures

Additional check: pnpm --filter @livekit/agents api:check is blocked by the existing API Extractor error for export * as in dist/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.

@changeset-bot

changeset-bot Bot commented Aug 21, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: f6d3bbf

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 39 packages
Name Type
@livekit/agents Patch
@livekit/agents-plugin-anam Patch
@livekit/agents-plugin-anthropic Patch
@livekit/agents-plugin-assemblyai Patch
@livekit/agents-plugin-azure Patch
@livekit/agents-plugin-baseten Patch
@livekit/agents-plugin-bey Patch
@livekit/agents-plugin-cartesia Patch
@livekit/agents-plugin-cerebras Patch
@livekit/agents-plugin-deepgram Patch
@livekit/agents-plugin-did Patch
@livekit/agents-plugin-elevenlabs Patch
@livekit/agents-plugin-fishaudio Patch
@livekit/agents-plugin-google Patch
@livekit/agents-plugin-hedra Patch
@livekit/agents-plugin-hume Patch
@livekit/agents-plugin-inworld Patch
@livekit/agents-plugin-krisp Patch
@livekit/agents-plugin-lemonslice Patch
@livekit/agents-plugin-liveavatar Patch
@livekit/agents-plugin-livekit Patch
@livekit/agents-plugin-minimax Patch
@livekit/agents-plugin-mistral Patch
@livekit/agents-plugin-mistralai Patch
@livekit/agents-plugin-neuphonic Patch
@livekit/agents-plugin-openai Patch
@livekit/agents-plugin-perplexity Patch
@livekit/agents-plugin-phonic Patch
@livekit/agents-plugin-protoface Patch
@livekit/agents-plugin-resemble Patch
@livekit/agents-plugin-rime Patch
@livekit/agents-plugin-runway Patch
@livekit/agents-plugin-sarvam Patch
@livekit/agents-plugin-silero Patch
@livekit/agents-plugin-soniox Patch
@livekit/agents-plugin-tavus Patch
@livekit/agents-plugins-test Patch
@livekit/agents-plugin-trugen Patch
@livekit/agents-plugin-xai Patch

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

@rosetta-livekit-bot
rosetta-livekit-bot Bot requested a review from u9g August 21, 2026 13:26

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 1 additional finding.

Open in Devin Review

@u9g
u9g force-pushed the unlearns-complain-twirls branch from 222d0c9 to a0ed705 Compare August 21, 2026 17:07
@u9g
u9g requested a review from a team as a code owner August 21, 2026 17:35
@u9g
u9g force-pushed the unlearns-complain-twirls branch from a0ed705 to bdc1481 Compare August 21, 2026 17:35
@u9g
u9g force-pushed the unlearns-complain-twirls branch from 24a3cc7 to f6d3bbf Compare August 21, 2026 17:56
@u9g
u9g merged commit 0da1e11 into main Aug 21, 2026
6 checks passed
@u9g
u9g deleted the unlearns-complain-twirls branch August 21, 2026 18:03
@github-actions github-actions Bot mentioned this pull request Aug 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant