Skip to content

Add 'last two messages' cache breakpoint strategy for Messages API#312472

Merged
bhavyaus merged 3 commits intomainfrom
dev/bhavyau/last-two-messages-cache-breakpoints
Apr 26, 2026
Merged

Add 'last two messages' cache breakpoint strategy for Messages API#312472
bhavyaus merged 3 commits intomainfrom
dev/bhavyau/last-two-messages-cache-breakpoints

Conversation

@bhavyaus
Copy link
Copy Markdown
Collaborator

Experiment-gated alternative cache breakpoint placement for Anthropic Messages API. Places cache_control on the last two merged messages instead of heuristic-based placement.

Behind chat.anthropic.cacheBreakpoints.lastTwoMessages (default false, onExp).

Ref: microsoft/vscode-internalbacklog#7315

Copilot AI review requested due to automatic review settings April 25, 2026 01:23
Copy link
Copy Markdown
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

Adds an experiment-gated alternative cache breakpoint placement strategy for the Anthropic Messages API, shifting cache_control markers to the last two merged messages (instead of relying on prompt/heuristic breakpoint placement) while preserving the existing tools/system prefix caching behavior.

Changes:

  • Introduces addLastTwoMessagesCacheControl and wires it into createMessagesRequestBody behind chat.anthropic.cacheBreakpoints.lastTwoMessages.
  • Disables prompt-tsx + heuristic cache breakpoints in the agent prompt path when the experiment is enabled.
  • Adds the new experiment-based setting to configuration + extension settings metadata and adds unit tests for the new strategy.
Show a summary per file
File Description
extensions/copilot/src/platform/endpoint/node/messagesApi.ts Adds the new “last two messages” cache marker strategy and enables it via experiment in request body construction.
extensions/copilot/src/platform/endpoint/test/node/messagesApi.spec.ts Adds a dedicated test suite validating expected cache marker placement and limit behavior.
extensions/copilot/src/platform/configuration/common/configurationService.ts Registers the new experiment-based config key.
extensions/copilot/src/extension/intents/node/agentIntent.ts Suppresses upstream prompt/heuristic cache breakpoint insertion when the new strategy is enabled.
extensions/copilot/package.json Exposes the new setting in extension contributes/configuration.
extensions/copilot/package.nls.json Adds the localized description for the new setting.

Copilot's findings

  • Files reviewed: 6/6 changed files
  • Comments generated: 2

Comment thread extensions/copilot/src/platform/endpoint/node/messagesApi.ts
@bhavyaus bhavyaus force-pushed the dev/bhavyau/last-two-messages-cache-breakpoints branch 2 times, most recently from daebb6e to 3d438e1 Compare April 26, 2026 07:19
Adds an experiment-gated alternative to the heuristic-based cache
breakpoint placement. Places cache_control on the last two merged
Anthropic messages instead of using prompt-tsx markers and
addCacheBreakpoints. Gated behind AnthropicCacheBreakpointsLastTwoMessages
(default false, onExp).
@bhavyaus bhavyaus force-pushed the dev/bhavyau/last-two-messages-cache-breakpoints branch from 3d438e1 to e487cd3 Compare April 26, 2026 16:08
Copy link
Copy Markdown
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.

Copilot's findings

  • Files reviewed: 6/6 changed files
  • Comments generated: 1

Comment thread extensions/copilot/src/extension/intents/node/agentIntent.ts
@bhavyaus bhavyaus marked this pull request as ready for review April 26, 2026 16:45
@bhavyaus bhavyaus enabled auto-merge (squash) April 26, 2026 16:45
@bhavyaus bhavyaus merged commit d603ad4 into main Apr 26, 2026
30 checks passed
@bhavyaus bhavyaus deleted the dev/bhavyau/last-two-messages-cache-breakpoints branch April 26, 2026 16:57
@vs-code-engineering vs-code-engineering Bot added this to the 1.118.0 milestone Apr 26, 2026
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.

3 participants