Skip to content

fix(anthropic): keep cache breakpoints within Anthropic's limit of 4 with deferred tools#3692

Merged
dgageot merged 2 commits into
docker:mainfrom
dgageot:fix-anthropic-cache-breakpoints
Jul 16, 2026
Merged

fix(anthropic): keep cache breakpoints within Anthropic's limit of 4 with deferred tools#3692
dgageot merged 2 commits into
docker:mainfrom
dgageot:fix-anthropic-cache-breakpoints

Conversation

@dgageot

@dgageot dgageot commented Jul 16, 2026

Copy link
Copy Markdown
Member

Commit 83956fc added a cache_control breakpoint on the tool list when deferred tools are present. Combined with the existing breakpoints applied to system blocks (up to 2) and the last conversation messages (up to 2), requests could exceed Anthropic's hard limit of 4 cache_control blocks and return API errors at runtime.

applyMessageCacheControl and applyBetaMessageCacheControl now accept a breakpoint budget. When deferred tools are in the request, only the last message receives a breakpoint instead of the last two, keeping the total at or below 4. The non-deferred path is unchanged: 2 system + 2 messages = 4. With deferred tools the worst case is 2 system + 1 tools + 1 message = 4. Cache efficiency is preserved because Anthropic's caching layer automatically looks back roughly 20 blocks for prior hits, so a single message breakpoint still gets cache hits on subsequent turns.

New tests assert that a worst-case request — two system breakpoints, deferred tools, and a multi-turn conversation — stays within the 4-block limit for both the standard and beta converters, and that the message breakpoint count drops from two to one when deferred tools are present.

dgageot added 2 commits July 16, 2026 17:42
Deferred tools add a cache_control breakpoint on the tool list, which
could push the total past Anthropic's limit of 4. Reduce message
breakpoints from 2 to 1 when deferred tools are present.

Assisted-By: Claude
Regression test covering the worst-case scenario (2 system breakpoints,
deferred tools, long conversation) for both standard and beta converters.

Assisted-By: Claude
@dgageot
dgageot requested a review from a team as a code owner July 16, 2026 16:36

@docker-agent docker-agent 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.

Assessment: 🟢 APPROVE

@aheritier aheritier added area/providers/anthropic For features/issues/fixes related to the usage of Anthropic models kind/fix PR fixes a bug (maps to fix:). Use on PRs only. labels Jul 16, 2026
@dgageot
dgageot merged commit c253477 into docker:main Jul 16, 2026
10 of 11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/providers/anthropic For features/issues/fixes related to the usage of Anthropic models kind/fix PR fixes a bug (maps to fix:). Use on PRs only.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants