Skip to content

Scope tool search to request tools and tighten deferred tool handling#317707

Closed
PenguinDOOM wants to merge 11 commits into
microsoft:mainfrom
PenguinDOOM:atlas/vscode-tool-search-request-scoping
Closed

Scope tool search to request tools and tighten deferred tool handling#317707
PenguinDOOM wants to merge 11 commits into
microsoft:mainfrom
PenguinDOOM:atlas/vscode-tool-search-request-scoping

Conversation

@PenguinDOOM

@PenguinDOOM PenguinDOOM commented May 21, 2026

Copy link
Copy Markdown
Contributor

Summary

  • centralize request-scoped tool classification with a shared request tool manifest
  • scope tool search results to deferred tools available for the active request
  • harden responses/messages serialization and prompt guidance for zero-deferred requests
  • restore Anthropic request-scoped tool grouping, including virtual activate_* groups
  • align ToolSearchTool with the request-scoped deferred snapshot, including virtual groups
  • preserve tool_search request context across real invocation, shallow-clone, and plain-object/JSON round-trip boundaries with regression tests
  • harden deferred tool handling by excluding tool_search from deferred manifests, sharing zero-deferred pruning, and opportunistically evicting stale request-scoped tool-search snapshots
  • keep non-deferred built-in tools direct when default built-in grouping is enabled, so tools like vscode_askQuestions remain directly callable
  • add regression coverage for request-scoped tool selection, endpoint behavior, prompt reminders, defaultIntentRequestHandler Anthropic grouping, clone-safe ToolSearchTool behavior, and built-in grouping behavior

Testing

  • npm run gulp compile-extensions
  • npm --prefix extensions/copilot run test:unit -- src/extension/intents/node/test/backgroundTodoEnablement.spec.ts src/extension/tools/node/test/testToolsService.ts
  • .\node_modules\.bin\vitest.cmd run src/extension/prompt/node/test/defaultIntentRequestHandler.spec.ts --testNamePattern "keeps activate_vs_code_interaction in request-scoped tools for anthropic tool search requests"
  • .\node_modules\.bin\vitest.cmd run src/extension/tools/node/test/toolSearchTool.spec.ts --testNamePattern "searches only deferred tools enabled for the active request"
  • .\node_modules\.bin\vitest.cmd run src/extension/tools/node/test/toolSearchTool.spec.ts --testNamePattern "fails explicitly when invoke runs without request-scoped resolveInput context"
  • .\node_modules\.bin\vitest.cmd run src/extension/tools/node/test/toolSearchTool.spec.ts --testNamePattern "retains request-scoped virtual activate groups during tool search candidate selection|preserves request-scoped deferred tools after resolved input is shallow-cloned|preserves request-scoped deferred tools after resolved input is JSON-round-tripped"
  • .\node_modules\.bin\vitest.cmd run src/extension/tools/test/node/virtualTools/builtInToolGroupHandler.spec.ts --reporter=basic
  • npx vitest run src/platform/endpoint/node/test/responsesApiToolSearch.spec.ts
  • npx vitest run src/platform/endpoint/test/node/messagesApi.spec.ts
  • npx vitest run src/extension/prompts/node/agent/test/agentPrompt.spec.tsx --testNamePattern "OpenAI reminder instructions"
  • npm run test:unit -- src/extension/prompts/node/agent/test/agentPrompt.spec.tsx -t "tool_search reminder|hidden-model-m reminder"

Review follow-up

  • Built-in grouping follow-up (fix(tool-grouping): keep non-deferred built-ins direct) was reviewed by Code-Review-subagent and approved.
  • No blocking correctness issues were found in the BuiltInToolGroupHandler / VirtualToolGrouper changes.
  • Only non-blocking notes remained: a possible clarifying comment around the effectively unreachable ToolCategory.Core summary branch, and a note that ToolSearch stays direct in the new test because it is categorized as Core.

Fixes #316779

Copilot AI review requested due to automatic review settings May 21, 2026 05:34

Copilot AI 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.

Pull request overview

This PR fixes tool-search deferral mismatches by introducing a request-scoped “tool manifest” that consistently classifies enabled tools as deferred vs non-deferred, then using that manifest to (1) scope tool-search results to tools actually deferred/available for the active request and (2) omit tool-search scaffolding/prompt guidance entirely when a request has zero deferred tools. This targets cases where models see tool suggestions (via tool search) that they cannot actually invoke in the current request.

