M21: Token optimization -- prompt caching, local summarization, context pruning#341
Merged
M21: Token optimization -- prompt caching, local summarization, context pruning#341
Conversation
Split system prompt into structured content blocks with cache_control markers. Add anthropic-beta: prompt-caching-2024-07-31 header to all requests. Parse API usage response for cache hit tracking. Closes #337
Add last_cache_usage() to LlmProvider trait for reading cache hit statistics. ClaudeProvider stores cache_creation and cache_read token counts from each response. Agent records these into MetricsSnapshot after each LLM call. Closes #340
Codecov Report❌ Patch coverage is @@ Coverage Diff @@
## main #341 +/- ##
==========================================
- Coverage 79.35% 79.23% -0.13%
==========================================
Files 99 99
Lines 25076 25406 +330
==========================================
+ Hits 19900 20131 +231
- Misses 5176 5275 +99
🚀 New features to boost your workflow:
|
Show cache write/read token counts conditionally when the active provider reports non-zero cache usage.
…zation Ensure tool_use blocks are only emitted in assistant messages and tool_result blocks only in user messages. Misplaced parts are downgraded to text blocks to prevent Anthropic API 400 errors.
Orchestrator was missing last_cache_usage() delegation, causing cache metrics to never reach MetricsSnapshot when using provider=orchestrator.
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
anthropic-betaheader (M21-P1: Anthropic prompt caching for ClaudeProvider #337)Estimated input token reduction: 80-90% from prompt caching alone.
Test plan
Closes #336, closes #337, closes #338, closes #339, closes #340