Skip to content

Add portable PromptCacheOptions for provider-agnostic cache configura…#5660

Open
sobychacko wants to merge 1 commit intospring-projects:mainfrom
sobychacko:feature/core-prompt-cache-types
Open

Add portable PromptCacheOptions for provider-agnostic cache configura…#5660
sobychacko wants to merge 1 commit intospring-projects:mainfrom
sobychacko:feature/core-prompt-cache-types

Conversation

@sobychacko
Copy link
Contributor

…tion

Today, configuring prompt caching requires learning provider-specific APIs — AnthropicCacheOptions with AnthropicCacheStrategy for Anthropic, BedrockCacheOptions with BedrockCacheStrategy for Bedrock. Users who switch providers must rewrite their cache configuration, and the conceptually identical strategies (SYSTEM_ONLY, TOOLS_ONLY, etc.) live in separate, unrelated enums.

Introduce PromptCacheStrategy and PromptCacheOptions as core types on the ChatOptions interface, allowing users to configure prompt caching once using portable types that work across providers. Each supporting provider translates these to its native cache mechanism — Anthropic maps strategy, TTL, and minContentLength to AnthropicCacheOptions; Bedrock maps strategy to BedrockCacheOptions (logging that TTL is ignored since Bedrock uses a fixed 5-minute TTL).

Provider-specific cache options take precedence when both are set, preserving full backward compatibility and access to provider-specific features like Anthropic's multi-block system caching or per-message-type TTL configuration.

…tion

Today, configuring prompt caching requires learning provider-specific
APIs — AnthropicCacheOptions with AnthropicCacheStrategy for Anthropic,
BedrockCacheOptions with BedrockCacheStrategy for Bedrock. Users who
switch providers must rewrite their cache configuration, and the
conceptually identical strategies (SYSTEM_ONLY, TOOLS_ONLY, etc.) live
in separate, unrelated enums.

Introduce PromptCacheStrategy and PromptCacheOptions as core types on
the ChatOptions interface, allowing users to configure prompt caching
once using portable types that work across providers. Each supporting
provider translates these to its native cache mechanism — Anthropic maps
strategy, TTL, and minContentLength to AnthropicCacheOptions; Bedrock
maps strategy to BedrockCacheOptions (logging that TTL is ignored since
Bedrock uses a fixed 5-minute TTL).

Provider-specific cache options take precedence when both are set,
preserving full backward compatibility and access to provider-specific
features like Anthropic's multi-block system caching or per-message-type
TTL configuration.

Signed-off-by: Soby Chacko <soby.chacko@broadcom.com>
@sobychacko sobychacko added this to the 2.0.0-M4 milestone Mar 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant