a
    ”˜ëjÍ‘  ã                	   @  sP  d Z ddlmZ ddlZddlmZmZmZmZ ddl	m
Z
 er ddlmZ ddlmZ ddlmZ dd	lmZmZ dd
lmZ ddlmZ ddlmZmZmZ e e¡ZG dd„ dƒZG dd„ dƒZ G dd„ dƒZ!G dd„ dƒZ"G dd„ dƒZ#G dd„ dƒZ$G dd„ de e!e"ee#e$ƒZ%G dd„ de%ƒZ&G dd„ de#ƒZ'eee(e% e'f  Z)dS )ú$Base callback handler for LangChain.é    )ÚannotationsN)ÚTYPE_CHECKINGÚAnyÚOptionalÚUnion)ÚSelf)ÚSequence)ÚUUID)ÚRetryCallState)ÚAgentActionÚAgentFinish)ÚDocument)ÚBaseMessage)ÚChatGenerationChunkÚGenerationChunkÚ	LLMResultc                   @  sH   e Zd ZdZddœddddddœd	d
„Zddœddddddœdd„ZdS )ÚRetrieverManagerMixinzMixin for Retriever callbacks.N©Úparent_run_idÚBaseExceptionr
   úOptional[UUID]r   ©ÚerrorÚrun_idr   ÚkwargsÚreturnc                K  s   dS )aG  Run when Retriever errors.

        Args:
            error (BaseException): The error that occurred.
            run_id (UUID): The run ID. This is the ID of the current run.
            parent_run_id (UUID): The parent run ID. This is the ID of the parent run.
            kwargs (Any): Additional keyword arguments.
        N© ©Úselfr   r   r   r   r   r   ú\/mnt/bigstor/www/usecases/.venv/lib/python3.9/site-packages/langchain_core/callbacks/base.pyÚon_retriever_error   s    z(RetrieverManagerMixin.on_retriever_errorúSequence[Document])Ú	documentsr   r   r   r   c                K  s   dS )aV  Run when Retriever ends running.

        Args:
            documents (Sequence[Document]): The documents retrieved.
            run_id (UUID): The run ID. This is the ID of the current run.
            parent_run_id (UUID): The parent run ID. This is the ID of the parent run.
            kwargs (Any): Additional keyword arguments.
        Nr   )r   r#   r   r   r   r   r   r    Úon_retriever_end,   s    z&RetrieverManagerMixin.on_retriever_end)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r!   r$   r   r   r   r    r      s
   ûûr   c                   @  sh   e Zd ZdZdddœddddddd	œd
d„Zddœddddddœdd„Zddœddddddœdd„ZdS )ÚLLMManagerMixinzMixin for LLM callbacks.N)Úchunkr   Ústrú5Optional[Union[GenerationChunk, ChatGenerationChunk]]r
   r   r   )Útokenr*   r   r   r   r   c                K  s   dS )a(  Run on new output token. Only available when streaming is enabled.

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

        Args:
            token (str): The new token.
            chunk (GenerationChunk | ChatGenerationChunk): The new generated chunk,
              containing content and other information.
            run_id (UUID): The run ID. This is the ID of the current run.
            parent_run_id (UUID): The parent run ID. This is the ID of the parent run.
            kwargs (Any): Additional keyword arguments.
        Nr   )r   r-   r*   r   r   r   r   r   r    Úon_llm_new_tokenA   s    	z LLMManagerMixin.on_llm_new_tokenr   r   )Úresponser   r   r   r   c                K  s   dS )aO  Run when LLM ends running.

        Args:
            response (LLMResult): The response which was generated.
            run_id (UUID): The run ID. This is the ID of the current run.
            parent_run_id (UUID): The parent run ID. This is the ID of the parent run.
            kwargs (Any): Additional keyword arguments.
        Nr   )r   r/   r   r   r   r   r   r    Ú
