fix: recognize Bedrock inference profile ARNs for prompt caching#1883
Open
giulio-leone wants to merge 1 commit intostrands-agents:mainfrom
Open
fix: recognize Bedrock inference profile ARNs for prompt caching#1883giulio-leone wants to merge 1 commit intostrands-agents:mainfrom
giulio-leone wants to merge 1 commit intostrands-agents:mainfrom
Conversation
The _cache_strategy property only checked for 'claude' or 'anthropic' substrings in the model_id. This works for system inference profile IDs (e.g. us.anthropic.claude-haiku-4-5-20251001-v1:0) but fails for application inference profile ARNs which have the form: arn:aws:bedrock:<region>:<account>:application-inference-profile/<id> These ARNs don't contain 'claude' or 'anthropic', so automatic caching was silently disabled even when the user explicitly set cache_config=CacheConfig(strategy='auto'). The fix detects ARNs that contain 'inference-profile' and optimistically enables caching. Currently only Anthropic Claude models support prompt caching on Bedrock; for non-caching models the cache point is silently ignored by the Converse API. Closes strands-agents#1705
4b7c9a2 to
aebdfe0
Compare
Contributor
Author
|
Friendly ping — adds recognition of Bedrock inference profile ARNs for prompt caching, which currently only matches standard model ARNs. |
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.
Issue
Closes #1705
Problem
_cache_strategyonly checked for'claude'or'anthropic'substrings in themodel_id:This works for system inference profile IDs (e.g.
us.anthropic.claude-haiku-4-5-20251001-v1:0) but fails for application inference profile ARNs which have the form:These ARNs don't contain 'claude' or 'anthropic', so automatic caching was silently disabled with a warning:
Solution
Added detection for inference profile ARNs: when
model_idstarts witharn:and containsinference-profile, optimistically enable caching.Design Rationale
GetInferenceProfileto resolve the underlying model, which would add latency, require additional IAM permissions (bedrock:GetInferenceProfile), and create a network dependency on everyconversecall.application-inference-profileandinference-profile(cross-region) ARNs.Testing
test_cache_strategy_anthropic_for_inference_profile_arn: Tests both application and cross-region inference profile ARNsChanges
src/strands/models/bedrock.py: Extended_cache_strategyto detect inference profile ARNstests/strands/models/test_bedrock.py: Added test for ARN-based cache strategy detection