
    D_i              
         S r SSKJr  SSKrSSKJrJr  \(       a6  SSKJr  SSK	J
r
  SSKJr  SSKJr  SS	KJrJr  SS
KJr  SSKJr  SSKJrJrJr  \R4                  " \5      r " S S5      r " S S5      r " S S5      r " S S5      r  " S S5      r! " S S5      r" " S S\\\ \\!\"5      r# " S S\#5      r$ " S S\!5      r%\&\#   \%-  S-  r'g)$Base callback handler for LangChain.    )annotationsN)TYPE_CHECKINGAny)Sequence)UUID)RetryCallState)Self)AgentActionAgentFinish)Document)BaseMessage)ChatGenerationChunkGenerationChunk	LLMResultc                  `    \ rS rSrSrSS.         SS jjrSS.         S	S jjrSrg)
RetrieverManagerMixin   zMixin for Retriever callbacks.Nparent_run_idc                   g)zRun when Retriever errors.

Args:
    error: The error that occurred.
    run_id: The run ID. This is the ID of the current run.
    parent_run_id: The parent run ID. This is the ID of the parent run.
    **kwargs: Additional keyword arguments.
N selferrorrun_idr   kwargss        W/home/james-whalen/.local/lib/python3.13/site-packages/langchain_core/callbacks/base.pyon_retriever_error(RetrieverManagerMixin.on_retriever_error           c                   g)zRun when Retriever ends running.

Args:
    documents: The documents retrieved.
    run_id: The run ID. This is the ID of the current run.
    parent_run_id: The parent run ID. This is the ID of the parent run.
    **kwargs: Additional keyword arguments.
Nr   )r   	documentsr   r   r   s        r   on_retriever_end&RetrieverManagerMixin.on_retriever_end+   r!   r"   r   
r   BaseExceptionr   r   r   UUID | Noner   r   returnr   )
r$   Sequence[Document]r   r   r   r)   r   r   r*   r   )__name__
__module____qualname____firstlineno____doc__r   r%   __static_attributes__r   r"   r   r   r      s~    ( &* 	
 #  
, &*% 	
 #  
 r"   r   c                      \ rS rSrSrSSS.           S
S jjrSS.         SS jjrSS.         SS jjrS	rg)LLMManagerMixin=   zMixin for LLM callbacks.N)chunkr   c                   g)a  Run on new output token. Only available when streaming is enabled.

For both chat models and non-chat models (legacy LLMs).

Args:
    token: The new token.
    chunk: The new generated chunk, containing content and other information.
    run_id: The run ID. This is the ID of the current run.
    parent_run_id: The parent run ID. This is the ID of the parent run.
    **kwargs: Additional keyword arguments.
Nr   )r   tokenr5   r   r   r   s         r   on_llm_new_token LLMManagerMixin.on_llm_new_token@   r!   r"   r   c                   g)a  Run when LLM ends running.

Args:
    response: The response which was generated.
    run_id: The run ID. This is the ID of the current run.
    parent_run_id: The parent run ID. This is the ID of the parent run.
    **kwargs: Additional keyword arguments.
Nr   )r   responser   r   r   s        r   
on_llm_endLLMManagerMixin.on_llm_endU   r!   r"   c                   g)zRun when LLM errors.

Args:
    error: The error that occurred.
    run_id: The run ID. This is the ID of the current run.
    parent_run_id: The parent run ID. This is the ID of the parent run.
    **kwargs: Additional keyword arguments.
Nr   r   s        r   on_llm_errorLLMManagerMixin.on_llm_errorf   r!   r"   r   )r7   strr5   ,GenerationChunk | ChatGenerationChunk | Noner   r   r   r)   r   r   r*   r   )
r;   r   r   r   r   r)   r   r   r*   r   r'   )	r,   r-   r.   r/   r0   r8   r<   r?   r1   r   r"   r   r3   r3   =   s    " ?C%) <	
  #  
4 &* 	
 #  
, &* 	
 #  
 r"   r3   c                      \ rS rSrSrSS.         S
