
    @h6                        S r SSKrSSKrSSKJr  SSKJrJrJr  SSK	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  \R0                  " \5      rSrS\S\S\\   S\S\\\4   4
S jr\" SSS9  SS\S\\   S\\\      S\S\\\4   4
S jj5       r\" SSS9S\\ \4   S\S\\\4   4S j5       r!S\\ \4   S\S\\\4   4S jr"g)z!Functionality for loading agents.    N)Path)AnyOptionalUnion)
deprecated)BaseLanguageModel)Tool)BaseMultiActionAgentBaseSingleActionAgent)AGENT_TO_CLASS)
load_chainload_chain_from_configzHhttps://raw.githubusercontent.com/hwchase17/langchain-hub/master/agents/configllmtoolskwargsreturnc                     U R                  S5      nU[        ;  a  SU S3n[        U5      e[        U   n0 U EUEnUR                  " X40 UD6$ )N_typeLoading  agent not supported)popr   
ValueErrorfrom_llm_and_tools)r   r   r   r   config_typemsg	agent_clscombined_configs           P/var/www/html/shao/venv/lib/python3.13/site-packages/langchain/agents/loading.py_load_agent_from_toolsr       sb     **W%K.(%9:o{+I**6*O''FoFF    z0.1.0z1.0)removalc                     SU ;  a  Sn[        U5      eU R                  SS5      nU(       a-  Uc  Sn[        U5      eUc  Sn[        U5      e[        XU40 UD6$ U R                  S5      nU[        ;  a  SU S3n[        U5      e[        U   nS	U ;   a  [	        U R                  S	5      5      U S	'   O1S
U ;   a  [        U R                  S
5      5      U S	'   OSn[        U5      eSU ;   a  [        R                  S5        U S	 0 U EUEnU" S0 UD6$ )a_  Load agent from Config Dict.

Args:
    config: Config dict to load agent from.
    llm: Language model to use as the agent.
    tools: List of tools this agent has access to.
    kwargs: Additional keyword arguments passed to the agent executor.

Returns:
    An agent executor.

Raises:
    ValueError: If agent type is not specified in the config.
r   z$Must specify an agent Type in configload_from_llm_and_toolsFzFIf `load_from_llm_and_tools` is set to True, then LLM must be providedzHIf `load_from_llm_and_tools` is set to True, then tools must be providedr   r   	llm_chainllm_chain_pathz<One of `llm_chain` and `llm_chain_path` should be specified.output_parserzZCurrently loading output parsers on agent is not supported, will just use the default one. )r   r   r    r   r   r   loggerwarning)	r   r   r   r   r   load_from_toolsr   r   r   s	            r   load_agent_from_configr,   &   s>   * f4ojj!:EBO;X  S/!=.  S/!%f5CFCC**W%K.(%9:o{+If4VZZ5LM{	V	#(4D)EF{Lo& -	
 ?#**6*O'''r!   pathc                     [        U [        5      (       a#  U R                  S5      (       a  Sn[        U5      e[	        U 40 UD6$ )a5  Unified method for loading an agent from LangChainHub or local fs.

Args:
    path: Path to the agent file.
    kwargs: Additional keyword arguments passed to the agent executor.

Returns:
    An agent executor.

Raises:
    RuntimeError: If loading from the deprecated github-based
        Hub is attempted.
zlc://zLoading from the deprecated github-based Hub is no longer supported. Please use the new LangChain Hub at https://smith.langchain.com/hub instead.)
isinstancestr
startswithRuntimeError_load_agent_from_file)r-   r   r   s      r   
load_agentr4   e   sF    $ $!9!9 	
 3 000r!   filec                    SS1n[        U [        5      (       a  [        U 5      OU nUR                  SS S:X  a0  UR	                  5        n[
        R                  " U5      nSSS5        OTUR                  SS S:X  a0  UR	                  5        n[        R                  " U5      nSSS5        OSU S3n[        U5      e[        W40 UD6$ ! , (       d  f       N= f! , (       d  f       N+= f)zLoad agent from file.jsonyaml   Nz&Unsupported file type, must be one of .)r/   r0   r   suffixopenr7   loadr8   	safe_loadr   r,   )r5   r   valid_suffixes	file_pathfr   r   s          r   r3   r3      s    
 f%N(s33T
Iv%^^YYq\F 			!"		'^^^^A&F  7~6FaHo!&3F33  s   
C
C

C
C))NN)#__doc__r7   loggingpathlibr   typingr   r   r   r8   langchain_core._apir   langchain_core.language_modelsr   langchain_core.toolsr	   langchain.agents.agentr
   r   langchain.agents.typesr   langchain.chains.loadingr   r   	getLogger__file__r)   URL_BASEdictlistr    r,   r0   r4   r3   r(   r!   r   <module>rQ      su   '    ' '  * < % N 1 G			8	$UGG	G :G 	G
  "667G  GU# (,"&;(;(	#	$;( DJ;( 	;(
  "667;( $;(| GU#1
T	
11  "6671 $164
T	
44  "6674r!   