feat(bedrock): add automatic prompt caching support#1438
feat(bedrock): add automatic prompt caching support#1438Unshure merged 4 commits intostrands-agents:mainfrom
Conversation
00a7eca to
92e2a59
Compare
|
This is an important change, thanks for this. |
🎯 Review - Automatic Prompt CachingExcellent implementation of automatic prompt caching for Bedrock! This addresses #1432 nicely and will provide significant performance and cost benefits for multi-turn conversations. What I Really Like ✅
Minor Suggestions 💡1. Cache Point Detection Could Be More ExplicitIn 2. Model Support DetectionThe 3. Integration Test ClarityThe integration tests are great! One suggestion - add a comment explaining the cache hit verification: # After second call, verify cache hit (cache_read_input_tokens > 0)
# This confirms the cache point strategy is working
assert result.metadata["converse_metrics"]["cache_read_input_tokens"] > 0Questions for Discussion 🤔
CI StatusI see CI is still pending. Once it passes, this looks ready for maintainer review! Overall AssessmentThis is a high-quality PR that will be valuable for the community. The automatic cache management removes complexity from users while providing real performance benefits. Great work, @kevmyung! 🎉 🦆 🤖 This is an experimental AI agent response from the Strands team, powered by Strands Agents. We're exploring how AI agents can help with community support and development. Your feedback helps us improve! If you'd prefer human assistance, please let us know. |
Unshure
left a comment
There was a problem hiding this comment.
This looks good to me, just need to rebase and address the nit.
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
- Inject into cleaned_messages instead of original messages to avoid mutating agent.messages - Use reversed iteration for safe in-place deletion - Consolidate redundant cache point tests
9e23a68 to
2a498bc
Compare
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Add test to verify cachePoint blocks are formatted as standalone blocks and not merged into previous content blocks. This confirms the fix from PR strands-agents#1438 works correctly for the scenario reported in Issue strands-agents#1219. Closes strands-agents#1219
Summary
CacheConfigwithstrategy="auto"for automatic prompt caching inBedrockModelUsage
Test plan
Closes #1432