Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/strands/models/bedrock.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,16 @@ def _cache_strategy(self) -> str | None:
model_id = self.config.get("model_id", "").lower()
if "claude" in model_id or "anthropic" in model_id:
return "anthropic"

# Application / cross-region inference profile ARNs don't contain the
# foundation model name, so the substring check above misses them.
# When the user explicitly opted into caching via cache_config, we
# optimistically enable caching for inference-profile ARNs. Currently
# only Anthropic Claude models support prompt caching on Bedrock; for
# non-caching models, the cache point is silently ignored by the API.
if model_id.startswith("arn:") and "inference-profile" in model_id:
return "anthropic"

return None

@override
Expand Down
22 changes: 21 additions & 1 deletion tests/strands/models/test_bedrock.py
Original file line number Diff line number Diff line change
Expand Up @@ -2597,7 +2597,27 @@ def test_cache_strategy_none_for_non_claude(bedrock_client):
assert model._cache_strategy is None


def test_inject_cache_point_adds_to_last_user(bedrock_client):
def test_cache_strategy_anthropic_for_inference_profile_arn(bedrock_client):
"""Test that _cache_strategy returns 'anthropic' for inference profile ARNs.

Application inference profile ARNs don't contain 'claude' or 'anthropic',
but should still support caching when the user explicitly opts in.

Reproduces: https://github.com/strands-agents/sdk-python/issues/1705
"""
# Application inference profile ARN
model = BedrockModel(
model_id="arn:aws:bedrock:us-east-1:123456789012:application-inference-profile/abc123def456"
)
assert model._cache_strategy == "anthropic"

# Cross-region inference profile ARN
model2 = BedrockModel(
model_id="arn:aws:bedrock:us-east-1:123456789012:inference-profile/us.anthropic.claude-sonnet-4-20250514-v1:0"
)
assert model2._cache_strategy == "anthropic"


"""Test that _inject_cache_point adds cache point to last user message."""
model = BedrockModel(
model_id="us.anthropic.claude-sonnet-4-20250514-v1:0", cache_config=CacheConfig(strategy="auto")
Expand Down