Skip to content

fix(chat): respect context key expressions for tool visibility#303663

Open
swg0101 wants to merge 1 commit intomicrosoft:mainfrom
swg0101:tool_including_disabled_fix
Open

fix(chat): respect context key expressions for tool visibility#303663
swg0101 wants to merge 1 commit intomicrosoft:mainfrom
swg0101:tool_including_disabled_fix

Conversation

@swg0101
Copy link

@swg0101 swg0101 commented Mar 21, 2026

The when clause in languageModelTools contributions was only being applied to getTools() (used by UI), not getAllToolsIncludingDisabled() (used by the extension API via $getTools).

This caused tools like configure_python_notebook and restart_notebook_kernel with when: "false" to be hidden from the tools panel but still appear in the available tools list sent to language models.

Now both methods consistently filter by the when context key expression.

Tested with the unify-chat-provider with verbose set to true and with a custom agent with tools: []. Confirmed that the tools block is no longer being sent to LLM providers.

Fixes #292260

Copilot AI review requested due to automatic review settings March 21, 2026 01:36
@vs-code-engineering vs-code-engineering bot added this to the 1.113.0 milestone Mar 21, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR makes tool visibility consistent by applying when context key expressions to both getTools() (UI) and getAllToolsIncludingDisabled() (extension API / $getTools), preventing context-hidden tools from being sent to language model providers.

Changes:

  • Apply when clause filtering in getAllToolsIncludingDisabled() to match getTools().
  • Ensure tools with when: "false" are excluded from the tool list surfaced via the extension API.

@swg0101 swg0101 force-pushed the tool_including_disabled_fix branch from ff446ca to 8986470 Compare March 21, 2026 01:41
The `when` clause in `languageModelTools` contributions was only being
applied to `getTools()` (used by UI), not `getAllToolsIncludingDisabled()`
(used by the extension API via `$getTools`).

This caused tools like `configure_python_notebook` and `restart_notebook_kernel`
with `when: "false"` to be hidden from the tools panel but still appear
in the available tools list sent to language models.

Now both methods consistently filter by the `when` context key expression.

Tested with the unify-chat-provider with verbose set to true and with a custom agent with tools: []. Confirmed that the tools block is no longer being sent to LLM providers.

Added new unit test to test new behavior.

Fixes microsoft#292260
@swg0101 swg0101 force-pushed the tool_including_disabled_fix branch from 8986470 to 98ee672 Compare March 21, 2026 01:49
@swg0101
Copy link
Author

swg0101 commented Mar 21, 2026

@microsoft-github-policy-service agree

@aeschli aeschli assigned connor4312 and unassigned aeschli Mar 22, 2026
@aeschli
Copy link
Contributor

aeschli commented Mar 22, 2026

@connor4312 you added getAllToolsIncludingDisabled
It differs from getTools from the model filter but also the when clause filter.
What does the disabled refer to?

Could the implementation of getTools use getAllToolsIncludingDisabled and add an additional filter?

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.

Notebook tools added without being enabled by the user

4 participants