fix: honor ignore on enter for toolsets - #2011
Merged
Merged
Conversation
🦋 Changeset detectedLatest commit: 280e7bd 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 |
Exercise full pipeline and realtime sessions so nested on-enter filtering remains scoped through tool responses without leaking into later user turns. Co-authored-by: Cursor <cursoragent@cursor.com>
Protect temporary realtime setup so providers that mutate before rejecting cannot leave ignored tools removed. Co-authored-by: Cursor <cursoragent@cursor.com>
Restore tool choice and tools independently so cleanup errors cannot mask the primary generation failure or skip later cleanup. Co-authored-by: Cursor <cursoragent@cursor.com>
toubatbrian
approved these changes
Jul 15, 2026
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.
Summary
Ports livekit/agents#6361 to JS by honoring
ToolFlag.IGNORE_ON_ENTERafter flatteningToolContext, so ignored tools nested inside aToolsetare hidden duringonEnterreplies and nested tool-response follow-ups, then restored for later user turns.Also adds
ignoreOnEntertocreateEndCallTool, matching the Python option for hiding the end-call tool during greetings.Python parity
The final implementation matches the current Python lifecycle and cleanup behavior:
ToolContextwhile preserving nestedToolsetlifecycle and routing.try/finally, so providers that mutate and then reject cannot strand the filtered context.failed to reset tool_choice/failed to reset tools), so one cleanup failure cannot skip the other or mask a primary generation error.createEndCallTool({ ignoreOnEnter: true })maps toToolFlag.IGNORE_ON_ENTER; the default remainsfalse.Source diff coverage
livekit-agents/livekit/agents/beta/tools/end_call.pyagents/src/beta/tools/end_call.ts: camelCase option and factory-function API.livekit-agents/livekit/agents/llm/tool_context.pyagents/src/llm/tool_context.ts: flattened exclusion plus an internal flattened copy for temporary realtime updates.livekit-agents/livekit/agents/voice/agent_activity.pyagents/src/voice/agent_activity.ts: pipeline/realtime filtering, setup-failure restoration, and independent cleanup failure logging.tests/test_agent_session.pyAgentSessioncoverage for greeting, nested tool response, later-turn restoration, provider mutation/rejection, and cleanup failures.tests/test_tools.py_excludebehavior andcreateEndCallTool({ ignoreOnEnter: true }).Production-path verification
The focused suite runs real
AgentSessionpipeline and realtime paths with ordinary, ignored, and two-level nested toolsets. It verifies:Final focused result on head
280e7bdbb78d196db1f9c82c8a2efaec2ca4ac12: 3 files passed, 86 tests passed.Additional local checks passed:
pnpm build:agents.pnpm build.pnpm --filter @livekit/agents typecheck.eslint --quiet.pnpm format:check.git diff --check.The existing full-agents run still has the unrelated AMD timing/classification failures, and API Extractor remains blocked by its existing unsupported generated
export * as ___syntax.Cue voice E2E
Fresh voice verification was run at literal local/remote head
280e7bdbb78d196db1f9c82c8a2efaec2ca4ac12after a successful full repository build.sid_6c92d326915e.openai/gpt-4.1-mini,deepgram/nova-3, andcartesia/sonic-3.allowed_greeting_probeand nestedallowed_nested_probe;ignored_restored_probewas absent. Cue then waited for the committed assistant message after playout.ignored_restored_probe, then committed the assistant confirmation after playout.~/.cue-cli/sessions/sid_6c92d326915e/events.jsonl— SHA-2563cb7530fdef5468f17a42209dc48d064b77961f41cb2d976fa1da48ecf33eaf6.recordings/001_run/result.json— SHA-2562de039d446a27bc963609df92837808a27d74e0e1099446bc44bea585ae3136d.recordings/002_run/result.json— SHA-256563df770a12640a2da7be3062312e6859f6f84ad344d4e0f4e6131e2bf57c971.2d17e9acf7f2ac6c952533efdc746574f54af9f29cee9c6b753f59151cd2c9ab.9f5e2bbf92393c414844f22fb11c511c7ef05be718ad169717abf61f0445c0af.917ec6d6535e47da6203a17f195e54c351a0d7bf081423579d307adc27cf9386.The temporary nested-toolset harness and worker were removed after the persisted artifacts were inspected.
Changeset
The existing patch changeset for
@livekit/agentsis retained.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.