§
    ˜Štj !  ã                  óæ   — d Z ddlmZ ddlZddlmZ ddlmZmZ ddl	m
Z
 ddlmZmZmZmZ  G d„ d	e
¦  «        Z G d
„ de¦  «        Z G d„ de
¦  «        Z G d„ de
¦  «        Zdd„Zdd„Zdd„ZdS )añ  Schema definitions for representing agent actions, observations, and return values.

!!! warning

    The schema definitions are provided for backwards compatibility.

!!! warning

    New agents should be built using the
    [`langchain` library](https://pypi.org/project/langchain/), which provides a
    simpler and more flexible way to define agents.

    See docs on [building agents](https://docs.langchain.com/oss/python/langchain/agents).

Agents use language models to choose a sequence of actions to take.

A basic agent works in the following manner:

1. Given a prompt an agent uses an LLM to request an action to take
    (e.g., a tool to run).
2. The agent executes the action (e.g., runs the tool), and receives an observation.
3. The agent returns the observation to the LLM, which can then be used to generate
    the next action.
4. When the agent reaches a stopping condition, it returns a final return value.

The schemas for the agents themselves are defined in `langchain.agents.agent`.
é    )ÚannotationsN)ÚSequence)ÚAnyÚLiteral)ÚSerializable)Ú	AIMessageÚBaseMessageÚFunctionMessageÚHumanMessagec                  ó    ‡ — e Zd ZU dZded<   	 ded<   	 ded<   	 d Zded<   dˆ fd„Zedd„¦   «         Zedd„¦   «         Z	e
dd„¦   «         Zˆ xZS )ÚAgentActionzàRepresents a request to execute an action by an agent.

    The action consists of the name of the tool to execute and the input to pass
    to the tool. The log is used to pass along extra information about the action.
    ÚstrÚtoolústr | dict[Any, Any]Ú
tool_inputÚlogzLiteral['AgentAction']ÚtypeÚkwargsr   c                óB   •—  t          ¦   «         j        d|||dœ|¤Ž dS )zàCreate an `AgentAction`.

        Args:
            tool: The name of the tool to execute.
            tool_input: The input to pass in to the `Tool`.
            log: Additional information to log about the action.
        )r   r   r   N© ©ÚsuperÚ__init__)Úselfr   r   r   r   Ú	__class__s        €úS/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/langchain_core/agents.pyr   zAgentAction.__init__G   s1   ø€ ð 	�‰ŒÔÐM˜d¨z¸sÐMÐMÀfÐMÐMÐMÐMÐMó    ÚreturnÚboolc                ó   — dS )zL`AgentAction` is serializable.

        Returns:
            `True`
        Tr   ©Úclss    r   Úis_lc_serializablezAgentAction.is_lc_serializableS   s	   € ð ˆtr   ú	list[str]c                ó
   — g d¢S ©ztGet the namespace of the LangChain object.

        Returns:
            `["langchain", "schema", "agent"]`
        )Ú	langchainÚschemaÚagentr   r!   s    r   Úget_lc_namespacezAgentAction.get_lc_namespace\   ó   € ð 0Ð/Ð/Ð/r   úSequence[BaseMessage]c                ó    — t          | ¦  «        S )z3Return the messages that correspond to this action.)Ú!_convert_agent_action_to_messages©r   s    r   ÚmessageszAgentAction.messagese   s   € õ 1°Ñ6Ô6Ð6r   )r   r   r   r   r   r   r   r   ©r   r   ©r   r$   ©r   r,   ©Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú__annotations__r   r   Úclassmethodr#   r*   Úpropertyr0   Ú__classcell__©r   s   @r   r   r   ,   sí   ø€ € € € € € ðð ð €I€I�IØ,à$Ð$Ð$Ñ$Ø-à€H€H�Hðð $1€DÐ0Ð0Ð0Ñ0ð
Nð 
Nð 
Nð 
Nð 
Nð 
Nð ðð ð ñ „[ðð ð0ð 0ð 0ñ „[ð0ð ð7ð 7ð 7ñ „Xð7ð 7ð 7ð 7ð 7r   r   c                  ó.   — e Zd ZU dZded<   	 d Zded<   dS )ÚAgentActionMessageLoga%  Representation of an action to be executed by an agent.

    This is similar to `AgentAction`, but includes a message log consisting of
    chat messages.

    This is useful when working with `ChatModels`, and is used to reconstruct
    conversation history from the agent's perspective.
    r,   Úmessage_logz Literal['AgentActionMessageLog']r   N)r5   r6   r7   r8   r9   r   r   r   r   r?   r?   k   sC   € € € € € € ðð ð 'Ð&Ð&Ñ&ðð .E€DÐDÐDÐDÑDÐDÐDr   r?   c                  óD   — e Zd ZU dZded<   	 ded<   	 ed
