feat(agents): add warm transfer task#1458
Open
rosetta-livekit-bot[bot] wants to merge 10 commits into
Open
Conversation
🦋 Changeset detectedLatest commit: 9e82f41 The changes in this PR will be included in the next version bump. This PR includes changesets to release 31 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 |
The `_humanAgentFailed` promise and its `_resolveHumanAgentFailed` resolver were declared as class field initializers. With `target: es2022`, ESM class fields use `[[Define]]` semantics: each declaration installs an own-property on the instance, so `_resolveHumanAgentFailed!: () => void;` overwrote the resolver that was just assigned inside the Promise executor of the previous field. The resolver was therefore `undefined` for the task's lifetime, and the human agent room disconnect handler crashed with `TypeError: this._resolveHumanAgentFailed is not a function`. Move both assignments into the constructor body, where plain `this.x = …` is not subject to `[[Define]]`. Co-authored-by: Cursor <cursoragent@cursor.com>
`AgentActivity.generateReply` defaulted `toolChoice` to `'none'` whenever it detected we were "inside a tool", using `functionCallStorage` (a Node.js `AsyncLocalStorage`). ALS contexts propagate across every `await`, including into a child `AgentSession` spawned from inside a tool's `execute` (e.g. the supervisor session in `beta.WarmTransferTask`). The child session's regular user-turn replies therefore inherited the parent's tool context, the framework forced `toolChoice: 'none'`, and `executeToolsTask` dropped every tool call the child agent emitted — including `connect_to_caller`, leaving the caller on hold indefinitely. Switch the check to per-task info (`Task.current()` + `_getActivityTaskInfo`), which is scoped to the owning activity and does not leak across sessions. Matches Python's `_get_activity_task_info(task).function_call` behaviour. Co-authored-by: Cursor <cursoragent@cursor.com>
- Disconnect _humanAgentRoom in setResult; AgentSession.shutdown() closes
RoomIO but does not disconnect the underlying Room, so each completed
transfer would otherwise leak a WebSocket to the supervisor room.
- Replace the chained INSTRUCTIONS_TEMPLATE substitutions with a single
regex pass using function replacements. Avoids JavaScript replace
string interpreting dollar-sign patterns from user content, and stops
earlier substitutions from hijacking later placeholders such as
{extra} appearing inside the conversation history.
Co-authored-by: Cursor <cursoragent@cursor.com>
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.
Summary
WarmTransferTaskworkflow for SIP-based human handoffs.Validation
pnpm --filter @livekit/agents buildpnpm --filter @livekit/agents build:typespnpm --filter @livekit/agents lint(passes with existing warnings)pnpm --filter @livekit/agents api:check(blocked by existing API Extractorexport * aslimitation indist/index.d.ts)