on_llm_endW   s    zLLMManagerMixin.on_llm_endr   r   c                K  s   dS )aA  Run when LLM errors.

        Args:
            error (BaseException): The error that occurred.
            run_id (UUID): The run ID. This is the ID of the current run.
            parent_run_id (UUID): The parent run ID. This is the ID of the parent run.
            kwargs (Any): Additional keyword arguments.
        Nr   r   r   r   r    Úon_llm_errorh   s    zLLMManagerMixin.on_llm_error)r%   r&   r'   r(   r.   r0   r1   r   r   r   r    r)   >   s   úûûr)   c                   @  s€   e Zd ZdZddœddddddœd	d
„Zddœddddddœdd„Zddœddddddœdd„Zddœddddddœdd„ZdS )ÚChainManagerMixinzMixin for chain callbacks.Nr   údict[str, Any]r
   r   r   )Úoutputsr   r   r   r   c                K  s   dS )aM  Run when chain ends running.

        Args:
            outputs (dict[str, Any]): The outputs of the chain.
            run_id (UUID): The run ID. This is the ID of the current run.
            parent_run_id (UUID): The parent run ID. This is the ID of the parent run.
            kwargs (Any): Additional keyword arguments.
        Nr   )r   r4   r   r   r   r   r   r    Úon_chain_end}   s    zChainManagerMixin.on_chain_endr   r   c                K  s   dS )aC  Run when chain errors.

        Args:
            error (BaseException): The error that occurred.
            run_id (UUID): The run ID. This is the ID of the current run.
            parent_run_id (UUID): The parent run ID. This is the ID of the parent run.
            kwargs (Any): Additional keyword arguments.
        Nr   r   r   r   r    Úon_chain_errorŽ   s    z ChainManagerMixin.on_chain_errorr   )Úactionr   r   r   r   c                K  s   dS )a9  Run on agent action.

        Args:
            action (AgentAction): The agent action.
            run_id (UUID): The run ID. This is the ID of the current run.
            parent_run_id (UUID): The parent run ID. This is the ID of the parent run.
            kwargs (Any): Additional keyword arguments.
        Nr   )r   r7   r   r   r   r   r   r    Úon_agent_actionŸ   s    z!ChainManagerMixin.on_agent_actionr   )Úfinishr   r   r   r   c                K  s   dS )a:  Run on the agent end.

        Args:
            finish (AgentFinish): The agent finish.
            run_id (UUID): The run ID. This is the ID of the current run.
            parent_run_id (UUID): The parent run ID. This is the ID of the parent run.
            kwargs (Any): Additional keyword arguments.
        Nr   )r   r9   r   r   r   r   r   r    Úon_agent_finish°   s    z!ChainManagerMixin.on_agent_finish)r%   r&   r'   r(   r5   r6   r8   r:   r   r   r   r    r2   z   s   ûûûûr2   c                   @  sH   e Zd ZdZddœddddddœdd	„Zddœd
dddddœdd„ZdS )ÚToolManagerMixinzMixin for tool callbacks.Nr   r   r
   r   )Úoutputr   r   r   r   c                K  s   dS )aB  Run when the tool ends running.

        Args:
            output (Any): The output of the tool.
            run_id (UUID): The run ID. This is the ID of the current run.
            parent_run_id (UUID): The parent run ID. This is the ID of the parent run.
            kwargs (Any): Additional keyword arguments.
        Nr   )r   r<   r   r   r   r   r   r    Úon_tool_endÅ   s    zToolManagerMixin.on_tool_endr   r   c                K  s   dS )aB  Run when tool errors.

        Args:
            error (BaseException): The error that occurred.
            run_id (UUID): The run ID. This is the ID of the current run.
            parent_run_id (UUID): The parent run ID. This is the ID of the parent run.
            kwargs (Any): Additional keyword arguments.
        Nr   r   r   r   r    Úon_tool_errorÖ   s    zToolManagerMixin.on_tool_error)r%   r&   r'   r(   r=   r>   r   r   r   r    r;   Â   s
   ûûr;   c                   @  sÒ   e Zd ZdZddddœdddddd	d