S jjrSS.         SS jjrSS.         SS jjrSS.         SS jjrS	r	g)ChainManagerMixinx   zMixin for chain callbacks.Nr   c                   g)zRun when chain ends running.

Args:
    outputs: The outputs of the chain.
    run_id: The run ID. This is the ID of the current run.
    parent_run_id: The parent run ID. This is the ID of the parent run.
    **kwargs: Additional keyword arguments.
Nr   )r   outputsr   r   r   s        r   on_chain_endChainManagerMixin.on_chain_end{   r!   r"   c                   g)zRun when chain errors.

Args:
    error: The error that occurred.
    run_id: The run ID. This is the ID of the current run.
    parent_run_id: The parent run ID. This is the ID of the parent run.
    **kwargs: Additional keyword arguments.
Nr   r   s        r   on_chain_error ChainManagerMixin.on_chain_error   r!   r"   c                   g)zRun on agent action.

Args:
    action: The agent action.
    run_id: The run ID. This is the ID of the current run.
    parent_run_id: The parent run ID. This is the ID of the parent run.
    **kwargs: Additional keyword arguments.
Nr   )r   actionr   r   r   s        r   on_agent_action!ChainManagerMixin.on_agent_action   r!   r"   c                   g)zRun on the agent end.

Args:
    finish: The agent finish.
    run_id: The run ID. This is the ID of the current run.
    parent_run_id: The parent run ID. This is the ID of the parent run.
    **kwargs: Additional keyword arguments.
Nr   )r   finishr   r   r   s        r   on_agent_finish!ChainManagerMixin.on_agent_finish   r!   r"   r   )
rG   dict[str, Any]r   r   r   r)   r   r   r*   r   r'   )
rN   r   r   r   r   r)   r   r   r*   r   )
rR   r   r   r   r   r)   r   r   r*   r   )
r,   r-   r.   r/   r0   rH   rK   rO   rS   r1   r   r"   r   rD   rD   x   s    $ &* 	
 #  
, &* 	
 #  
, &* 	
 #  
, &* 	
 #  
 r"   rD   c                  `    \ rS rSrSrSS.         SS jjrSS.         S	S jjrSrg)
ToolManagerMixin   zMixin for tool callbacks.Nr   c                   g)zRun when the tool ends running.

Args:
    output: The output of the tool.
    run_id: The run ID. This is the ID of the current run.
    parent_run_id: The parent run ID. This is the ID of the parent run.
    **kwargs: Additional keyword arguments.
Nr   )r   outputr   r   r   s        r   on_tool_endToolManagerMixin.on_tool_end   r!   r"   c                   g)zRun when tool errors.

Args:
    error: The error that occurred.
    run_id: The run ID. This is the ID of the current run.
    parent_run_id: The parent run ID. This is the ID of the parent run.
    **kwargs: Additional keyword arguments.
Nr   r   s        r   on_tool_errorToolManagerMixin.on_tool_error   r!   r"   r   )
rZ   r   r   r   r   r)   r   r   r*   r   r'   )r,   r-   r.   r/   r0   r[   r^   r1   r   r"   r   rW   rW      s~    # &* 	
 #  
, &* 	
 #  
 r"   rW   c                  "   \ rS rSrSrSSSS.               SS jjrSSSS.               SS jjrSSSS.               SS jjrSSSS.               SS jjrSSSSS	.                 SS
 jjr	Sr
g)CallbackManagerMixin   zMixin for callback manager.Nr   tagsmetadatac                   g)a  Run when LLM starts running.

!!! warning
    This method is called for non-chat models (regular LLMs). If you're
    implementing a handler for a chat model, you should use
    `on_chat_model_start` instead.

Args:
    serialized: The serialized LLM.
    prompts: The prompts.
    run_id: The run ID. This is the ID of the current run.
    parent_run_id: The parent run ID. This is the ID of the parent run.
    tags: The tags.
    metadata: The metadata.
    **kwargs: Additional keyword arguments.
Nr   r   
serializedpromptsr   r   rd   re   r   s           r   on_llm_start!CallbackManagerMixin.on_llm_start   r!   r"   c               J    U R                   R                   S3n[        U5      ea  Run when a chat model starts running.

