
    KKi                    j   S r SSKJr  SSKJr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  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'  SSK(J)r)  SSK*J+r+   " S S\5      r,\
" S\SS9 " S S\5      5       r-\
" S\SS9 " S S\5      5       r.g)zOAttempt to implement MRKL systems as described in arxiv.org/pdf/2205.00445.pdf.    )annotations)CallableSequence)Any
NamedTuple)
deprecated)BaseCallbackManager)BaseLanguageModel)PromptTemplate)BaseToolTool)render_text_description)Field)override)AGENT_DEPRECATION_WARNING)AgentAgentExecutorAgentOutputParser)	AgentTypeMRKLOutputParser)FORMAT_INSTRUCTIONSPREFIXSUFFIX)validate_tools_single_input)LLMChainc                  8    \ rS rSr% SrS\S'   S\S'   S\S'   Srg	)
ChainConfig   zConfiguration for a chain to use in MRKL system.

Args:
    action_name: Name of the action.
    action: Action function to call.
    action_description: Description of the action.
straction_namer   actionaction_description N)__name__
__module____qualname____firstlineno____doc____annotations____static_attributes__r$       d/var/www/html/dynamic-report/venv/lib/python3.13/site-packages/langchain_classic/agents/mrkl/base.pyr   r      s     r,   r   z0.1.0z1.0)messageremovalc                  ,  ^  \ rS rSr% Sr\" \S9rS\S'   \	\
SS j5       5       r\SS j5       r\SS j5       r\SS	 j5       r\	\\\S
4           SS jj5       r\	S
S
\\\S
4                   SS jj5       r\	SU 4S jj5       rSrU =r$ )ZeroShotAgent(   zQAgent for the MRKL chain.

Args:
    output_parser: Output parser for the agent.
)default_factoryr   output_parserc                    [        5       $ )Nr   )clskwargss     r-   _get_default_output_parser(ZeroShotAgent._get_default_output_parser6   s      !!r,   c                "    [         R                  $ )z Return Identifier of agent type.)r   ZERO_SHOT_REACT_DESCRIPTIONselfs    r-   _agent_typeZeroShotAgent._agent_type;   s     444r,   c                    g)zEPrefix to append the observation with.

Returns:
    "Observation: "
zObservation: r$   r<   s    r-   observation_prefix ZeroShotAgent.observation_prefix@   s     r,   c                    g)z>Prefix to append the llm call with.

Returns:
    "Thought: "
zThought:r$   r<   s    r-   
llm_prefixZeroShotAgent.llm_prefixI   s     r,   Nc                   [        [        U5      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	U(       a	  [        XS9$ [
        R                  " U	5      $ s  snf )a  Create prompt in the style of the zero shot agent.

Args:
    tools: List of tools the agent will have access to, used to format the
        prompt.
    prefix: String to put before the list of tools.
    suffix: String to put after the list of tools.
    format_instructions: Instructions on how to use the tools.
    input_variables: List of input variables the final prompt will expect.


Returns:
    A PromptTemplate with the template assembled from the pieces here.
z, )
tool_namesz

)templateinput_variables)r   listjoinnameformatr   from_template)
r6   toolsprefixsuffixformat_instructionsrI   tool_stringstoolrG   rH   s
             r-   create_promptZeroShotAgent.create_promptR   s    . /tE{;YYe<ed		e<=
188J8OXT,t4G3HVHU!8UU++H55  =s   Bc	                    U R                  U5        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=(       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 LLM to use as the agent LLM.
    tools: The tools to use.
    callback_manager: The callback manager to use.
    output_parser: The output parser to use.
    prefix: The prefix to use.
    suffix: The suffix to use.
    format_instructions: The format instructions to use.
    input_variables: The input variables to use.
    kwargs: Additional parameters to pass to the agent.
)rP   rQ   rR   rI   )llmpromptcallback_manager)	llm_chainallowed_toolsr4   r$   )_validate_toolsrU   r   rL   r8   )r6   rX   rO   rZ   r4   rP   rQ   rR   rI   r7   rY   r[   rT   rG   _output_parsers                  r-   from_llm_and_tools ZeroShotAgent.from_llm_and_toolsq   s    4 	E""" 3+ # 
 -
	
 -22EDiiE
2&J#*H*H*J 
$(
 	
 	
 3s   A0c                  > [        U R                  U5        [        U5      S:X  a  SU R                   S3n[        U5      eU H+  nUR                  b  M  SUR
                   S3n[        U5      e   [        TU ]  U5        g )Nr   zGot no tools for z%. At least one tool must be provided.zGot a tool zN without a description. For this agent, a description must always be provided.)r   r%   len
ValueErrordescriptionrL   superr]   )r6   rO   msgrT   	__class__s       r-   r]   ZeroShotAgent._validate_tools   s    #CLL%8u:?#CLL>1VW  S/!D'!$)) -= >  !o%  	&r,   r$   )r7   r   returnr   )ri   r    )rO   Sequence[BaseTool]rP   r    rQ   r    rR   r    rI   list[str] | Noneri   r   )rX   r
   rO   rj   rZ   zBaseCallbackManager | Noner4   zAgentOutputParser | NonerP   r    rQ   r    rR   r    rI   rk   r7   r   ri   r   )rO   rj   ri   None)r%   r&   r'   r(   r)   r   r   r4   r*   classmethodr   r8   propertyr>   rA   rD   r   r   r   rU   r_   r]   r+   __classcell__)rg   s   @r-   r1   r1   (   sl    (-=M'NM$N"  " 5 5      #6,06!6 6 	6
 !6 *6 
6 6< 
 8<26#6,0-
-
 "-
 5	-

 0-
 -
 -
 !-
 *-
 -
 
-
 -
^ ' 'r,   r1   c                  <    \ rS rSrSr\        SS j5       rSrg)	MRKLChain   z&Chain that implements the MRKL system.c           	         U Vs/ s H,  n[        UR                  UR                  UR                  S9PM.     nn[        R                  X5      nU " SXeS.UD6$ s  snf )aH  User-friendly way to initialize the MRKL chain.

This is intended to be an easy way to get up and running with the
MRKL chain.

Args:
    llm: The LLM to use as the agent LLM.
    chains: The chains the MRKL system has access to.
    **kwargs: parameters to be passed to initialization.

Returns:
    An initialized MRKL chain.
)rL   funcrd   )agentrO   r$   )r   r!   r"   r#   r1   r_   )r6   rX   chainsr7   crO   ru   s          r-   from_chainsMRKLChain.from_chains   sn    4 
  ]]XX00
  	 
 00<66v66
s   3Ar$   N)rX   r
   rv   zlist[ChainConfig]r7   r   ri   r   )r%   r&   r'   r(   r)   rm   rx   r+   r$   r,   r-   rq   rq      s?     177 "7 	7
 
7 7r,   rq   N)/r)   
__future__r   collections.abcr   r   typingr   r   langchain_core._apir   langchain_core.callbacksr	   langchain_core.language_modelsr
   langchain_core.promptsr   langchain_core.toolsr   r   langchain_core.tools.renderr   pydanticr   typing_extensionsr   "langchain_classic._api.deprecationr   langchain_classic.agents.agentr   r   r   $langchain_classic.agents.agent_typesr   +langchain_classic.agents.mrkl.output_parserr   $langchain_classic.agents.mrkl.promptr   r   r   langchain_classic.agents.utilsr   langchain_classic.chainsr   r   r1   rq   r$   r,   r-   <module>r      s    U " . " * 8 < 1 / ?  & H R R : H T T F -*  %
C'E C'
C'L %
 7  7
 7r,   