fix: honor ignore on enter for toolsets#2011
Open
rosetta-livekit-bot[bot] wants to merge 1 commit into
Open
Conversation
🦋 Changeset detectedLatest commit: 07b0948 The changes in this PR will be included in the next version bump. This PR includes changesets to release 36 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.
Summary
Ports livekit/agents#6361 to JS by honoring
ToolFlag.IGNORE_ON_ENTERafter flatteningToolContext, so ignored tools nested inside aToolsetare hidden duringonEnterreplies and their nested tool-response follow-ups.Also adds
ignoreOnEntertocreateEndCallTool, matching the source option for hiding the end-call tool during greetings.Source diff coverage
Coverage classification
livekit-agents/livekit/agents/beta/tools/end_call.pyagents/src/beta/tools/end_call.ts: addedignoreOnEnter?: booleanand maps it toToolFlag.IGNORE_ON_ENTER; JS uses camelCase options and factory function style.livekit-agents/livekit/agents/llm/tool_context.pyagents/src/llm/tool_context.ts: added internal_exclude()/ flattened sync behavior that hides selected callable tools while preserving owningToolsetlifecycle/grouping.livekit-agents/livekit/agents/voice/agent_activity.pyagents/src/voice/agent_activity.ts: replaced top-level-only on-enter filtering with flattenedToolContextfiltering for pipeline replies, added_onEnterIgnoredTools, and applied temporary filtered tools for realtime replies.tests/test_agent_session.pyagents/src/voice/agent_activity.test.ts: ported the source behavioral assertions to target unit-style coverage for bare plus toolset-nested ignored tools, nested async/tool-response context preservation, restoration outsideonEnter, and agent/session scoping.tests/test_tools.pyagents/src/llm/tool_context.test.ts: ported_excludetests and adapted the end-call flag test tocreateEndCallTool({ ignoreOnEnter: true }).Verification
pnpm test agents/src/llm/tool_context.test.ts agents/src/voice/agent_activity.test.tspassed.pnpm --filter @livekit/agents typecheckpassed.pnpm --filter @livekit/agents buildpassed.pnpm --filter @livekit/agents lintcompleted with existing warnings only.pnpm test agents/srcwas run twice. The final run had 90 test files pass and 1 fail:agents/src/voice/amd.test.tswith 11 AMD-classification/time-out failures unrelated to this port.pnpm --filter @livekit/agents api:checkis blocked by existing API Extractor tooling:The "export * as ___" syntax is not supported yetin generatedagents/dist/index.d.ts.cue-cliruntime validation was attempted with a temporary built.mjsagent using aToolset-nested ignored tool. The worker registered and ranonEnter, butcue-cli run --resume --until 'debug_message(.payload.visible_tools="keep")'timed out with zero captured framework events, so the cue-cli validation was inconclusive. The temporary agent was not committed.Changeset
Added a patch changeset for
@livekit/agents.Ported from livekit/agents#6361
Original PR description
Closes #6354
ToolFlag.IGNORE_ON_ENTERwas only honored for bareFunctionTool/RawFunctionToolinstances in theon_enterreply filter — tools nested in aToolset(e.g.EndCallTool) passed through unfiltered, so the model could fire a speculativeend_callduring the greeting turn (withdelete_room=True, an instant hangup at pickup).The filter now flattens toolsets and hides flagged tools via
ToolContext._exclude, which drops them from the callable/LLM-visible set while keeping the owning toolset in place so executor routing and lifecycle are unaffected. Rather than threading the ignored set through the reply tasks,_on_enter_ignored_toolsreads theon_entercontextvar directly; the reply task and its tool-response follow-ups inherit it throughasyncio.create_task.The realtime path is covered too: it only overrides its session tools when
generate_replyis giventools=, so insideon_enterit now falls back to the agent's full set and hides flagged tools even without an explicittools=.EndCallToolgains anignore_on_enterparameter (defaults toFalse, preserving current behavior) to opt into hidingend_callduring the greeting.