!!! warning
    This method is called for chat models. If you're implementing a handler for
    a non-chat model, you should use `on_llm_start` instead.

Args:
    serialized: The serialized chat model.
    messages: The messages.
    run_id: The run ID. This is the ID of the current run.
    parent_run_id: The parent run ID. This is the ID of the parent run.
    tags: The tags.
    metadata: The metadata.
    **kwargs: Additional keyword arguments.
z) does not implement `on_chat_model_start`	__class__r,   NotImplementedError	r   rh   messagesr   r   rd   re   r   msgs	            r   on_chat_model_start(CallbackManagerMixin.on_chat_model_start  s'    8 (())RS!#&&r"   c                   g)aM  Run when the Retriever starts running.

Args:
    serialized: The serialized Retriever.
    query: The query.
    run_id: The run ID. This is the ID of the current run.
    parent_run_id: The parent run ID. This is the ID of the parent run.
    tags: The tags.
    metadata: The metadata.
    **kwargs: Additional keyword arguments.
Nr   r   rh   queryr   r   rd   re   r   s           r   on_retriever_start'CallbackManagerMixin.on_retriever_start$  r!   r"   c                   gaE  Run when a chain starts running.

Args:
    serialized: The serialized chain.
    inputs: The inputs.
    run_id: The run ID. This is the ID of the current run.
    parent_run_id: The parent run ID. This is the ID of the parent run.
    tags: The tags.
    metadata: The metadata.
    **kwargs: Additional keyword arguments.
Nr   r   rh   inputsr   r   rd   re   r   s           r   on_chain_start#CallbackManagerMixin.on_chain_start;  r!   r"   r   rd   re   r~   c                   g)ag  Run when the tool starts running.

Args:
    serialized: The serialized chain.
    input_str: The input string.
    run_id: The run ID. This is the ID of the current run.
    parent_run_id: The parent run ID. This is the ID of the parent run.
    tags: The tags.
    metadata: The metadata.
    inputs: The inputs.
    **kwargs: Additional keyword arguments.
Nr   	r   rh   	input_strr   r   rd   re   r~   r   s	            r   on_tool_start"CallbackManagerMixin.on_tool_startR  r!   r"   r   )rh   rU   ri   	list[str]r   r   r   r)   rd   list[str] | Nonere   dict[str, Any] | Noner   r   r*   r   rh   rU   rr   zlist[list[BaseMessage]]r   r   r   r)   rd   r   re   r   r   r   r*   r   )rh   rU   rx   rA   r   r   r   r)   rd   r   re   r   r   r   r*   r   )rh   rU   r~   rU   r   r   r   r)   rd   r   re   r   r   r   r*   r   )rh   rU   r   rA   r   r   r   r)   rd   r   re   r   r~   r   r   r   r*   r   )r,   r-   r.   r/   r0   rj   rt   ry   r   r   r1   r   r"   r   ra   ra      s   % &*!%*." 
  #  (  
D &*!%*.'"' *'
 ' #' ' (' ' 
'J &*!%*." 
  #  (  
: &*!%*." 
  #  (  
: &*!%*.(," 
  #  ( &  
 r"   ra   c                      \ rS rSrSrSS.         S
S jjrSS.         SS jjrSSS.             SS jjrS	rg)RunManagerMixinil  zMixin for run manager.Nr   c                   g)zRun on an arbitrary text.

Args:
    text: The text.
    run_id: The run ID. This is the ID of the current run.
    parent_run_id: The parent run ID. This is the ID of the parent run.
    **kwargs: Additional keyword arguments.
Nr   )r   textr   r   r   s        r   on_textRunManagerMixin.on_texto  r!   r"   c                   gzRun on a retry event.

Args:
    retry_state: The retry state.
    run_id: The run ID. This is the ID of the current run.
    parent_run_id: The parent run ID. This is the ID of the parent run.
    **kwargs: Additional keyword arguments.
