feat: enable Anthropic prompt caching for system prompts#15
Open
samarthpatel24 wants to merge 1 commit into
Open
feat: enable Anthropic prompt caching for system prompts#15samarthpatel24 wants to merge 1 commit into
samarthpatel24 wants to merge 1 commit into
Conversation
Contributor
Author
|
@microsoft-github-policy-service agree |
2b2dbd9 to
70e51b4
Compare
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.
Problem:
The Anthropic backend re-sends the full system prompt (~5K+ tokens) on everysingle agent step at full price. On a 100-step Claude Opus run, that's ~$7.50 burned just on the same static system prompt repeating 100 times. The irony — the codebase already tracks cached_input_tokens, but it's always 0 because caching was never wired up.
Fix:
Flips on Anthropic prompt caching by sending the system prompt as a content block with cache_control ephemeral. Step 1 writes to cache (1.25x); steps 2–100 read from it (0.1x). That's roughly ~90% savings on system prompt input cost per run.
Changes:
Not affected:
Test plan: