Optimize prompt cache hit rate by freezing deferred tool list in initial context#312577
Merged
Optimize prompt cache hit rate by freezing deferred tool list in initial context#312577
Conversation
93cebad to
b0861b3
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
This PR improves Anthropic prompt-cache hit rates by relocating the dynamic deferred-tool inventory from the system prompt into the cached “global agent context” (initial user message), while keeping tool-search guidance in the system prompt. It also enables tool-search prompt support for HiddenModelB.
Changes:
- Split tool-search prompt responsibilities: keep guidance in
ToolSearchToolPromptOptimized, and emit the deferred-tool inventory once viaDeferredToolListReminder. - Render the deferred-tool inventory inside
GlobalAgentContextso it’s frozen viaGlobalContextMessageMetadataacross turns. - Update Anthropic and HiddenModelB prompts + snapshots to reflect the new placement of
<availableDeferredTools>.
Show a summary per file
| File | Description |
|---|---|
| extensions/copilot/src/extension/prompts/node/agent/toolSearchInstructions.tsx | Adds DeferredToolListReminder and removes the inline deferred-tool list from the optimized tool-search system prompt. |
| extensions/copilot/src/extension/prompts/node/agent/agentPrompt.tsx | Emits <availableDeferredTools> from GlobalAgentContext to keep it in the cached initial context. |
| extensions/copilot/src/extension/prompts/node/agent/anthropicPrompts.tsx | Updates legacy Anthropic tool-search prompt to no longer inline the deferred-tool list and to reference initial context. |
| extensions/copilot/src/extension/prompts/node/agent/openai/hiddenModelBPrompt.tsx | Adds tool-search guidance to HiddenModelB system prompt + a per-turn reminder gated on supportsToolSearch. |
| extensions/copilot/src/extension/prompts/node/agent/test/snapshots/agentPrompts-claude-sonnet-4.6/all_tools.spec.snap | Snapshot updates: <availableDeferredTools> moved from tool-search instructions to global context. |
| extensions/copilot/src/extension/prompts/node/agent/test/snapshots/agentPrompts-claude-sonnet-4.6/all_non_edit_tools.spec.snap | Snapshot updates for the same relocation. |
| extensions/copilot/src/extension/prompts/node/agent/test/snapshots/agentPrompts-claude-sonnet-4.5/all_tools.spec.snap | Snapshot updates for the same relocation + prose tweaks. |
| extensions/copilot/src/extension/prompts/node/agent/test/snapshots/agentPrompts-claude-sonnet-4.5/all_non_edit_tools.spec.snap | Snapshot updates for the same relocation + prose tweaks. |
| extensions/copilot/src/extension/prompts/node/agent/test/snapshots/agentPrompts-claude-opus-4.6/all_tools.spec.snap | Snapshot updates: <availableDeferredTools> moved to global context. |
| extensions/copilot/src/extension/prompts/node/agent/test/snapshots/agentPrompts-claude-opus-4.6/all_non_edit_tools.spec.snap | Snapshot updates for the same relocation. |
| extensions/copilot/src/extension/prompts/node/agent/test/snapshots/agentPrompts-claude-opus-4.5/all_tools.spec.snap | Snapshot updates for the same relocation + prose tweaks. |
| extensions/copilot/src/extension/prompts/node/agent/test/snapshots/agentPrompts-claude-opus-4.5/all_non_edit_tools.spec.snap | Snapshot updates for the same relocation + prose tweaks. |
Copilot's findings
- Files reviewed: 12/12 changed files
- Comments generated: 1
alexdima
approved these changes
Apr 26, 2026
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.
Optimizes Anthropic prompt cache hit rate by moving the dynamic deferred-tool list out of the cached system prompt and into the global agent context (first user message), which is frozen across turns via
GlobalContextMessageMetadata. The instructional/guidance prose stays in the system prompt; only the dynamic tool inventory moves.Also wires up tool-search support for HiddenModelB.
cc: @kevin-m-kent