Add: Dynamic prompt cache breakpoints for Anthropic prefix caching#621
Merged
Add: Dynamic prompt cache breakpoints for Anthropic prefix caching#621
Conversation
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…ching Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
BP1 on system message covers tools+system (prefix order: tools→system→messages). BP2-4 distributed every ~20 content blocks across conversation messages, working backwards from the last message. Removes redundant tool-level BP. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Replace explicit applyCacheBreakpoints() with Anthropic's request-level
automatic caching (cache_control: {type: "ephemeral"}). Auto-places
breakpoints on last system, tool, and message blocks optimally.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.
Summary
applyCacheBreakpoints()pure function that places optimal cache breakpoints before each LLM callgeneratingToolCallLogic— the only LLM call site in the state machineproviders.test.ts,continue.test.ts)Impact: On multi-turn Anthropic runs, Turn 2+ gets prefix cache hits on the entire previous conversation. Verified with 3-turn test: Turn 2 cached 1,164 tokens (40.8%), Turn 3 cached 2,328 tokens (36.2%).
No changes needed for OpenAI (automatic prefix caching) or Google Gemini (automatic implicit caching).
Test plan
applyCacheBreakpoints()— empty array, single message, multi-message, instruction preservation, stale flag clearing, immutability, reference reuse, multi-turn simulationproviders.test.ts: cache token metric fields verified across all 3 providerscontinue.test.ts: cache usage flows through multi-turn conversationsclaude-sonnet-4-5confirmscachedInputTokens > 0on Turn 2+🤖 Generated with Claude Code