feat: Add Anthropic implicit caching support#140
Merged
Conversation
- Implement `implicit_caching` option for Anthropic provider - Set smart defaults: enabled for single-call, disabled for fan-out - Update ProviderCapabilities to enforce caching support - Add runtime errors for unsupported providers - Document caching approaches in docs (caching.md, portable-code.md, etc.) - Add test coverage for new caching behavior
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
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
Adds support for Anthropic's implicit caching mechanism, allowing caching of prompt prefixes in generated responses. Introduces a new
implicit_cachingoption with smart defaults (enabled for single calls, disabled for fan-out) to optimize costs, while remaining capability-transparent.Related issue
None
Test plan
Added unit and provider characterization tests in
tests/test_pipeline.pyandtests/test_providers.pycovering:implicit_cachingon.implicit_cachingoff.implicit_caching=Truerequests correctly failing with aConfigurationErroron unsupported providers (e.g. Gemini).cache_control={"type": "ephemeral"}.just checkpasses with all the tests successfully passing.Notes
Anthropic caching applies a 1.25x premium on cache writes, so the default for
run_manyfan-outs is disabled to prevent runaway costs on concurrent requests that would simultaneously write the same prefix.make checkpasses