sdk-python icon indicating copy to clipboard operation
sdk-python copied to clipboard

[FEATURE] cache_messages argument for Bedrock model provider

Open pitta-bread opened this issue 1 year ago • 3 comments

Problem Statement

Just like the existing cache point arguments for system prompts and tools: cache_prompt and cache_tools. Wouldn't it be fairly easy to add in a similar option cache_messages. Looking at the Bedrock model invocation logs, I see this as a big opportunity for significant cost (and latency!) improvements. Also increases the attractiveness of Bedrock as a model provider.

Proposed Solution

When cache_tools="default" is passed to the constructor for BedrockModel the format request method, instead of currently just passing through messages as they are received, iterates through messages to ensure {"cachePoint": {"type": self.config["cache_tools"]}} snippets are added after each assistant message. Similar to the unpacking done for tools.

Use Case

When using Bedrock model provider, saves both time and money ! Even with current usage of both cache_tools and cache_prompt, still 80% of input token usage is not from the cache when it comes to the last few requests of a long-running agent. And the previous messages are mostly the same, just each request 2 messages are being added, with the rest remaining the same and perfect for caching!

Alternatives Solutions

No response

Additional Context

https://github.com/strands-agents/sdk-python/blob/df7c327b143dbef8f2e78c450e73c430580d3277/src/strands/models/bedrock.py#L190

https://docs.aws.amazon.com/bedrock/latest/userguide/prompt-caching.html

pitta-bread avatar Jul 10 '25 14:07 pitta-bread

Yes, would be nice to have. As a workaround, you can append {"cachePoint": {"type": "default"}} to the message.

macsir avatar Jul 11 '25 00:07 macsir

Yes, would be nice to have. As a workaround, you can append {"cachePoint": {"type": "default"}} to the message.

This doesn't work it seems, can you share any working sample code?

ashivadi avatar Nov 25 '25 22:11 ashivadi

Hi, we recently implemented a cache_config parameter to the bedrock model provider that does just this: https://github.com/strands-agents/sdk-python/issues/1432

Please let me know if this addresses the feature request you were looking for.

Unshure avatar Jan 27 '26 23:01 Unshure