Nr   r   retry_stater   r   r   s        r   on_retryRunManagerMixin.on_retry  r!   r"   rd   re   c                   g)a  Override to define a handler for a custom event.

Args:
    name: The name of the custom event.
    data: The data for the custom event. Format will match
        the format specified by the user.
    run_id: The ID of the run.
    tags: The tags associated with the custom event
        (includes inherited tags).
    metadata: The metadata associated with the custom event
        (includes inherited metadata).
Nr   r   namedatar   rd   re   r   s          r   on_custom_eventRunManagerMixin.on_custom_event  r!   r"   r   )
r   rA   r   r   r   r)   r   r   r*   r   
r   r	   r   r   r   r)   r   r   r*   r   )r   rA   r   r   r   r   rd   r   re   r   r   r   r*   r   )	r,   r-   r.   r/   r0   r   r   r   r1   r   r"   r   r   r   l  s      &* 	
 #  
, &*# 	
 #  
. "&*. 
   (  
 r"   r   c                      \ rS rSr% SrSrS\S'    SrS\S'    \SS j5       r	\SS j5       r
\SS	 j5       r\SS
 j5       r\SS j5       r\SS j5       r\SS j5       rSrg)BaseCallbackHandleri  r   Fboolraise_error
run_inlinec                    g)z Whether to ignore LLM callbacks.Fr   r   s    r   
ignore_llmBaseCallbackHandler.ignore_llm       r"   c                    g)z"Whether to ignore retry callbacks.Fr   r   s    r   ignore_retry BaseCallbackHandler.ignore_retry  r   r"   c                    g)z"Whether to ignore chain callbacks.Fr   r   s    r   ignore_chain BaseCallbackHandler.ignore_chain  r   r"   c                    g)z"Whether to ignore agent callbacks.Fr   r   s    r   ignore_agent BaseCallbackHandler.ignore_agent  r   r"   c                    g)z&Whether to ignore retriever callbacks.Fr   r   s    r   ignore_retriever$BaseCallbackHandler.ignore_retriever  r   r"   c                    g)z'Whether to ignore chat model callbacks.Fr   r   s    r   ignore_chat_model%BaseCallbackHandler.ignore_chat_model  r   r"   c                    g)zIgnore custom event.Fr   r   s    r   ignore_custom_event'BaseCallbackHandler.ignore_custom_event  r   r"   r   Nr*   r   )r,   r-   r.   r/   r0   r   __annotations__r   propertyr   r   r   r   r   r   r   r1   r   r"   r   r   r     s     /K;J-             r"   r   c                  r   \ rS rSrSrSSSS.               SS jjrSSSS.               SS jjrSSSS.             S S jjrSSS	.           S!S
 jjrSSS	.           S"S jjr	SSSS.               S#S jjr
SSS	.           S$S jjrSSS	.           S"S jjrSSSSS.                 S%S jjrSSS	.           S&S jjrSSS	.           S"S jjrSSS	.           S'S jjrSS.         S(S jjrSSS	.           S)S jjrSSS	.           S*S jjrSSSS.               S+S jjrSSS	.           S,S jjrSSS	.           S"S jjrSSS.             S-S jjrSrg).AsyncCallbackHandleri  z%Async callback handler for LangChain.Nrc   c                  #    g7f)a  Run when the model starts running.

!!! warning
    This method is called for non-chat models (regular LLMs). If you're
    implementing a handler for a chat model, you should use
    `on_chat_model_start` instead.

Args:
    serialized: The serialized LLM.
    prompts: The prompts.
    run_id: The run ID. This is the ID of the current run.
    parent_run_id: The parent run ID. This is the ID of the parent run.
    tags: The tags.
    metadata: The metadata.
    **kwargs: Additional keyword arguments.
Nr   rg   s           r   rj   !AsyncCallbackHandler.on_llm_start          c               R   #    U R                   R                   S3n[        U5      e7frm   rn   rq   s	            r   rt   (AsyncCallbackHandler.on_chat_model_start  s*     8 (())RS!#&&s   %')r5   r   rd   c                  #    g7f)a  Run on new output token. Only available when streaming is enabled.