d„¦   «         Zd	S )Ú	AgentStepz#Result of running an `AgentAction`.r   Úactionr   Úobservationr   r,   c                ó6   — t          | j        | j        ¦  «        S )ú-Messages that correspond to this observation.)Ú&_convert_agent_observation_to_messagesrC   rD   r/   s    r   r0   zAgentStep.messagesŽ   s   € õ 6°d´kÀ4ÔCSÑTÔTÐTr   Nr3   )r5   r6   r7   r8   r9   r;   r0   r   r   r   rB   rB   …   s^   € € € € € € Ø-Ð-àÐÐÑØ.àÐÐÑØ*àðUð Uð Uñ „XðUð Uð Ur   rB   c                  ó”   ‡ — e Zd ZU dZded<   	 ded<   	 d Zded<   dˆ fd
„Zedd„¦   «         Zedd„¦   «         Z	e
dd„¦   «         Zˆ xZS )ÚAgentFinishz}Final return value of an `ActionAgent`.

    Agents return an `AgentFinish` when they have reached a stopping condition.
    údict[Any, Any]Úreturn_valuesr   r   zLiteral['AgentFinish']r   r   r   c                ó@   •—  t          ¦   «         j        d||dœ|¤Ž dS )zGOverride init to support instantiation by position for backward compat.)rK   r   Nr   r   )r   rK   r   r   r   s       €r   r   zAgentFinish.__init__©   s-   ø€ à�‰ŒÔÐH }¸#ÐHÐHÀÐHÐHÐHÐHÐHr   r   r   c                ó   — dS )z,Return `True` as this class is serializable.Tr   r!   s    r   r#   zAgentFinish.is_lc_serializable­   s	   € ð ˆtr   r$   c                ó
   — g d¢S r&   r   r!   s    r   r*   zAgentFinish.get_lc_namespace²   r+   r   r,   c                ó.   — t          | j        ¬¦  «        gS )rF   ©Úcontent)r   r   r/   s    r   r0   zAgentFinish.messages»   s   € õ  $¤(Ð+Ñ+Ô+Ð,Ð,r   )rK   rJ   r   r   r   r   r1   r2   r3   r4   r=   s   @r   rI   rI   ”   sá   ø€ € € € € € ðð ð
 "Ð!Ð!Ñ!Ø&à€H€H�Hðð $1€DÐ0Ð0Ð0Ñ0ðIð Ið Ið Ið Ið Ið ðð ð ñ „[ðð ð0ð 0ð 0ñ „[ð0ð ð-ð -ð -ñ „Xð-ð -ð -ð -ð -r   rI   Úagent_actionr   r,   c                óf   — t          | t          ¦  «        r| j        S t          | j        ¬¦  «        gS )a  Convert an agent action to a message.

    This code is used to reconstruct the original AI message from the agent action.

    Args:
        agent_action: Agent action to convert.

    Returns:
        `AIMessage` that corresponds to the original tool invocation.
    rP   )Ú
isinstancer?   r@   r   r   )rR   s    r   r.   r.   Á   s7   € õ �,Õ 5Ñ6Ô6ð (ØÔ'Ð'Ý˜lÔ.Ð/Ñ/Ô/Ð0Ð0r   rD   r   c                ó  — t          | t          ¦  «        rt          | |¦  «        gS |}t          |t          ¦  «        s7	 t	          j        |d¬¦  «        }n# t          $ r t          |¦  «        }Y nw xY wt          |¬¦  «        gS )aG  Convert an agent action to a message.

    This code is used to reconstruct the original AI message from the agent action.

    Args:
        agent_action: Agent action to convert.
        observation: Observation to convert to a message.

    Returns:
        `AIMessage` that corresponds to the original tool invocation.
    F©Úensure_asciirP   )rT   r?   Ú_create_function_messager   ÚjsonÚdumpsÚ	Exceptionr   ©rR   rD   rQ   s      r   rG   rG   Ó   s�   € õ �,Õ 5Ñ6Ô6ð EÝ(¨°{ÑCÔCÐDÐDØ€GÝ�k¥3Ñ'Ô'ð 'ð	'Ý”j ¸5ÐAÑAÔAˆGˆGøÝð 	'ð 	'ð 	'Ý˜+Ñ&Ô&ˆGˆGˆGð	'øøøå Ð)Ñ)Ô)Ð*Ð*s   ¿A ÁA2Á1A2r
   c                óÊ   — t          |t          ¦  «        s7	 t          j        |d¬¦  «        }n!# t          $ r t          |¦  «        }Y nw xY w|}t          | j        |¬¦  «        S )a!  Convert agent action and observation into a function message.

    Args:
        agent_action: the tool invocation request from the agent.
        observation: the result of the tool invocation.

    Returns:
        `FunctionMessage` that corresponds to the original tool invocation.
    FrV   )ÚnamerQ   )rT   r   rY   rZ   r[   r
   r   r\   s      r   rX   rX   ì   s„   € õ �k¥3Ñ'Ô'ð ð	'Ý”j ¸5ÐAÑAÔAˆGˆGøÝð 	'ð 	'ð 	'Ý˜+Ñ&Ô&ˆGˆGˆGð	'øøøð ˆÝØÔØðñ ô ð s   —. ®A
Á	A
)rR   r   r   r,   )rR   r   rD   r   r   r,   )rR   r   rD   r   r   r
   )r8   Ú
__future__r   rY   Úcollections.abcr   Útypingr   r   Ú langchain_core.load.serializabler   Úlangchain_core.messagesr   r	   r
   r   r   r?   rB   rI   r.   rG   rX   r   r   r   ú<module>rd      s¤  ððð ð8 #Ð "Ð "Ð "Ð "Ð "à €€€Ø $Ð $Ð $Ð $Ð $Ð $Ø Ð Ð Ð Ð Ð Ð Ð à 9Ð 9Ð 9Ð 9Ð 9Ð 9ðð ð ð ð ð ð ð ð ð ð ð ð<7ð <7ð <7ð <7ð <7�,ñ <7ô <7ð <7ð~Eð Eð Eð Eð E˜Kñ Eô Eð Eð4Uð Uð Uð Uð U�ñ Uô Uð Uð*-ð *-ð *-ð *-ð *-�,ñ *-ô *-ð *-ðZ1ð 1ð 1ð 1ð$+ð +ð +ð +ð2ð ð ð ð ð r   