Skip to content

feat(provider): apply system_and_3 multi-breakpoint cache strategy for Anthropic#905

Open
sytone wants to merge 19 commits into
mainfrom
feat/anthropic-multi-breakpoint
Open

feat(provider): apply system_and_3 multi-breakpoint cache strategy for Anthropic#905
sytone wants to merge 19 commits into
mainfrom
feat/anthropic-multi-breakpoint

Conversation

@sytone

@sytone sytone commented Jun 6, 2026

Copy link
Copy Markdown
Owner

Closes #804
Part of #702

Changes

AnthropicMessageConverter.cs

  • Added ApplyMultiBreakpointCacheControl(messages, retention, baseUrl, maxBreakpoints=3) -- walks the message list backwards and stamps cache_control on up to maxBreakpoints non-system messages
  • Refactored ApplyLastUserMessageCacheControl as a 1-breakpoint delegate to the new method (backwards compat)
  • Skips messages that already have cache_control on their last block (idempotent)
  • String-content user messages are wrapped into a block list before stamping

AnthropicRequestBuilder.cs

  • Updated call site to use ApplyMultiBreakpointCacheControl (default max=3, matching system_and_3 strategy)

BotNexus.Agent.Providers.Anthropic.csproj

  • Added InternalsVisibleTo for BotNexus.Agent.Providers.Anthropic.Tests

AnthropicCacheControlTests.cs (new)

10 new tests: None no-op, 1-turn, 2-turn, 3-turn, 5-turn (max 3), string wrapping, assistant blocks, BuildCacheControl Short/Long/NonAnthropicUrl.

Tests

  • Anthropic.Tests: 108/108 pass (10 new)
  • Architecture.Tests: 167/167 pass
  • Gateway.Tests: 2164/2165 pass (1 expected skip)
  • All impacted tests passing

Merge Notes

Independent -- zero file overlap with any open PR. Safe to merge in any order.

…r Anthropic

Extends ApplyLastUserMessageCacheControl into ApplyMultiBreakpointCacheControl which
places cache-control breakpoints on the last 3 non-system messages, matching the
Anthropic system_and_3 strategy. Anthropic supports 4 cache breakpoints total; the
system prompt already consumes one, so up to 3 more are placed on recent messages.

- Add ApplyMultiBreakpointCacheControl(messages, retention, baseUrl, maxBreakpoints=3)
  walking backwards from the last message, stamping up to maxBreakpoints entries
- Preserve ApplyLastUserMessageCacheControl as a 1-breakpoint delegate for back compat
- Update AnthropicRequestBuilder to call ApplyMultiBreakpointCacheControl directly
- Add InternalsVisibleTo for test project access to internal converter methods
- 10 new tests: None no-op, 1-turn, 2-turn, 3-turn, 5-turn, string-content wrapping,
  assistant block attachment, BuildCacheControl Short/Long/NonAnthropicUrl variants

Closes #804
Part of #702
@sytone

sytone commented Jun 6, 2026

Copy link
Copy Markdown
Owner Author

PR Review -- #905

Area Status
Conventional commit title pass
Test coverage 10 tests covering multi-breakpoint placement, idempotency, retention modes, backward compat
Spec completeness Complete: multi-breakpoint cache strategy implemented per #804 spec
Merge conflicts clean

Responses to comments:

  • Re: post-refactor review -- Verified: this PR only touches Anthropic-specific files (AnthropicMessageConverter.cs, AnthropicRequestBuilder.cs). The Copilot refactor added CopilotMessagesProvider/ResponsesProvider/CompletionsProvider in separate projects. No shared interfaces or base classes were modified. The single callsite change (ApplyLastUserMessageCacheControl -> ApplyMultiBreakpointCacheControl) in AnthropicRequestBuilder.cs line 24 is still valid against current main. Safe to merge.

Notes:

  • No security bot findings. PR is architecturally isolated from Copilot changes.

  • 2026-06-08 05:24 UTC
  • 2026-06-08 02:24 UTC
  • 2026-06-08 02:03 UTC
  • 2026-06-07 23:25 UTC
  • 2026-06-07 18:04 UTC
  • 2026-06-06 22:17 UTC
  • 2026-06-06 07:02 UTC
  • 2026-06-06 06:53 UTC

Farnsworth (autonomous maintenance) -- BotNexus -- Last updated: 2026-06-08 05:24 UTC

@sytone

sytone commented Jun 7, 2026

Copy link
Copy Markdown
Owner Author

This needs a full review after the recent reactors in the providers,

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.

[Provider] Anthropic multi-breakpoint caching -- system_and_3 strategy

1 participant