For both chat models and non-chat models (legacy LLMs).

Args:
    token: The new token.
    chunk: The new generated chunk, containing content and other information.
    run_id: The run ID. This is the ID of the current run.
    parent_run_id: The parent run ID. This is the ID of the parent run.
    tags: The tags.
    **kwargs: Additional keyword arguments.
Nr   )r   r7   r5   r   r   rd   r   s          r   r8   %AsyncCallbackHandler.on_llm_new_token  r   r   )r   rd   c                  #    g7f)a  Run when the model ends running.

Args:
    response: The response which was generated.
    run_id: The run ID. This is the ID of the current run.
    parent_run_id: The parent run ID. This is the ID of the parent run.
    tags: The tags.
    **kwargs: Additional keyword arguments.
Nr   )r   r;   r   r   rd   r   s         r   r<   AsyncCallbackHandler.on_llm_end2  r   r   c                  #    g7f)ak  Run when LLM errors.

Args:
    error: The error that occurred.
    run_id: The run ID. This is the ID of the current run.
    parent_run_id: The parent run ID. This is the ID of the parent run.
    tags: The tags.
    **kwargs: Additional keyword arguments.
        - response (LLMResult): The response which was generated before
            the error occurred.
Nr   r   r   r   r   rd   r   s         r   r?   !AsyncCallbackHandler.on_llm_errorE  r   r   c                  #    g7fr|   r   r}   s           r   r   #AsyncCallbackHandler.on_chain_startZ  r   r   c                  #    g7f)a  Run when a chain ends running.

Args:
    outputs: The outputs of the chain.
    run_id: The run ID. This is the ID of the current run.
    parent_run_id: The parent run ID. This is the ID of the parent run.
    tags: The tags.
    **kwargs: Additional keyword arguments.
Nr   )r   rG   r   r   rd   r   s         r   rH   !AsyncCallbackHandler.on_chain_endq  r   r   c                  #    g7f)a  Run when chain errors.

Args:
    error: The error that occurred.
    run_id: The run ID. This is the ID of the current run.
    parent_run_id: The parent run ID. This is the ID of the parent run.
    tags: The tags.
    **kwargs: Additional keyword arguments.
Nr   r   s         r   rK   #AsyncCallbackHandler.on_chain_error  r   r   r   c                  #    g7f)af  Run when the tool starts running.

Args:
    serialized: The serialized tool.
    input_str: The input string.
    run_id: The run ID. This is the ID of the current run.
    parent_run_id: The parent run ID. This is the ID of the parent run.
    tags: The tags.
    metadata: The metadata.
    inputs: The inputs.
    **kwargs: Additional keyword arguments.
Nr   r   s	            r   r   "AsyncCallbackHandler.on_tool_start  r   r   c                  #    g7f)a  Run when the tool ends running.

Args:
    output: The output of the tool.
    run_id: The run ID. This is the ID of the current run.
    parent_run_id: The parent run ID. This is the ID of the parent run.
    tags: The tags.
    **kwargs: Additional keyword arguments.
Nr   )r   rZ   r   r   rd   r   s         r   r[    AsyncCallbackHandler.on_tool_end  r   r   c                  #    g7f)a  Run when tool errors.

Args:
    error: The error that occurred.
    run_id: The run ID. This is the ID of the current run.
    parent_run_id: The parent run ID. This is the ID of the parent run.
    tags: The tags.
    **kwargs: Additional keyword arguments.
Nr   r   s         r   r^   "AsyncCallbackHandler.on_tool_error  r   r   c                  #    g7f)zRun on an arbitrary text.

Args:
    text: The text.
    run_id: The run ID. This is the ID of the current run.
    parent_run_id: The parent run ID. This is the ID of the parent run.
    tags: The tags.
    **kwargs: Additional keyword arguments.
Nr   )r   r   r   r   rd   r   s         r   r   AsyncCallbackHandler.on_text  r   r   r   c                  #    g7fr   r   r   s        r   r   AsyncCallbackHandler.on_retry  r   r   c                  #    g7f)zRun on agent action.

