o
    +i                      @  s   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	 d	e
ZG d
d deZG dd de
ZG dd de
ZdddZdddZd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                      sx   e Zd ZU dZded< 	 ded< 	 ded< 	 d Zded< d fddZedddZedddZ	e
dddZ  ZS )AgentActionzRepresents 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
tool_inputlogzLiteral['AgentAction']typekwargsr   c                   s   t  jd|||d| dS )zCreate 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__r   R/var/www/html/psymed-ai/venv/lib/python3.10/site-packages/langchain_core/agents.pyr   B   s   zAgentAction.__init__returnboolc                 C     dS )zL`AgentAction` is serializable.

        Returns:
            `True`
        Tr   clsr   r   r   is_lc_serializableL   s   zAgentAction.is_lc_serializable	list[str]c                 C     g dS ztGet the namespace of the LangChain object.

        Returns:
            `["langchain", "schema", "agent"]`
        )	langchainschemaagentr   r   r   r   r   get_lc_namespaceU      zAgentAction.get_lc_namespaceSequence[BaseMessage]c                 C  s   t | S )z3Return the messages that correspond to this action.)!_convert_agent_action_to_messagesr   r   r   r   messages^   s   zAgentAction.messages)r   r   r   r   r   r   r   r   r   r   r   r!   r   r)   __name__
__module____qualname____doc____annotations__r   r   classmethodr    r'   propertyr,   __classcell__r   r   r   r   r   *   s    
 	
r   c                   @  s(   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)r1   r2   r3   r4   r5   r   r   r   r   r   r9   d   s
   
 	r9   c                   @  s4   e Zd ZU dZded< 	 ded< 	 eddd	Zd
S )	AgentStepz#Result of running an `AgentAction`.r   actionr   observationr   r)   c                 C  s   t | j| jS )-Messages that correspond to this observation.)&_convert_agent_observation_to_messagesr<   r=   r+   r   r   r   r,         zAgentStep.messagesNr/   )r1   r2   r3   r4   r5   r7   r,   r   r   r   r   r;   ~   s   
 r;   c                      sn   e Zd ZU dZded< 	 ded< 	 d Zded< d fd
dZedddZedddZ	e
dddZ  ZS )AgentFinishz}Final return value of an `ActionAgent`.

    Agents return an `AgentFinish` when they have reached a stopping condition.
    dictreturn_valuesr   r   zLiteral['AgentFinish']r   r   r   c                   s   t  jd||d| dS )zGOverride init to support instantiation by position for backward compat.)rC   r   Nr   r   )r   rC   r   r   r   r   r   r      s   zAgentFinish.__init__r   r   c                 C  r   )z,Return `True` as this class is serializable.Tr   r   r   r   r   r       s   zAgentFinish.is_lc_serializabler!   c                 C  r"   r#   r   r   r   r   r   r'      r(   zAgentFinish.get_lc_namespacer)   c                 C  s   t | jdgS )r>   content)r   r   r+   r   r   r   r,      r@   zAgentFinish.messages)rC   rB   r   r   r   r   r-   r.   r/   r0   r   r   r   r   rA      s   
 	rA   agent_actionr   r)   c                 C  s   t | tr| jS t| jd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.
    rD   )
isinstancer9   r:   r   r   )rF   r   r   r   r*      s   
r*   r=   r   c                 C  s^   t | trt| |gS |}t |ts)z	tj|dd}W n ty(   t|}Y nw t|d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_asciirD   )rG   r9   _create_function_messager   jsondumps	Exceptionr
   rF   r=   rE   r   r   r   r?      s   

r?   r	   c                 C  sJ   t |tsz	tj|dd}W n ty   t|}Y nw |}t| j|d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.
    FrH   )namerE   )rG   r   rK   rL   rM   r	   r   rN   r   r   r   rJ      s   
rJ   )rF   r   r   r)   )rF   r   r=   r   r   r)   )rF   r   r=   r   r   r	   )r4   
__future__r   rK   collections.abcr   typingr   r    langchain_core.load.serializabler   langchain_core.messagesr   r   r	   r
   r   r9   r;   rA   r*   r?   rJ   r   r   r   r   <module>   s    :
,
