From 2832834367fec55b817774d475443faa1c02a597 Mon Sep 17 00:00:00 2001 From: lorenzejay Date: Thu, 26 Mar 2026 15:40:27 -0700 Subject: [PATCH] feat: enhance system message handling with prompt caching in AnthropicCompletion --- .../crewai/llms/providers/anthropic/completion.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/crewai/src/crewai/llms/providers/anthropic/completion.py b/lib/crewai/src/crewai/llms/providers/anthropic/completion.py index 077c31589..32b6b53bd 100644 --- a/lib/crewai/src/crewai/llms/providers/anthropic/completion.py +++ b/lib/crewai/src/crewai/llms/providers/anthropic/completion.py @@ -469,9 +469,15 @@ class AnthropicCompletion(BaseLLM): "stream": self.stream, } - # Add system message if present + # Add system message if present, with prompt caching if system_message: - params["system"] = system_message + params["system"] = [ + { + "type": "text", + "text": system_message, + "cache_control": {"type": "ephemeral"}, + } + ] # Add optional parameters if set if self.temperature is not None: @@ -497,6 +503,10 @@ class AnthropicCompletion(BaseLLM): if self.tool_search is not None and len(regular_tools) >= 2: converted_tools = self._apply_tool_search(converted_tools) + + if converted_tools: + converted_tools[-1]["cache_control"] = {"type": "ephemeral"} + params["tools"] = converted_tools if available_functions and len(regular_tools) == 1: