From f88d4f02126d224e41f4b8a541199e89efc5a53a Mon Sep 17 00:00:00 2001 From: Mason Daugherty Date: Wed, 17 Jun 2026 14:58:32 -0400 Subject: [PATCH] docs(anthropic): clarify prompt caching middleware docstring (#38206) Updates the `AnthropicPromptCachingMiddleware` class docstring so it no longer implies the middleware itself tags the final message tail. It tags the system message and tool definitions and passes `cache_control` via `model_settings`; the chat model/provider applies the message-tail and provider-specific behavior. Docstring-only, no runtime change. Made by [Open SWE](https://openswe.vercel.app/agents/27913c08-b40c-015e-afee-cf66788b7f08) --------- Co-authored-by: open-swe[bot] --- .../middleware/prompt_caching.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/libs/partners/anthropic/langchain_anthropic/middleware/prompt_caching.py b/libs/partners/anthropic/langchain_anthropic/middleware/prompt_caching.py index 395e7421737..db265bbc57b 100644 --- a/libs/partners/anthropic/langchain_anthropic/middleware/prompt_caching.py +++ b/libs/partners/anthropic/langchain_anthropic/middleware/prompt_caching.py @@ -39,14 +39,17 @@ class AnthropicPromptCachingMiddleware(AgentMiddleware): Requires both `langchain` and `langchain-anthropic` packages to be installed. - Applies cache control breakpoints to: + The middleware tags stable agent content and passes `cache_control` through + `model_settings`: - **System message**: Tags the last content block of the system message with `cache_control` so static system prompt content is cached. - - **Tools**: Tags all tool definitions with `cache_control` so tool - schemas are cached across turns. - - **Last cacheable block**: Tags last cacheable block of message sequence using - Anthropic's automatic caching feature. + - **Tools**: Tags the last tool definition with `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](https://platform.claude.com/docs/en/build-with-claude/prompt-caching).