Args:
    action: The agent action.
    run_id: The run ID. This is the ID of the current run.
    parent_run_id: The parent run ID. This is the ID of the parent run.
    tags: The tags.
    **kwargs: Additional keyword arguments.
Nr   )r   rN   r   r   rd   r   s         r   rO   $AsyncCallbackHandler.on_agent_action  r   r   c                  #    g7f)zRun on the agent end.

Args:
    finish: The agent finish.
    run_id: The run ID. This is the ID of the current run.
    parent_run_id: The parent run ID. This is the ID of the parent run.
    tags: The tags.
    **kwargs: Additional keyword arguments.
Nr   )r   rR   r   r   rd   r   s         r   rS   $AsyncCallbackHandler.on_agent_finish  r   r   c                  #    g7f)aB  Run on the retriever start.

Args:
    serialized: The serialized retriever.
    query: The query.
    run_id: The run ID. This is the ID of the current run.
    parent_run_id: The parent run ID. This is the ID of the parent run.
    tags: The tags.
    metadata: The metadata.
    **kwargs: Additional keyword arguments.
Nr   rw   s           r   ry   'AsyncCallbackHandler.on_retriever_start   r   r   c                  #    g7f)a  Run on the retriever end.

Args:
    documents: The documents retrieved.
    run_id: The run ID. This is the ID of the current run.
    parent_run_id: The parent run ID. This is the ID of the parent run.
    tags: The tags.
    **kwargs: Additional keyword arguments.
Nr   )r   r$   r   r   rd   r   s         r   r%   %AsyncCallbackHandler.on_retriever_end7  r   r   c                  #    g7f)a  Run on retriever error.

Args:
    error: The error that occurred.
    run_id: The run ID. This is the ID of the current run.
    parent_run_id: The parent run ID. This is the ID of the parent run.
    tags: The tags.
    **kwargs: Additional keyword arguments.
Nr   r   s         r   r   'AsyncCallbackHandler.on_retriever_errorJ  r   r   r   c                  #    g7f)a  Override to define a handler for custom events.

Args:
    name: The name of the custom event.
    data: The data for the custom event. Format will match
        the format specified by the user.
    run_id: The ID of the run.
    tags: The tags associated with the custom event
        (includes inherited tags).
    metadata: The metadata associated with the custom event
        (includes inherited metadata).
