[FEATURE] cache_messages argument for Bedrock model provider
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
Yes, would be nice to have. As a workaround, you can append {"cachePoint": {"type": "default"}} to the message.
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?
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.