Repository navigation
Conversation
This branch has not been deployed
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.
Why
ClaudeLLM.simple_responseresends the instructions, the tools and the whole conversation on every turn, and nothing in the request asks Anthropic to cache them, so each turn pays full input price for everything the previous turn already sent. The router's Anthropic provider already places breakpoints (acceleration/internal/llm/anthropic/messages.go); the Python plugin has none.claude-sonnet-4-6, the default), each later turn reads the earlier prefix at 0.1x and writes only the new turn at 1.25x, roughly 60-80% less input-token cost on those turns (assumptions: turns arrive within the 5-minute cache lifetime, as they do in a live call; a few hundred tokens of instructions and tools; about 100-200 new tokens per exchange). Shorter conversations simply don't cache and cost the same as today.Changes
simple_responsesends the top-levelcache_control: {"type": "ephemeral"}(automatic prompt caching), which puts the breakpoint on the last block and moves it forward as the conversation grows.anthropic.AsyncAnthropicclient, so a Bedrock or Vertex client passed in gets the same request as before.create_messageand the tool follow-up requests are unchanged.Validation
ruff checkandruff format --checkonplugins/anthropic: pass.mypy plugins/anthropic/vision_agents: no issues.pytest plugins/anthropic -m "not integration": 12 passed. The newtest_each_turn_asks_to_cache_the_conversationfails without the change (nocache_controlin the request body) and passes with it. Integration tests need an API key and were not run.It may also be worth experimenting with smaller models for some of these calls, for faster and more efficient results.