Changes:

  • Centralized request-scoped tool classification via createRequestToolManifest and used it across endpoint body builders and tools services.
  • Tightened tool_search behavior: omit client tool_search machinery when no deferred tools exist; and enforce request-scoped context for ToolSearchTool invocation.
  • Added regression tests and updated prompt snapshots to reflect conditional tool_search guidance/reminders.

Reviewed changes

Copilot reviewed 26 out of 26 changed files in this pull request and generated no comments.

Show a summary per file
File Description
extensions/copilot/src/platform/endpoint/test/node/messagesApi.spec.ts Adds coverage ensuring Messages API omits tool_search scaffolding when no tools are deferred.
extensions/copilot/src/platform/endpoint/node/test/responsesApiToolSearch.spec.ts Adds coverage ensuring Responses API omits client tool_search tool when no tools are deferred.
extensions/copilot/src/platform/endpoint/node/responsesApi.ts Uses request-scoped manifest to gate tool search deferral and tool_search inclusion for Responses API.
extensions/copilot/src/platform/endpoint/node/messagesApi.ts Uses request-scoped manifest + model capability gating to skip tool_search when it would be ineffective.
extensions/copilot/src/extension/tools/vscode-node/toolsService.ts Prunes tool_search from enabled tools when the request contains zero deferred tools.
extensions/copilot/src/extension/tools/node/toolSearchTool.ts Scopes tool search candidates to deferred tools enabled for the active request; enforces resolveInput context.
extensions/copilot/src/extension/tools/node/test/toolSearchTool.spec.ts New unit tests for request-scoped tool search behavior and explicit failure without resolveInput context.
extensions/copilot/src/extension/tools/node/test/testToolsService.ts Aligns test tools service with request-scoped manifest and tool_search pruning behavior.
extensions/copilot/src/extension/tools/common/requestToolManifest.ts New shared helper to classify active tools into deferred vs non-deferred for a request.
extensions/copilot/src/extension/prompts/node/agent/toolSearchInstructions.tsx Makes tool_search guidance conditional on endpoint support, tool_search availability, and presence of deferred tools.
extensions/copilot/src/extension/prompts/node/agent/test/agentPrompt.spec.tsx Adds tests for OpenAI prompt reminders to omit tool_search guidance when no deferred tools exist.
extensions/copilot/src/extension/prompts/node/agent/test/snapshots/agentPrompts-claude-sonnet-4.6/all_tools.spec.snap Snapshot updates reflecting conditional removal of tool_search instructions / deferred tool list.
extensions/copilot/src/extension/prompts/node/agent/test/snapshots/agentPrompts-claude-sonnet-4.6/all_non_edit_tools.spec.snap Snapshot updates reflecting conditional removal of tool_search instructions / deferred tool list.
extensions/copilot/src/extension/prompts/node/agent/test/snapshots/agentPrompts-claude-sonnet-4.5/all_tools.spec.snap Snapshot updates reflecting conditional removal of deferred tool list + whitespace normalization.
extensions/copilot/src/extension/prompts/node/agent/test/snapshots/agentPrompts-claude-sonnet-4.5/all_non_edit_tools.spec.snap Snapshot updates reflecting conditional removal of deferred tool list + whitespace normalization.
extensions/copilot/src/extension/prompts/node/agent/test/snapshots/agentPrompts-claude-opus-4.6/all_tools.spec.snap Snapshot updates reflecting conditional removal of tool_search instructions / deferred tool list.
extensions/copilot/src/extension/prompts/node/agent/test/snapshots/agentPrompts-claude-opus-4.6/all_non_edit_tools.spec.snap Snapshot updates reflecting conditional removal of tool_search instructions / deferred tool list.
extensions/copilot/src/extension/prompts/node/agent/test/snapshots/agentPrompts-claude-opus-4.5/all_tools.spec.snap Snapshot updates reflecting conditional removal of deferred tool list + whitespace normalization.
extensions/copilot/src/extension/prompts/node/agent/test/snapshots/agentPrompts-claude-opus-4.5/all_non_edit_tools.spec.snap Snapshot updates reflecting conditional removal of deferred tool list + whitespace normalization.
extensions/copilot/src/extension/prompts/node/agent/openai/hiddenModelMPrompt.tsx Makes reminder tool_search guidance conditional using the shared predicate and tool deferral service.
extensions/copilot/src/extension/prompts/node/agent/openai/gpt55BasePrompt.tsx Makes reminder tool_search guidance conditional using the shared predicate and tool deferral service.
extensions/copilot/src/extension/prompts/node/agent/openai/gpt54Prompt.tsx Makes reminder tool_search guidance conditional using the shared predicate and tool deferral service.
extensions/copilot/src/extension/prompts/node/agent/defaultAgentInstructions.tsx Extends reminder props to include availableTools for request-scoped tool_search reminder logic.
extensions/copilot/src/extension/prompts/node/agent/agentPrompt.tsx Plumbs availableTools into reminder instruction props.
extensions/copilot/src/extension/intents/node/test/backgroundTodoEnablement.spec.ts Adds regression coverage around publishing/explicitly disabling vscode_askQuestions in agent tools.
extensions/copilot/src/extension/intents/node/agentIntent.ts Allows vscode_askQuestions tool in agent tool set by default (subject to request tool picker overrides).

