
    Ah                     R    S SK r S SKJr  S SKJr  S SKJr  S SKJr   " S S\5      r	g)    N)Any)
BaseMemory)field_validator)BaseChatMemoryc                       \ rS rSr% Sr\\   \S'    \" S5      \	S\\   S\\   4S j5       5       r
\" S5      \	S\\   S\\   4S j5       5       r\S\\   4S j5       rS	\\\4   S\\\4   4S
 jrS	\\\4   S\\\4   SS4S jrSS jrSrg)CombinedMemory
   z+Combining multiple memories' data together.memoriesvaluereturnc                     [        5       nU HN  nUR                  UR                  5      nU(       a  SU S3n[        U5      eU[        UR                  5      -  nMP     U$ )NzThe same variables zL are found in multiplememory object, which is not allowed by CombinedMemory.)setintersectionmemory_variables
ValueError)clsr   all_variablesvaloverlapmsgs         Q/var/www/html/shao/venv/lib/python3.13/site-packages/langchain/memory/combined.pycheck_repeated_memory_variable-CombinedMemory.check_repeated_memory_variable   sn     #&%C#001E1EFG)' 3M M  !o%S!5!566M      c                     U HA  n[        U[        5      (       d  M  UR                  b  M)  [        R                  " SU 3SS9  MC     U$ )zHCheck that if memories are of type BaseChatMemory that input keys exist.zWWhen using CombinedMemory, input keys should be so the input is known.  Was not set on    )
stacklevel)
isinstancer   	input_keywarningswarn)r   r   r   s      r   check_input_keyCombinedMemory.check_input_key#   sK     C#~..3==3H''*e-  !	  r   c                 h     / nU R                    H  nUR                  UR                  5        M      U$ )z5All the memory variables that this instance provides.)r
   extendr   )selfr   memorys      r   r   CombinedMemory.memory_variables1   s7     	:mmF##F$;$;< $  r   inputsc                     0 nU R                    HG  nUR                  U5      nUR                  5        H  u  pVXR;   a  SU S3n[        U5      eXbU'   M!     MI     U$ )z Load all vars from sub-memories.zThe variable z# is repeated in the CombinedMemory.)r
   load_memory_variablesitemsr   )r&   r)   memory_datar'   datakeyr   r   s           r   r+   $CombinedMemory.load_memory_variables=   sh    &( mmF//7D"jjl
%)#.QRC$S/)#(C 	 + $ r   outputsNc                 L    U R                    H  nUR                  X5        M     g)z0Save context from this session for every memory.N)r
   save_context)r&   r)   r1   r'   s       r   r3   CombinedMemory.save_contextL   s      mmF0 $r   c                 J    U R                    H  nUR                  5         M     g)z1Clear context from this session for every memory.N)r
   clear)r&   r'   s     r   r6   CombinedMemory.clearR   s    mmFLLN $r    )r   N)__name__
__module____qualname____firstlineno____doc__listr   __annotations__r   classmethodr   r"   propertystrr   dictr   r+   r3   r6   __static_attributes__r8   r   r   r   r   
   s    5:@Z J 
j	  !" Z 
D$4 
j9I 
  !
 	 $s) 	  	 DcN tCH~ 14S> 1DcN 1t 1r   r   )
r    typingr   langchain_core.memoryr   pydanticr   langchain.memory.chat_memoryr   r   r8   r   r   <module>rI      s"      , $ 7KZ Kr   