Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions lib/crewai/src/crewai/llms/providers/anthropic/completion.py
Original file line number Diff line number Diff line change
Expand Up @@ -469,9 +469,15 @@ def _prepare_completion_params(
"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:
Expand All @@ -497,6 +503,9 @@ def _prepare_completion_params(
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:
Expand Down
Loading