@PenguinDOOM PenguinDOOM marked this pull request as draft May 21, 2026 20:42
PenguinDOOM and others added 8 commits May 22, 2026 06:29
 - add RED contracts for zero-deferred endpoint behavior
 - cover initial vscode_askQuestions publication in agent mode
 - add ToolSearchTool and getEnabledTools request-scope regressions
 - add shared request-scoped deferred tool classification
 - prune tool_search when no deferred tools remain
 - publish vscode_askQuestions on initial agent requests
 - capture deferred tool names from request context
 - isolate request snapshots on resolved input objects
 - filter search candidates to request-scoped deferred tools
 - fail explicitly when request-scoped context is missing
 - gate responses and messages tool search on deferred availability
 - suppress prompt guidance unless tool_search is active for the request
 - keep endpoint and prompt behavior aligned on request-scoped signals
Co-authored-by: Copilot <copilot@github.com>
Co-authored-by: Copilot <copilot@github.com>
@PenguinDOOM PenguinDOOM force-pushed the atlas/vscode-tool-search-request-scoping branch from 30b8cc2 to c1e2f77 Compare May 21, 2026 21:30
@PenguinDOOM

Copy link
Copy Markdown
Contributor Author

I was able to confirm locally that there were no problems calling the tools with either GPT or Claude.

@PenguinDOOM PenguinDOOM marked this pull request as ready for review May 21, 2026 21:39
@PenguinDOOM PenguinDOOM requested a review from Copilot May 21, 2026 21:39

Copilot AI 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.

Pull request overview

Copilot reviewed 28 out of 28 changed files in this pull request and generated 5 comments.

Comment thread extensions/copilot/src/extension/tools/node/toolSearchTool.ts
Comment thread extensions/copilot/src/extension/tools/node/toolSearchTool.ts Outdated
Comment thread extensions/copilot/src/extension/tools/node/toolSearchTool.ts
Comment thread extensions/copilot/src/extension/tools/node/toolSearchTool.ts
Comment thread extensions/copilot/src/extension/tools/vscode-node/toolsService.ts Outdated
Updated the comment in the 'createMessagesRequestBody tool search deferral' test to clarify the behavioral contract regarding the omission of the client-side tool_search scaffold when no request tool is deferred.
@bhavyaus

Copy link
Copy Markdown
Collaborator

Thanks — the root cause is real and a good catch: a non-deferred tool (like askQuestions) getting pulled into a virtual group while defaultToolsGrouped + tool search are both active means it's never surfaced via tool_search_output, so the model can't call it.

I'm going to pass on this PR as the fix, though. The actual fix is basically a one-line invariant ("non-deferred tools must never be grouped"), but this PR is ~1,100 lines across 31 files of request-scoped manifests, serialization, and prompt-gating changes that go well beyond the root cause and touch experimental tool-search internals we're actively iterating on.

@bhavyaus bhavyaus closed this May 23, 2026
@PenguinDOOM PenguinDOOM deleted the atlas/vscode-tool-search-request-scoping branch May 27, 2026 15:06
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.

The target tool appears in the suggestions via toolSearch, but it cannot actually be used (GPT)

3 participants