
    KKid                        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	  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  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"J#r#  S SK$J%r%  S SK&J'r'  \" S\SS9 " S S\5      5       r(g)    )Sequence)Any)
deprecated)AgentAction)BaseCallbackManager)BaseLanguageModel)BasePromptTemplate)ChatPromptTemplateHumanMessagePromptTemplateSystemMessagePromptTemplate)BaseTool)Field)override)AGENT_DEPRECATION_WARNING)AgentAgentOutputParserChatOutputParser)FORMAT_INSTRUCTIONSHUMAN_MESSAGESYSTEM_MESSAGE_PREFIXSYSTEM_MESSAGE_SUFFIX)validate_tools_single_input)LLMChainz0.1.0z1.0)messageremovalc                     ^  \ rS rSr% Sr\" \S9r\\	S'    \
S\4S j5       r\
S\4S j5       rS\\\\4      S\4U 4S	 jjr\\S
\S\4S j5       5       r\S\\   SS4U 4S jj5       r\
S\\   4S j5       r\\\\\S4S\\   S\S\S\S\S\\   S-  S\4S jj5       r\SS\\\\S4S\ S\\   S\!S-  S\S-  S\S\S\S\S\\   S-  S
\S\"4S jj5       r#\
S\4S j5       r$Sr%U =r&$ )	ChatAgent   zChat Agent.)default_factoryoutput_parserreturnc                     g)z&Prefix to append the observation with.zObservation:  selfs    d/var/www/html/dynamic-report/venv/lib/python3.13/site-packages/langchain_classic/agents/chat/base.pyobservation_prefixChatAgent.observation_prefix*   s         c                     g)z#Prefix to append the llm call with.zThought:r$   r%   s    r'   
llm_prefixChatAgent.llm_prefix/   s     r*   intermediate_stepsc                    > [         TU ]  U5      n[        U[        5      (       d  Sn[	        U5      eU(       a  SU 3$ U$ )Nz*agent_scratchpad should be of type string.zhThis was your previous work (but I haven't seen any of it! I only see what you return as final answer):
)super_construct_scratchpad
isinstancestr
ValueError)r&   r.   agent_scratchpadmsg	__class__s       r'   r1   ChatAgent._construct_scratchpad4   sT     !789KL*C00>CS/!11A0BD
  r*   kwargsc                     [        5       $ Nr   )clsr9   s     r'   _get_default_output_parser$ChatAgent._get_default_output_parserD   s      !!r*   toolsNc                 L   > [         TU ]  U5        [        U R                  US9  g )N)
class_namer?   )r0   _validate_toolsr   __name__)r<   r?   r7   s     r'   rB   ChatAgent._validate_toolsI   s    &#s||5Ir*   c                     S/$ )NzObservation:r$   r%   s    r'   _stopChatAgent._stopN   s    r*   system_message_prefixsystem_message_suffixhuman_messageformat_instructionsinput_variablesc                    SR                  U Vs/ s H  owR                   SUR                   3PM     sn5      nSR                  U Vs/ s H  owR                  PM     sn5      n	UR                  U	S9nU SU SU SU 3n
[        R
                  " U
5      [        R
                  " U5      /nUc  SS/n[        XkS9$ s  snf s  snf )	aY  Create a prompt from a list of tools.

Args:
    tools: A list of tools.
    system_message_prefix: The system message prefix.
    system_message_suffix: The system message suffix.
    human_message: The `HumanMessage`.
    format_instructions: The format instructions.
    input_variables: The input variables.

Returns:
    A prompt template.

z: z, )
tool_namesz

inputr5   )rL   messages)joinnamedescriptionformatr   from_templater   r
   )r<   r?   rH   rI   rJ   rK   rL   tooltool_stringsrO   templaterQ   s               r'   create_promptChatAgent.create_promptR   s    . yyQV!WQVYYKr$2B2B1C"DQV!WXYYe<ed		e<=
188J8O$%TnD"#4$%' 	 (55h?&44]C
 "&(:;O!/UU "X<s   $B>
Cllmcallback_managerc
           	          U R                  U5        U R                  U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=(       d    U R	                  5       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.
    tools: A list of tools.
    callback_manager: The callback manager.
    output_parser: The output parser.
    system_message_prefix: The system message prefix.
    system_message_suffix: The system message suffix.
    human_message: The `HumanMessage`.
    format_instructions: The format instructions.
    input_variables: The input variables.
    kwargs: Additional keyword arguments.

Returns:
    An agent.
)rH   rI   rJ   rK   rL   )r\   promptr]   )	llm_chainallowed_toolsr!   r$   )rB   rZ   r   rS   r=   )r<   r\   r?   r]   r!   rH   rI   rJ   rK   rL   r9   r_   r`   rW   rO   _output_parsers                   r'   from_llm_and_toolsChatAgent.from_llm_and_toolsz   s    > 	E""""7"7' 3+ # 
 -
	
 -22EDiiE
2&J#*H*H*J 
$(
 	
 	
 3s   A1c                     [         er;   )r4   r%   s    r'   _agent_typeChatAgent._agent_type   s    r*   r$   )'rC   
__module____qualname____firstlineno____doc__r   r   r!   r   __annotations__propertyr3   r(   r,   listtupler   r1   classmethodr   r   r=   r   r   rB   rF   r   r   r   r   r	   rZ   r   r   r   rc   rf   __static_attributes____classcell__)r7   s   @r'   r   r      s7    ',=M'NM$N&C   C    {C'7!89  
   "# ":K "  " JHX$6 J4 J J  tCy      &;%:*#6,0%V!%V  #%V  #	%V
 %V !%V cT)%V 
%V %VN 
 8<26%:%:*#6,03
3
 !3
 .4	3

 )4/3
  #3
  #3
 3
 !3
 cT)3
 3
 
3
 3
j S  r*   r   N))collections.abcr   typingr   langchain_core._apir   langchain_core.agentsr   langchain_core.callbacksr   langchain_core.language_modelsr   langchain_core.promptsr	   langchain_core.prompts.chatr
   r   r   langchain_core.toolsr   pydanticr   typing_extensionsr   "langchain_classic._api.deprecationr   langchain_classic.agents.agentr   r   +langchain_classic.agents.chat.output_parserr   $langchain_classic.agents.chat.promptr   r   r   r   langchain_classic.agents.utilsr   langchain_classic.chains.llmr   r   r$   r*   r'   <module>r      sw    $  * - 8 < 5 
 *  & H C H  G 1 %
N N
Nr*   