File tree Expand file tree Collapse file tree 2 files changed +6
-5
lines changed Expand file tree Collapse file tree 2 files changed +6
-5
lines changed Original file line number Diff line number Diff line change @@ -118,7 +118,7 @@ class AnthropicSettings(BaseModel):
118
118
Controls how caching is applied for Anthropic models when prompt_caching is enabled globally.
119
119
- "off": No caching, even if global prompt_caching is true.
120
120
- "prompt": Caches the initial system/user prompt. Useful for large, static prompts.
121
- - "auto": Caches the last user message . Default behavior if prompt_caching is true.
121
+ - "auto": Caches the last three messages . Default behavior if prompt_caching is true.
122
122
"""
123
123
124
124
model_config = ConfigDict (extra = "allow" , arbitrary_types_allowed = True )
Original file line number Diff line number Diff line change @@ -130,11 +130,12 @@ async def _anthropic_completion(
130
130
if cache_mode == "auto" :
131
131
apply_cache_to_system_prompt = True # Cache system prompt
132
132
if messages : # If there are any messages
133
- messages_to_cache_indices .append (
134
- len (messages ) - 1
135
- ) # Cache only the last message
133
+ # Cache the last 3 messages
134
+ messages_to_cache_indices .extend (
135
+ range (max (0 , len (messages ) - 3 ), len (messages ))
136
+ )
136
137
self .logger .debug (
137
- f"Auto mode: Caching system prompt (if present) and last message at index : { messages_to_cache_indices } "
138
+ f"Auto mode: Caching system prompt (if present) and last three messages at indices : { messages_to_cache_indices } "
138
139
)
139
140
elif cache_mode == "prompt" :
140
141
# Find the first user message in the fully constructed messages list
You can’t perform that action at this time.
0 commit comments