d
dœdd„Zddddœdddddd	d
d
dœdd„Zddddœdddddd	d
d
dœdd„Zddddœdddddd	d
d
dœdd„Zdddddœdddddd	d	d
d
dœ	dd„ZdS )ÚCallbackManagerMixinzMixin for callback manager.N©r   ÚtagsÚmetadatar3   ú	list[str]r
   r   úOptional[list[str]]úOptional[dict[str, Any]]r   ©Ú
serializedÚpromptsr   r   rA   rB   r   r   c                K  s   dS )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 (dict[str, Any]): The serialized LLM.
            prompts (list[str]): The prompts.
            run_id (UUID): The run ID. This is the ID of the current run.
            parent_run_id (UUID): The parent run ID. This is the ID of the parent run.
            tags (Optional[list[str]]): The tags.
            metadata (Optional[dict[str, Any]]): The metadata.
            kwargs (Any): Additional keyword arguments.
        Nr   ©r   rG   rH   r   r   rA   rB   r   r   r   r    Úon_llm_startë   s    z!CallbackManagerMixin.on_llm_startúlist[list[BaseMessage]]©rG   Úmessagesr   r   rA   rB   r   r   c          	      K  s   | j j› d�}t|ƒ‚dS ©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 (dict[str, Any]): The serialized chat model.
            messages (list[list[BaseMessage]]): The messages.
            run_id (UUID): The run ID. This is the ID of the current run.
            parent_run_id (UUID): The parent run ID. This is the ID of the parent run.
            tags (Optional[list[str]]): The tags.
            metadata (Optional[dict[str, Any]]): The metadata.
            kwargs (Any): Additional keyword arguments.
        z) does not implement `on_chat_model_start`N©Ú	__class__r%   ÚNotImplementedError©	r   rG   rM   r   r   rA   rB   r   Úmsgr   r   r    Úon_chat_model_start  s    z(CallbackManagerMixin.on_chat_model_startr+   ©rG   Úqueryr   r   rA   rB   r   r   c                K  s   dS )aï  Run when the Retriever starts running.

        Args:
            serialized (dict[str, Any]): The serialized Retriever.
            query (str): The query.
            run_id (UUID): The run ID. This is the ID of the current run.
            parent_run_id (UUID): The parent run ID. This is the ID of the parent run.
            tags (Optional[list[str]]): The tags.
            metadata (Optional[dict[str, Any]]): The metadata.
            kwargs (Any): Additional keyword arguments.
        Nr   ©r   rG   rV   r   r   rA   rB   r   r   r   r    Úon_retriever_start&  s    z'CallbackManagerMixin.on_retriever_start©rG   Úinputsr   r   rA   rB   r   r   c                K  s   dS ©aò  Run when a chain starts running.

        Args:
            serialized (dict[str, Any]): The serialized chain.
            inputs (dict[str, Any]): The inputs.
            run_id (UUID): The run ID. This is the ID of the current run.
            parent_run_id (UUID): The parent run ID. This is the ID of the parent run.
            tags (Optional[list[str]]): The tags.
            metadata (Optional[dict[str, Any]]): The metadata.
            kwargs (Any): Additional keyword arguments.
        Nr   ©r   rG   rZ   r   r   rA   rB   r   r   r   r    Úon_chain_start=  s    z#CallbackManagerMixin.on_chain_start©r   rA   rB   rZ   ©	rG   Ú	input_strr   r   rA   rB   rZ   r   r   c          	      K  s   dS ©a+  Run when the tool starts running.

        Args:
            serialized (dict[str, Any]): The serialized tool.
            input_str (str): The input string.
            run_id (UUID): The run ID. This is the ID of the current run.
            parent_run_id (UUID): The parent run ID. This is the ID of the parent run.
            tags (Optional[list[str]]): The tags.
            metadata (Optional[dict[str, Any]]): The metadata.
            inputs (Optional[dict[str, Any]]): The inputs.
            kwargs (Any): Additional keyword arguments.
        Nr   ©	r   rG   r`   r   r   rA   rB   rZ   r   r   r   r    Úon_tool_startT  s    z"CallbackManagerMixin.on_tool_start)	r%   r&   r'   r(   rJ   rT   rX   r]   rc   r   r   r   r    r?   è   s,   ø "ø %ø ø ÷r?   c                	   @  sj   e Zd ZdZddœddddddœd	d
„Zddœddddddœdd„Zdddœddddddddœdd„ZdS )ÚRunManagerMixinzMixin for run manager.Nr   r+   r
   r   r   )Útextr   r   r   r   c                K  s   dS )a,  Run on an arbitrary text.

        Args:
            text (str): The text.
            run_id (UUID): The run ID. This is the ID of the current run.
            parent_run_id (UUID): The parent run ID. This is the ID of the parent run.
            kwargs (Any): Additional keyword arguments.
        Nr   )r   re   r   r   r   r   r   r    Úon_textq  s    zRunManagerMixin.on_textr   ©Úretry_stater   r   r   r   c                K  s   dS ©aA  Run on a retry event.

        Args:
            retry_state (RetryCallState): The retry state.
            run_id (UUID): The run ID. This is the ID of the current run.
            parent_run_id (UUID): The parent run ID. This is the ID of the parent run.
            kwargs (Any): Additional keyword arguments.
        Nr   ©r   rh   r   r   r   r   r   r    Úon_retry‚  s    zRunManagerMixin.on_retry©rA   rB   rD   rE   ©ÚnameÚdatar   rA   rB   r   r   c                K  s   dS )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).

        .. versionadded:: 0.2.15
        Nr   ©r   rn   ro   r   rA   rB   r   r   r   r    Úon_custom_event“  s    
zRunManagerMixin.on_custom_event)r%   r&   r'   r(   rf   rk   rq   r   r   r   r    rd   n  s   ûûùrd   c                   @  s¨   e Zd ZU dZdZded< dZded< eddœdd„ƒZeddœd	d
„ƒZ	eddœdd„ƒZ
eddœdd„ƒZeddœdd„ƒZeddœdd„ƒZeddœdd„ƒZdS )ÚBaseCallbackHandlerr   FÚboolÚraise_errorÚ
run_inline©r   c                 C  s   dS )z Whether to ignore LLM callbacks.Fr   ©r   r   r   r    Ú
ignore_llm½  s    zBaseCallbackHandler.ignore_llmc                 C  s   dS )z"Whether to ignore retry callbacks.Fr   rw   r   r   r    Úignore_retryÂ  s    z BaseCallbackHandler.ignore_retryc                 C  s   dS )z"Whether to ignore chain callbacks.Fr   rw   r   r   r    Úignore_chainÇ  s    z BaseCallbackHandler.ignore_chainc                 C  s   dS )z"Whether to ignore agent callbacks.Fr   rw   r   r   r    Úignore_agentÌ  s    z BaseCallbackHandler.ignore_agentc                 C  s   dS )z&Whether to ignore retriever callbacks.Fr   rw   r   r   r    Úignore_retrieverÑ  s    z$BaseCallbackHandler.ignore_retrieverc                 C  s   dS )z'Whether to ignore chat model callbacks.Fr   rw   r   r   r    Úignore_chat_modelÖ  s    z%BaseCallbackHandler.ignore_chat_modelc                 C  s   dS )zIgnore custom event.Fr   rw   r   r   r    Úignore_custom_eventÛ  s    z'BaseCallbackHandler.ignore_custom_eventN)r%   r&   r'   r(   rt   Ú__annotations__ru   Úpropertyrx   ry   rz   r{   r|   r}   r~   r   r   r   r    rr   ­  s"   
rr   c                   @  s”  e Zd ZdZddddœdddddd	d
ddœdd„Zddddœdddddd	d
d
dœdd„Zddddœdddddd
ddœdd„Zdddœddddd
ddœdd„Zdddœddddd
ddœd d!„Zddddœdddddd	d
dd"œd#d$„Z	dddœddddd
dd%œd&d'„Z
dddœddddd
ddœd(d)„Zddddd*œdddddd	d	d
dd+œ	d,d-„Zdddœd
dddd
dd.œd/d0„Zdddœddddd
ddœd1d2„Zdddœddddd
dd3œd4d5„Zdd6œd7ddd
d
d8œd9d:„Zdddœd;dddd
dd<œd=d>„Zdddœd?dddd
dd@œdAdB„Zddddœdddddd	d
ddCœdDdE„ZdddœdFdddd
ddGœdHdI„Zdddœddddd
ddœdJdK„ZdddLœdd
ddd	d
ddMœdNdO„ZdS )PÚAsyncCallbackHandlerz%Async callback handler for LangChain.Nr@   r3   rC   r
   r   rD   rE   r   ÚNonerF   c                Ë  s   dS )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 (dict[str, Any]): The serialized LLM.
            prompts (list[str]): The prompts.
            run_id (UUID): The run ID. This is the ID of the current run.
            parent_run_id (UUID): The parent run ID. This is the ID of the parent run.
            tags (Optional[list[str]]): The tags.
            metadata (Optional[dict[str, Any]]): The metadata.
            kwargs (Any): Additional keyword arguments.
        Nr   rI   r   r   r    rJ   ä  s    z!AsyncCallbackHandler.on_llm_startrK   rL   c          	      Ë  s   | j j› d�}t|ƒ‚dS rN   rO   rR   r   r   r    rT      s    z(AsyncCallbackHandler.on_chat_model_start)r*   r   rA   r+   r,   )r-   r*   r   r   rA   r   r   c                Ë  s   dS )aZ  Run on new output token. Only available when streaming is enabled.

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

        Args:
            token (str): The new token.
            chunk (GenerationChunk | ChatGenerationChunk): The new generated chunk,
              containing content and other information.
            run_id (UUID): The run ID. This is the ID of the current run.
            parent_run_id (UUID): The parent run ID. This is the ID of the parent run.
            tags (Optional[list[str]]): The tags.
            kwargs (Any): Additional keyword arguments.
        Nr   )r   r-   r*   r   r   rA   r   r   r   r    r.     s    
z%AsyncCallbackHandler.on_llm_new_token)r   rA   r   )r/   r   r   rA   r   r   c                Ë  s   dS )a‡  Run when the model ends running.

        Args:
            response (LLMResult): The response which was generated.
            run_id (UUID): The run ID. This is the ID of the current run.
            parent_run_id (UUID): The parent run ID. This is the ID of the parent run.
            tags (Optional[list[str]]): The tags.
            kwargs (Any): Additional keyword arguments.
        Nr   )r   r/   r   r   rA   r   r   r   r    r0   7  s    	zAsyncCallbackHandler.on_llm_endr   )r   r   r   rA   r   r   c                Ë  s   dS )a·  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 (Any): Additional keyword arguments.
                - response (LLMResult): The response which was generated before
                    the error occurred.
        Nr   ©r   r   r   r   rA   r   r   r   r    r1   J  s    	z!AsyncCallbackHandler.on_llm_errorrY   c                Ë  s   dS r[   r   r\   r   r   r    r]   _  s    z#AsyncCallbackHandler.on_chain_start)r4   r   r   rA   r   r   c                Ë  s   dS )a�  Run when a chain ends running.

        Args:
            outputs (dict[str, Any]): The outputs of the chain.
            run_id (UUID): The run ID. This is the ID of the current run.
            parent_run_id (UUID): The parent run ID. This is the ID of the parent run.
            tags (Optional[list[str]]): The tags.
            kwargs (Any): Additional keyword arguments.
        Nr   )r   r4   r   r   rA   r   r   r   r    r5   v  s    	z!AsyncCallbackHandler.on_chain_endc                Ë  s   dS )au  Run when chain errors.

        Args:
            error (BaseException): The error that occurred.
            run_id (UUID): The run ID. This is the ID of the current run.
            parent_run_id (UUID): The parent run ID. This is the ID of the parent run.
            tags (Optional[list[str]]): The tags.
            kwargs (Any): Additional keyword arguments.
        Nr   rƒ   r   r   r    r6   ‰  s    	z#AsyncCallbackHandler.on_chain_errorr^   r_   c          	      Ë  s   dS ra   r   rb   r   r   r    rc   œ  s    z"AsyncCallbackHandler.on_tool_start)r<   r   r   rA   r   r   c                Ë  s   dS )at  Run when the tool ends running.

        Args:
            output (Any): The output of the tool.
            run_id (UUID): The run ID. This is the ID of the current run.
            parent_run_id (UUID): The parent run ID. This is the ID of the parent run.
            tags (Optional[list[str]]): The tags.
            kwargs (Any): Additional keyword arguments.
        Nr   )r   r<   r   r   rA   r   r   r   r    r=   µ  s    	z AsyncCallbackHandler.on_tool_endc                Ë  s   dS )at  Run when tool errors.

        Args:
            error (BaseException): The error that occurred.
            run_id (UUID): The run ID. This is the ID of the current run.
            parent_run_id (UUID): The parent run ID. This is the ID of the parent run.
            tags (Optional[list[str]]): The tags.
            kwargs (Any): Additional keyword arguments.
        Nr   rƒ   r   r   r    r>   È  s    	z"AsyncCallbackHandler.on_tool_error)re   r   r   rA   r   r   c                Ë  s   dS )a^  Run on an arbitrary text.

        Args:
            text (str): The text.
            run_id (UUID): The run ID. This is the ID of the current run.
            parent_run_id (UUID): The parent run ID. This is the ID of the parent run.
            tags (Optional[list[str]]): The tags.
            kwargs (Any): Additional keyword arguments.
        Nr   )r   re   r   r   rA   r   r   r   r    rf   Û  s    	zAsyncCallbackHandler.on_textr   r   rg   c                Ë  s   dS ri   r   rj   r   r   r    rk   î  s    zAsyncCallbackHandler.on_retryr   )r7   r   r   rA   r   r   c                Ë  s   dS )ak  Run on agent action.

        Args:
            action (AgentAction): The agent action.
            run_id (UUID): The run ID. This is the ID of the current run.
            parent_run_id (UUID): The parent run ID. This is the ID of the parent run.
            tags (Optional[list[str]]): The tags.
            kwargs (Any): Additional keyword arguments.
        Nr   )r   r7   r   r   rA   r   r   r   r    r8   ÿ  s    	z$AsyncCallbackHandler.on_agent_actionr   )r9   r   r   rA   r   r   c                Ë  s   dS )al  Run on the agent end.

        Args:
            finish (AgentFinish): The agent finish.
            run_id (UUID): The run ID. This is the ID of the current run.
            parent_run_id (UUID): The parent run ID. This is the ID of the parent run.
            tags (Optional[list[str]]): The tags.
            kwargs (Any): Additional keyword arguments.
        Nr   )r   r9   r   r   rA   r   r   r   r    r:     s    	z$AsyncCallbackHandler.on_agent_finishrU   c                Ë  s   dS )aä  Run on the retriever start.

        Args:
            serialized (dict[str, Any]): The serialized retriever.
            query (str): The query.
            run_id (UUID): The run ID. This is the ID of the current run.
            parent_run_id (UUID): The parent run ID. This is the ID of the parent run.
            tags (Optional[list[str]]): The tags.
            metadata (Optional[dict[str, Any]]): The metadata.
            kwargs (Any): Additional keyword arguments.
        Nr   rW   r   r   r    rX   %  s    z'AsyncCallbackHandler.on_retriever_startr"   )r#   r   r   rA   r   r   c                Ë  s   dS )a�  Run on the retriever end.

        Args:
            documents (Sequence[Document]): The documents retrieved.
            run_id (UUID): The run ID. This is the ID of the current run.
            parent_run_id (UUID): The parent run ID. This is the ID of the parent run.
            tags (Optional[list[str]]): The tags.
            kwargs (Any): Additional keyword arguments.
        Nr   )r   r#   r   r   rA   r   r   r   r    r$   <  s    	z%AsyncCallbackHandler.on_retriever_endc                Ë  s   dS )av  Run on retriever error.

        Args:
            error (BaseException): The error that occurred.
            run_id (UUID): The run ID. This is the ID of the current run.
            parent_run_id (UUID): The parent run ID. This is the ID of the parent run.
            tags (Optional[list[str]]): The tags.
            kwargs (Any): Additional keyword arguments.
        Nr   rƒ   r   r   r    r!   O  s    	z'AsyncCallbackHandler.on_retriever_errorrl   rm   c                Ë  s   dS )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).

        .. versionadded:: 0.2.15
        Nr   rp   r   r   r    rq   b  s    
z$AsyncCallbackHandler.on_custom_event)r%   r&   r'   r(   rJ   rT   r.   r0   r1   r]   r5   r6   rc   r=   r>   rf   rk   r8   r:   rX   r$   r!   rq   r   r   r   r    r�   á  s€   ø "ø #ùúúø úú÷"úúúûúúø úúùr�   c                   @  sþ   e Zd ZdZd2dddddœdddddddd	d
œdd„Zddœdd„Zd ddœdd„Zeddœdd„ƒZd3ddd	dœdd„Z	dd	dœdd„Z
d4ddd	dœd d!„Zd5ddd	dœd"d#„Zd6d$dd	d%œd&d'„Zd$d	d(œd)d*„Zd7d+dd	d,œd-d.„Zd$d	d/œd0d1„ZdS )8ÚBaseCallbackManagerz$Base callback manager for LangChain.N)rA   Úinheritable_tagsrB   Úinheritable_metadatazlist[BaseCallbackHandler]z#Optional[list[BaseCallbackHandler]]r   rD   rE   r‚   )ÚhandlersÚinheritable_handlersr   rA   r…   rB   r†   r   c                C  sB   || _ |pg | _|| _|pg | _|p&g | _|p0i | _|p:i | _dS )a»  Initialize callback manager.

        Args:
            handlers (list[BaseCallbackHandler]): The handlers.
            inheritable_handlers (Optional[list[BaseCallbackHandler]]):
              The inheritable handlers. Default is None.
            parent_run_id (Optional[UUID]): The parent run ID. Default is None.
            tags (Optional[list[str]]): The tags. Default is None.
            inheritable_tags (Optional[list[str]]): The inheritable tags.
                Default is None.
            metadata (Optional[dict[str, Any]]): The metadata. Default is None.
            inheritable_metadata (Optional[dict[str, Any]]): The inheritable metadata.
                Default is None.
        N©r‡   rˆ   r   rA   r…   rB   r†   )r   r‡   rˆ   r   rA   r…   rB   r†   r   r   r    Ú__init__  s    ÿ


zBaseCallbackManager.__init__r   rv   c              	   C  s>   | j | j ¡ | j ¡ | j| j ¡ | j ¡ | j ¡ | j ¡ d�S )z&Return a copy of the callback manager.r‰   )	rP   r‡   Úcopyrˆ   r   rA   r…   rB   r†   rw   r   r   r    r‹   ¢  s    ùzBaseCallbackManager.copy)Úotherr   c              	   C  s’   | j | jp|jg g tt| j|j ƒƒtt| j|j ƒƒi | j¥|j¥d�}| j|j }| j|j }|D ]}| 	|¡ qf|D ]}|j	|dd� qz|S )aM  Merge the callback manager with another callback manager.

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

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

        Example: Merging two callback managers.

            .. code-block:: 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ˆ   rA   r…   rB   T©Úinherit)
rP   r   ÚlistÚsetrA   r…   rB   r‡   rˆ   Úadd_handler)r   rŒ   Úmanagerr‡   rˆ   Úhandlerr   r   r    Úmerge®  s&    %
ÿþúzBaseCallbackManager.mergers   c                 C  s   dS )z&Whether the callback manager is async.Fr   rw   r   r   r    Úis_asyncé  s    zBaseCallbackManager.is_asyncTrr   )r“   rŽ   r   c                 C  s4   || j vr| j  |¡ |r0|| jvr0| j |¡ dS )zÊAdd a handler to the callback manager.

        Args:
            handler (BaseCallbackHandler): The handler to add.
            inherit (bool): Whether to inherit the handler. Default is True.
        N)r‡   Úappendrˆ   ©r   r“   rŽ   r   r   r    r‘   î  s    
zBaseCallbackManager.add_handler)r“   r   c                 C  s0   || j v r| j  |¡ || jv r,| j |¡ dS )z…Remove a handler from the callback manager.

        Args:
            handler (BaseCallbackHandler): The handler to remove.
        N)r‡   Úremoverˆ   )r   r“   r   r   r    Úremove_handlerþ  s    

z"BaseCallbackManager.remove_handler)r‡   rŽ   r   c                 C  s(   g | _ g | _|D ]}| j||d� qdS )zçSet handlers as the only handlers on the callback manager.

        Args:
            handlers (list[BaseCallbackHandler]): The handlers to set.
            inherit (bool): Whether to inherit the handlers. Default is True.
        r�   N)r‡   rˆ   r‘   )r   r‡   rŽ   r“   r   r   r    Úset_handlers	  s    z BaseCallbackManager.set_handlersc                 C  s   | j |g|d� dS )zÜSet handler as the only handler on the callback manager.

        Args:
            handler (BaseCallbackHandler): The handler to set.
            inherit (bool): Whether to inherit the handler. Default is True.
        r�   N)rš   r—   r   r   r    Úset_handler  s    zBaseCallbackManager.set_handlerrC   )rA   rŽ   r   c                 C  s@   |D ]}|| j v r|  |g¡ q| j  |¡ |r<| j |¡ dS )z²Add tags to the callback manager.

        Args:
            tags (list[str]): The tags to add.
            inherit (bool): Whether to inherit the tags. Default is True.
        N)rA   Úremove_tagsÚextendr…   )r   rA   rŽ   Útagr   r   r    Úadd_tags&  s    
zBaseCallbackManager.add_tags)rA   r   c                 C  s:   |D ]0}|| j v r| j  |¡ || jv r| j |¡ qdS )zpRemove tags from the callback manager.

        Args:
            tags (list[str]): The tags to remove.
        N)rA   r˜   r…   )r   rA   rž   r   r   r    rœ   8  s
    

zBaseCallbackManager.remove_tagsr3   )rB   rŽ   r   c                 C  s    | j  |¡ |r| j |¡ dS )zÇAdd metadata to the callback manager.

        Args:
            metadata (dict[str, Any]): The metadata to add.
            inherit (bool): Whether to inherit the metadata. Default is True.
        N)rB   Úupdater†   )r   rB   rŽ   r   r   r    Úadd_metadataD  s    z BaseCallbackManager.add_metadata)Úkeysr   c                 C  s*   |D ] }| j  |d¡ | j |d¡ qdS )ztRemove metadata from the callback manager.

        Args:
            keys (list[str]): The keys to remove.
        N)rB   Úpopr†   )r   r¢   Úkeyr   r   r    Úremove_metadataS  s    z#BaseCallbackManager.remove_metadata)NN)T)T)T)T)T)r%   r&   r'   r(   rŠ   r‹   r”   r€   r•   r‘   r™   rš   r›   rŸ   rœ   r¡   r¥   r   r   r   r    r„   |  s4     ü÷ #; ý ý ý ý ýr„   )*r(   Ú
__future__r   ÚloggingÚtypingr   r   r   r   Ztyping_extensionsr   Úcollections.abcr	   Úuuidr
   Ztenacityr   Zlangchain_core.agentsr   r   Zlangchain_core.documentsr   Zlangchain_core.messagesr   Zlangchain_core.outputsr   r   r   Ú	getLoggerr%   Z_LOGGERr   r)   r2   r;   r?   rd   rr   r�   r„   r�   Z	Callbacksr   r   r   r    Ú<module>   sF   
&<H& ?
ú4    c