Skip to content

Feat/prompt caching#16

Closed
Unshure wants to merge 3 commits intomainfrom
feat/prompt-caching
Closed

Feat/prompt caching#16
Unshure wants to merge 3 commits intomainfrom
feat/prompt-caching

Conversation

@Unshure
Copy link
Owner

@Unshure Unshure commented Jan 25, 2026

Summary

  • Add CacheConfig with strategy="auto" for automatic prompt caching in BedrockModel
  • Cache points are injected at the end of the last assistant message before each model call
  • Supports all Claude models on Bedrock that have prompt caching capability

Usage

from strands import Agent
from strands.models import BedrockModel, CacheConfig

model = BedrockModel(
    model_id="us.anthropic.claude-sonnet-4-5-20250929-v1:0",
    cache_config=CacheConfig(strategy="auto")
)
agent = Agent(model=model)

Test plan

  • Unit tests for cache point injection logic
  • Integration test with Claude models on Bedrock confirming cache hits

Closes strands-agents#1432

Add CacheConfig with strategy="auto" for BedrockModel to automatically
inject cache points at the end of assistant messages in multi-turn
conversations.

- Add CacheConfig dataclass in model.py with strategy field
- Add supports_caching property to check Claude model compatibility
- Implement _inject_cache_point() for automatic cache point management
- Export CacheConfig from models/__init__.py

Closes strands-agents#1432
- Add warning when cache_config enabled but model doesn't support caching
- Make supports_caching private (_supports_caching)
- Fix log formatting to follow style guide
- Clean up tests and imports
@Unshure
Copy link
Owner Author

Unshure commented Jan 25, 2026

/strands review

for block_idx, block in reversed(list(enumerate(content))):
if "cachePoint" in block:
del content[block_idx]
logger.warning(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Issue: Using logger.warning here seems too aggressive - this is expected behavior when cache_config manages cache points automatically.

Suggestion: Consider using logger.debug instead since stripping existing cache points is the intended behavior in auto mode, not a warning condition.

@github-actions
Copy link

Issue: The PR description mentions "Integration test with Claude models on Bedrock confirming cache hits" but I couldn't find any integration test in tests_integ/ for the new cache_config feature.

Suggestion: If the integration test exists, please ensure it's included in this PR. If it was tested manually, consider documenting how to verify cache hits in the PR description.

@github-actions
Copy link

Review Summary

Assessment: Comment (Minor changes requested)

Key Themes:

  • Clean, well-structured implementation of automatic prompt caching
  • Good test coverage for the new functionality
  • Minor issues: unrelated file modification and logging level choice

The implementation correctly injects cache points into cleaned_messages (not mutating original messages), handles non-Claude models gracefully, and properly strips existing cache points when in auto mode.

Minor Items:

  1. tests/strands/agent/test_agent.py has unrelated changes (extra blank lines)
  2. Consider logger.debug instead of logger.warning for stripped cache points (expected behavior in auto mode)
  3. Clarify the integration test mentioned in the PR description

Nice work on this feature! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE] Add cache_strategy="auto" for automatic prompt caching

2 participants