| Name | Type | Description |
|---|---|---|
type | Literal['ephemeral'] | Default: 'ephemeral'The type of cache to use, only |
ttl | Literal['5m', '1h'] | Default: '5m'The time to live for the cache, only |
min_messages_to_cache | int | Default: 0 |
unsupported_model_behavior | Literal['ignore', 'warn', 'raise'] | Default: 'warn' |
Prompt Caching Middleware.
Optimizes API usage by caching conversation prefixes for Anthropic models.
Requires both langchain and langchain-anthropic packages to be installed.
The middleware tags stable agent content and passes cache_control through
model_settings:
cache_control so static system prompt content is cached.cache_control. Because
tool definitions are sent as one contiguous block, a single trailing
breakpoint caches the entire tool set across turns.model_settings: Passes cache_control to the chat model. The chat
model/provider then applies the correct message-tail and
provider-specific behavior at request time.Learn more about Anthropic prompt caching here.
The minimum number of messages until the cache is used.
The behavior to take when an unsupported model is used.
'ignore' will ignore the unsupported model and continue without
caching.
'warn' will warn the user and continue without caching.
'raise' will raise an error and stop the agent.