
    @h8                    0   S 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  SSKJr  SS	KJrJrJr  SS
KJr  SSKJr  SSKJrJrJr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'J(r(J)r)  SSK*J+r+  SSK,J-r-  \	" SSSS9 " S S\"5      5       r.g)DAn agent designed to hold a conversation in addition to using tools.    )annotations)Sequence)AnyOptional)
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                  @  ^  \ rS rSr% Sr\" \S9r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U 4S jj5       r\\\SS4           SS jj5       r    SS jr\SS\\S4                 SS jj5       rSrU =r$ )ConversationalChatAgent#   r   )default_factoryr   output_parserstrtemplate_tool_responsec                    [        5       $ Nr   )clskwargss     a/var/www/html/shao/venv/lib/python3.13/site-packages/langchain/agents/conversational_chat/base.py_get_default_output_parser2ConversationalChatAgent._get_default_output_parser,   s     ""    c                    [         er+   )NotImplementedErrorselfs    r.   _agent_type#ConversationalChatAgent._agent_type0   s    !!r1   c                    g)zEPrefix to append the observation with.

Returns:
    "Observation: "
zObservation:  r4   s    r.   observation_prefix*ConversationalChatAgent.observation_prefix4   s     r1   c                    g)z>Prefix to append the llm call with.

Returns:
    "Thought: "
zThought:r9   r4   s    r.   
llm_prefix"ConversationalChatAgent.llm_prefix=   s     r1   c                P   > [         TU ]  U5        [        U R                  U5        g r+   )super_validate_toolsr   __name__)r,   tools	__class__s     r.   rA   'ConversationalChatAgent._validate_toolsF   s    &#CLL%8r1   Nc           	        SR                  U Vs/ sH  nSUR                   SUR                   3PM!     sn5      nSR                  U Vs/ sH  ofR                  PM     sn5      nU=(       d    U R                  5       n	UR	                  U	R                  5       S9n
U
R	                  UUS9nUc  / SQn[        R                  " U5      [        SS	9[        R                  " U5      [        S
S	9/n[        XLS9$ s  snf s  snf )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_namesrC   )inputchat_historyagent_scratchpadrK   )variable_namerL   )input_variablesmessages)joinnamedescriptionr/   formatget_format_instructionsr   from_templater   r   r   )r,   rC   system_messagehuman_messagerN   r'   tooltool_stringsrI   _output_parserrH   final_promptrO   s                r.   create_prompt%ConversationalChatAgent.create_promptK   s   . yy>CDedr$))Bt//01eD
 YYe<ed		e<=
&J#*H*H*J+22 . F F H 3 
 +11! 2 
 "KO'55nEn=&44\B.@A	
 "/UU' E<s   %C8C=c                    / nU HX  u  p4UR                  [        UR                  S95        [        U R                  R                  US9S9nUR                  U5        MZ     U$ )zJConstruct the scratchpad that lets the agent continue its thought process.)content)observation)appendr   logr   r)   rS   )r5   intermediate_stepsthoughtsactionr`   rW   s         r.   _construct_scratchpad-ConversationalChatAgent._construct_scratchpadx   sa    
 ')#5FOOIfjj9:(33::{:SM OOM* $6 r1   c                    U R                  U5        U=(       d    U R                  5       n	U R                  UUUUU	S9n
[        UU
US9nU Vs/ sH  oR                  PM     nnU " SUUU	S.UD6$ s  snf )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.
)rV   rW   rN   r'   )llmpromptcallback_manager)	llm_chainallowed_toolsr'   r9   )rA   r/   r\   r   rQ   )r,   ri   rC   rk   r'   rV   rW   rN   r-   rZ   rj   rl   rX   rI   s                 r.   from_llm_and_tools*ConversationalChatAgent.from_llm_and_tools   s    6 	E"&J#*H*H*J"")'+( # 
 -
	
 -22EDiiE
2 
$(
 	
 	
 3s   A/r9   )r-   r   returnr   )rp   r(   )rC   Sequence[BaseTool]rp   None)rC   rq   rV   r(   rW   r(   rN   Optional[list[str]]r'   zOptional[BaseOutputParser]rp   r   )rc   zlist[tuple[AgentAction, str]]rp   zlist[BaseMessage])ri   r   rC   rq   rk   zOptional[BaseCallbackManager]r'   zOptional[AgentOutputParser]rV   r(   rW   r(   rN   rs   r-   r   rp   r   )rB   
__module____qualname____firstlineno____doc__r   r   r'   __annotations__r   r)   classmethodr/   propertyr6   r:   r=   rA   r   r   r\   rf   rn   __static_attributes____classcell__)rD   s   @r.   r$   r$   #   s   N',=N'OM$O&"8C8)# # " "     9 9  %#/348*V!*V *V 	*V
 -*V 2*V 
*V *VX9 
 
 ;?59$#/3.
.
 ".
 8	.

 3.
 .
 .
 -.
 .
 
.
 .
r1   r$   N)/rw   
__future__r   collections.abcr   typingr   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$   r9   r1   r.   <module>r      s|    J " $   * - 8 < H H : 5  *  ; P 
 ? % G!95IQ
e Q
 JQ
r1   