Nr   r   s          r   r   $AsyncCallbackHandler.on_custom_event]  r   r   r   )rh   rU   ri   r   r   r   r   r)   rd   r   re   r   r   r   r*   Noner   )r7   rA   r5   rB   r   r   r   r)   rd   r   r   r   r*   r   )r;   r   r   r   r   r)   rd   r   r   r   r*   r   )r   r(   r   r   r   r)   rd   r   r   r   r*   r   )rh   rU   r~   rU   r   r   r   r)   rd   r   re   r   r   r   r*   r   )rG   rU   r   r   r   r)   rd   r   r   r   r*   r   )rh   rU   r   rA   r   r   r   r)   rd   r   re   r   r~   r   r   r   r*   r   )rZ   r   r   r   r   r)   rd   r   r   r   r*   r   )r   rA   r   r   r   r)   rd   r   r   r   r*   r   r   )rN   r   r   r   r   r)   rd   r   r   r   r*   r   )rR   r   r   r   r   r)   rd   r   r   r   r*   r   )rh   rU   rx   rA   r   r   r   r)   rd   r   re   r   r   r   r*   r   )r$   r+   r   r   r   r)   rd   r   r   r   r*   r   )r   rA   r   r   r   r   rd   r   re   r   r   r   r*   r   )r,   r-   r.   r/   r0   rj   rt   r8   r<   r?   r   rH   rK   r   r[   r^   r   r   rO   rS   ry   r%   r   r   r1   r   r"   r   r   r     s   / &*!%*." 
  #  (  
D &*!%*.'"' *'
 ' #' ' (' ' 
'F ?C%)!% <	
  #   
8 &*!% 	
 #   
0 &*!% 	
 #   
6 &*!%*." 
  #  (  
8 &*!% 	
 #   
0 &*!% 	
 #   
2 &*!%*.(," 
  #  ( &  
< &*!% 	
 #   
0 &*!% 	
 #   
0 &*!% 	
 #   
0 &*# 	
 #  
, &*!% 	
 #   
0 &*!% 	
 #   
2 &*!%*." 
  #  (  
8 &*!%% 	
 #   
0 &*!% 	
 #   
2 "&*. 
   (  
 r"   r   c                     \ rS rSrSr  SSSSSS.               SS jjjrSS jrSS jr\SS j5       r	 S     SS	 jjr
SS
 jr S     SS jjr S     SS jjr S     SS jjrSS jr S     SS jjrSS jrSrg)BaseCallbackManageriu  z$Base callback manager for LangChain.N)rd   inheritable_tagsre   inheritable_metadatac                   Xl         U=(       d    / U l        X0l        U=(       d    / U l        U=(       d    / U l        U=(       d    0 U l        U=(       d    0 U l        g)a*  Initialize callback manager.

Args:
    handlers: The handlers.
    inheritable_handlers: The inheritable handlers.
    parent_run_id: The parent run ID.
    tags: The tags.
    inheritable_tags: The inheritable tags.
    metadata: The metadata.
    inheritable_metadata: The inheritable metadata.
Nhandlersinheritable_handlersr   rd   r   re   r   )r   r   r   r   rd   r   re   r   s           r   __init__BaseCallbackManager.__init__x  sQ    , 4< &B 	! +8JB	 0 6B B$8$>B!r"   c           
     `   U R                  U R                  R                  5       U R                  R                  5       U R                  U R
                  R                  5       U R                  R                  5       U R                  R                  5       U R                  R                  5       S9$ )z&Return a copy of the callback manager.r   )	ro   r   copyr   r   rd   r   re   r   r   s    r   r   BaseCallbackManager.copy  s    ~~]]'')!%!:!:!?!?!A,,!!22779]]'')!%!:!:!?!?!A  
 	
r"   c                :   [        [        U R                  5      [        UR                  5      -  5      n[        [        U R                  5      [        UR                  5      -  5      nU R	                  U R
                  =(       d    UR
                  UU[        [        U R                  UR                  -   5      5      [        [        U R                  UR                  -   5      5      0 U R                  EUR                  E0 U R                  EUR                  ES9$ )a  Merge the callback manager with another callback manager.

May be overwritten in subclasses. Primarily used internally
within merge_configs.

Returns:
    The merged callback manager of the same type as the current object.

Example: Merging two callback managers.

    ```python
    from langchain_core.callbacks.manager import (
        CallbackManager,
        trace_as_chain_group,
    )
    from langchain_core.callbacks.stdout import StdOutCallbackHandler

    manager = CallbackManager(handlers=[StdOutCallbackHandler()], tags=["tag2"])
    with trace_as_chain_group("My Group Name", tags=["tag1"]) as group_manager:
        merged_manager = group_manager.merge(manager)
        print(merged_manager.handlers)
        # [
        #    <langchain_core.callbacks.stdout.StdOutCallbackHandler object at ...>,
        #    <langchain_core.callbacks.streaming_stdout.StreamingStdOutCallbackHandler object at ...>,
        # ]

        print(merged_manager.tags)
        #    ['tag2', 'tag1']
    ```
)r   r   r   rd   r   re   r   )
listsetr   r   ro   r   rd   r   re   r   )r   othercombined_handlerscombined_inheritables       r   mergeBaseCallbackManager.merge  s    B !T]]!3c%..6I!IJ#))*S1K1K-LL 
 ~~,,C0C0C&!5c$))ejj012!#d&;&;e>T>T&T"UV--.."++",,"  
 	
r"   c                    g)z&Whether the callback manager is async.Fr   r   s    r   is_asyncBaseCallbackManager.is_async  r   r"   c                    XR                   ;  a  U R                   R                  U5        U(       a,  XR                  ;  a  U R                  R                  U5        ggg)z|Add a handler to the callback manager.

Args:
    handler: The handler to add.
    inherit: Whether to inherit the handler.
N)r   appendr   r   handlerinherits      r   add_handlerBaseCallbackManager.add_handler  sJ     --'MM  )w&?&??%%,,W5 @7r"   c                    XR                   ;   a  U R                   R                  U5        XR                  ;   a  U R                  R                  U5        gg)zWRemove a handler from the callback manager.

Args:
    handler: The handler to remove.
N)r   remover   )r   r  s     r   remove_handler"BaseCallbackManager.remove_handler  sE     mm#MM  )///%%,,W5 0r"   c                P    / U l         / U l        U H  nU R                  X2S9  M     g)zSet handlers as the only handlers on the callback manager.

Args:
    handlers: The handlers to set.
    inherit: Whether to inherit the handlers.
r  N)r   r   r  )r   r   r  r  s       r   set_handlers BaseCallbackManager.set_handlers  s.     $&!GW6  r"   c                &    U R                  U/US9  g)zSet handler as the only handler on the callback manager.

Args:
    handler: The handler to set.
    inherit: Whether to inherit the handler.
r  N)r  r  s      r   set_handlerBaseCallbackManager.set_handler
  s     	7)W5r"   c                    U H&  nX0R                   ;   d  M  U R                  U/5        M(     U R                   R                  U5        U(       a  U R                  R                  U5        gg)znAdd tags to the callback manager.

Args:
    tags: The tags to add.
    inherit: Whether to inherit the tags.
N)rd   remove_tagsextendr   )r   rd   r  tags       r   add_tagsBaseCallbackManager.add_tags  sX     Cii  #'  			!!((. r"   c                    U HY  nX R                   ;   a  U R                   R                  U5        X R                  ;   d  M>  U R                  R                  U5        M[     g)zLRemove tags from the callback manager.

Args:
    tags: The tags to remove.
N)rd   r
  r   )r   rd   r  s      r   r  BaseCallbackManager.remove_tags)  sJ     Cii		  %+++%%,,S1	 r"   c                    U R                   R                  U5        U(       a  U R                  R                  U5        gg)z~Add metadata to the callback manager.

Args:
    metadata: The metadata to add.
    inherit: Whether to inherit the metadata.
N)re   updater   )r   re   r  s      r   add_metadata BaseCallbackManager.add_metadata5  s2     	X&%%,,X6 r"   c                    U H;  nU R                   R                  US5        U R                  R                  US5        M=     g)zPRemove metadata from the callback manager.

Args:
    keys: The keys to remove.
N)re   popr   )r   keyskeys      r   remove_metadata#BaseCallbackManager.remove_metadataD  s8     CMMc4(%%))#t4 r"   )r   r   r   r   re   r   rd   )NN)r   list[BaseCallbackHandler]r   z list[BaseCallbackHandler] | Noner   r)   rd   r   r   r   re   r   r   r   r*   r   )r*   r
   )r   r   r*   r
   r   )T)r  r   r  r   r*   r   )r  r   r*   r   )r   r&  r  r   r*   r   )rd   r   r  r   r*   r   )rd   r   r*   r   )re   rU   r  r   r*   r   )r"  r   r*   r   )r,   r-   r.   r/   r0   r   r   r   r   r   r  r  r  r  r  r  r  r$  r1   r   r"   r   r   r   u  sb   .
 BF%)	? "&-1*.6:?+? ?? #	? ? +? (? 4? 
?@

4
l   6$6 6 
	6 	6 7+7 7 
	7& 6$6 6 
	6  // / 
	/$
2 7 7 7 
	75r"   r   )(r0   
__future__r   loggingtypingr   r   collections.abcr   uuidr   tenacityr	   typing_extensionsr
   langchain_core.agentsr   r   langchain_core.documentsr   langchain_core.messagesr   langchain_core.outputsr   r   r   	getLoggerr,   _LOGGERr   r3   rD   rW   ra   r   r   r   r   r   	Callbacksr   r"   r   <module>r5     s    * "  %('&>13VV


H
%# #L8 8vE EP# #LC CL: :z11hU. UpW5. W5t $%(;;dB	r"   