
    ihA                    6   d Z ddlmZ ddlmZmZmZmZmZ ddl	m
Z
 ddlmZ ddlmZ ddlmZ ddlmZmZmZ dd	lmZ dd
lmZ ddlmZmZmZ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(m)Z)m*Z* ddl+m,Z, ddl-m.Z.  e
ddd       G d de#             Z/y)DAn agent designed to hold a conversation in addition to using tools.    )annotations)AnyListOptionalSequenceTuple)
deprecated)AgentAction)BaseCallbackManager)BaseLanguageModel)	AIMessageBaseMessageHumanMessage)BaseOutputParser)BasePromptTemplate)ChatPromptTemplateHumanMessagePromptTemplateMessagesPlaceholderSystemMessagePromptTemplate)BaseTool)Field)AgentAgentOutputParserConvoOutputParser)PREFIXSUFFIXTEMPLATE_TOOL_RESPONSE)validate_tools_single_input)LLMChainz0.1.0create_json_chat_agentz1.0)alternativeremovalc                  (    e Zd ZU dZ ee      Zded<   	 eZ	ded<   	 e
dd       Zedd       Zedd	       Zedd
       Ze
d fd       Ze
eeddf	 	 	 	 	 	 	 	 	 	 	 dd       Z	 	 	 	 ddZe
ddeedf	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dd       Z xZS )ConversationalChatAgentr   )default_factoryr   output_parserstrtemplate_tool_responsec                    t               S Nr   )clskwargss     g/var/www/html/dev/engine/venv/lib/python3.12/site-packages/langchain/agents/conversational_chat/base.py_get_default_output_parserz2ConversationalChatAgent._get_default_output_parser+   s     ""    c                    t         r,   )NotImplementedErrorselfs    r/   _agent_typez#ConversationalChatAgent._agent_type/   s    !!r1   c                     y)z]Prefix to append the observation with.

        Returns:
            "Observation: "
        zObservation:  r4   s    r/   observation_prefixz*ConversationalChatAgent.observation_prefix3   s     r1   c                     y)zVPrefix to append the llm call with.

        Returns:
            "Thought: "
        zThought:r8   r4   s    r/   
llm_prefixz"ConversationalChatAgent.llm_prefix<   s     r1   c                P    t         |   |       t        | j                  |       y r,   )super_validate_toolsr    __name__)r-   tools	__class__s     r/   r>   z'ConversationalChatAgent._validate_toolsE   s    &#CLL%8r1   Nc           	        dj                  |D cg c]  }d|j                   d|j                     c}      }dj                  |D cg c]  }|j                   c}      }|xs | j                         }	|j	                  |	j                               }
|
j	                  ||      }|g d}t        j                  |      t        d	      t        j                  |      t        d
	      g}t        ||      S c c}w c c}w )a  Create a prompt for the agent.

        Args:
            tools: The tools to use.
            system_message: The system message to use.
                Defaults to the PREFIX.
            human_message: The human message to use.
                Defaults to the SUFFIX.
            input_variables: The input variables to use. Defaults to None.
            output_parser: The output parser to use. Defaults to None.

        Returns:
            A PromptTemplate.
        
z> z: z, )format_instructions)
tool_namesr@   )inputchat_historyagent_scratchpadrG   )variable_namerH   )input_variablesmessages)joinnamedescriptionr0   formatget_format_instructionsr   from_templater   r   r   )r-   r@   system_messagehuman_messagerJ   r(   tooltool_stringsrE   _output_parserrD   final_promptrK   s                r/   create_promptz%ConversationalChatAgent.create_promptJ   s   . yy>CDdr$))Bt//01D
 YYe<d		<=
&J#*H*H*J+22 . F F H 3 
 +11! 2 
 "KO'55nEn=&44\B.@A	
 "/HUU% E<s   #C=	Dc                    g }|D ]a  \  }}|j                  t        |j                               t        | j                  j                  |            }|j                  |       c |S )zJConstruct the scratchpad that lets the agent continue its thought process.)content)observation)appendr   logr   r*   rO   )r5   intermediate_stepsthoughtsactionr[   rS   s         r/   _construct_scratchpadz-ConversationalChatAgent._construct_scratchpadv   sh     ')#5 	+FKOOIfjj9:(33::{:SM OOM*	+ r1   c                    | j                  |       |xs | j                         }	| j                  |||||	      }
t        ||
|      }|D cg c]  }|j                   }} | d|||	d|S c c}w )a^  Construct an agent from an LLM and tools.

        Args:
            llm: The language model to use.
            tools: A list of tools to use.
            callback_manager: The callback manager to use. Default is None.
            output_parser: The output parser to use. Default is None.
            system_message: The system message to use. Default is PREFIX.
            human_message: The human message to use. Default is SUFFIX.
            input_variables: The input variables to use. Default is None.
            **kwargs: Any additional arguments.

        Returns:
            An agent.
        )rR   rS   rJ   r(   )llmpromptcallback_manager)	llm_chainallowed_toolsr(   r8   )r>   r0   rX   r!   rM   )r-   rc   r@   re   r(   rR   rS   rJ   r.   rV   rd   rf   rT   rE   s                 r/   from_llm_and_toolsz*ConversationalChatAgent.from_llm_and_tools   s    6 	E"&J#*H*H*J"")'+( # 
 -
	
 -22Ddii2
2 
$(
 	
 	
 3s   A/)r.   r   returnr   )ri   r)   )r@   Sequence[BaseTool]ri   None)r@   rj   rR   r)   rS   r)   rJ   Optional[List[str]]r(   zOptional[BaseOutputParser]ri   r   )r^   zList[Tuple[AgentAction, str]]ri   zList[BaseMessage])rc   r   r@   rj   re   zOptional[BaseCallbackManager]r(   zOptional[AgentOutputParser]rR   r)   rS   r)   rJ   rl   r.   r   ri   r   )r?   
__module____qualname____doc__r   r   r(   __annotations__r   r*   classmethodr0   propertyr6   r9   r;   r>   r   r   rX   ra   rh   __classcell__)rA   s   @r/   r&   r&   "   s   N',=N'OM$O&"8C8)# # " "     9 9  %#/348)V!)V )V 	)V
 -)V 2)V 
)V )VV"?	 
 ;?59$#/3.
.
 ".
 8	.

 3.
 .
 .
 -.
 .
 
.
 .
r1   r&   N)0ro   
__future__r   typingr   r   r   r   r	   langchain_core._apir
   langchain_core.agentsr   langchain_core.callbacksr   langchain_core.language_modelsr   langchain_core.messagesr   r   r   langchain_core.output_parsersr   langchain_core.promptsr   langchain_core.prompts.chatr   r   r   r   langchain_core.toolsr   pydanticr   langchain.agents.agentr   r   2langchain.agents.conversational_chat.output_parserr   +langchain.agents.conversational_chat.promptr   r   r   langchain.agents.utilsr    langchain.chainsr!   r&   r8   r1   r/   <module>r      s|    J " 7 7 * - 8 < H H : 5  *  ; P 
 ? % G!95IO
e O
 JO
r1   