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):
118118    Controls how caching is applied for Anthropic models when prompt_caching is enabled globally. 
119119    - "off": No caching, even if global prompt_caching is true. 
120120    - "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. 
122122    """ 
123123
124124    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(
130130            if  cache_mode  ==  "auto" :
131131                apply_cache_to_system_prompt  =  True   # Cache system prompt 
132132                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+                     )
136137                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 }  " 
138139                )
139140            elif  cache_mode  ==  "prompt" :
140141                # Find the first user message in the fully constructed messages list 
    
 
   
 
     
   
   
          
     
  
    
     
 
    
      
     
 
     
    You can’t perform that action at this time.
  
 
    
  
     
    
      
        
     
 
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments