feat(cache): add TTL support to CachePoint for prompt caching#1660
feat(cache): add TTL support to CachePoint for prompt caching#1660kpx-dev wants to merge 3 commits intostrands-agents:mainfrom
Conversation
Add optional ttl field to CachePoint TypedDict to support AWS Bedrock's cache TTL configuration. The field accepts "5m" or "1h" values as specified in the Bedrock API. Updated BedrockModel to preserve ttl field when formatting cache point content blocks. Includes tests for TTL preservation and backward compatibility. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
| """ | ||
|
|
||
| type: str | ||
| ttl: NotRequired[Literal["5m", "1h"]] |
There was a problem hiding this comment.
Do any of the other providers support this? E.g. should anthropic have something similar?
There was a problem hiding this comment.
For AWS specific models, some supported 5m, some supports 1h: https://docs.aws.amazon.com/bedrock/latest/userguide/prompt-caching.html
Looks like Anthropic does support its ttl:
https://platform.claude.com/docs/en/build-with-claude/prompt-caching#1-hour-cache-duration
Should we also implement it in this same PR or create a new one? Happy to research it and send update.
There was a problem hiding this comment.
Should we have an integ test validating all of the values are valid for bedrock?
There was a problem hiding this comment.
Looks like we need this PR merged in before we can test ttl correctly via integ test? Do you have a better approach you suggest? I'm happy to add that now, but don't know how yet.
There was a problem hiding this comment.
Nope, you can update the integ test already, and it will run as approval wofkflow in this PR. See https://github.com/strands-agents/sdk-python/blob/main/tests_integ/models/test_model_bedrock.py
There was a problem hiding this comment.
cool I added it on my last commit. How can I test it locally? I just push and see if CI picks up.
Head branch was pushed to by a user without write access
|
FYI this PR fails label size: https://github.com/strands-agents/sdk-python/actions/runs/22110060966 . Not sure if CI needs update or label input needs update |
Description
Add optional ttl field to CachePoint TypedDict to support AWS Bedrock's cache TTL configuration. The field accepts "5m" or "1h" values as specified in the Bedrock API. Updated BedrockModel to preserve ttl field when formatting cache point content blocks. Includes tests for TTL preservation and backward compatibility.
Doc shows API supports ttl option now:
https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_CachePointBlock.html
launch announcement:
https://aws.amazon.com/about-aws/whats-new/2026/01/amazon-bedrock-one-hour-duration-prompt-caching/
more details:
https://docs.aws.amazon.com/bedrock/latest/userguide/prompt-caching.html
Related Issues
#1243
Documentation PR
Type of Change
New feature
Testing
How have you tested the change? Verify that the changes do not break functionality or introduce warnings in consuming repositories: agents-docs, agents-tools, agents-cli
hatch run prepareChecklist
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.