
    ih                        d Z ddlZddlZddlmZ ddlmZmZmZm	Z	 ddl
Z
ddl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  ej2                  e      ZdZdededee   dede	eef   f
dZ edd      	 	 ddedee   deee      dede	eef   f
d       Z edd      de	e ef   dede	eef   fd       Z!de	e ef   dede	eef   fdZ"y)z!Functionality for loading agents.    N)Path)AnyList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                     | j                  d      }|t        vrt        d| d      t        |   }i | |} |j                  ||fi |S )N_typeLoading  agent not supported)popr   
ValueErrorfrom_llm_and_tools)r   r   r   r   config_type	agent_clscombined_configs          V/var/www/html/dev/engine/venv/lib/python3.12/site-packages/langchain/agents/loading.py_load_agent_from_toolsr       sb     **W%K.(8K=0DEFF{+I**6*O'9''UFoFF    z0.1.0z1.0)removalc                    d| vrt        d      | j                  dd      }|r(|t        d      |t        d      t        | ||fi |S | j                  d      }|t        vrt        d| d      t        |   }d	| v rt	        | j                  d	            | d	<   n-d
| v rt        | j                  d
            | d	<   nt        d      d| v rt        j                  d       | d= i | |} |di |S )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   load_from_toolsr   r   r   s           r   load_agent_from_configr,   "   s2   * f?@@jj!:EBO;X  =.  &fc5CFCC**W%K.(8K=0DEFF{+If4VZZ5LM{	V	#(4D)EF{WXX& -	
 ?#**6*O'''r!   pathc                 r    t        | t              r| j                  d      rt        d      t	        | fi |S )aY  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   s     r   
load_agentr4   \   s=    " $!9
 	

 !000r!   filec                    ddh}t        | t              rt        |       }n| }|j                  dd dk(  r*t	        |      5 }t        j                  |      }ddd       nL|j                  dd dk(  r+t	        |d      5 }t        j                  |      }ddd       nt        d| d      t        fi |S # 1 sw Y   xY w# 1 sw Y   !xY w)zLoad agent from file.jsonyaml   Nrz&Unsupported file type, must be one of .)r/   r0   r   suffixopenr7   loadr8   	safe_loadr   r,   )r5   r   valid_suffixes	file_pathfr   s         r   r3   r3   v   s     f%N$J		v%)_ 	"YYq\F	" 	"			!"		')S! 	'Q^^A&F	' 	' A.AQQRSTT!&3F33	" 	"	' 	's    B7=C7C C)NN)#__doc__r7   loggingpathlibr   typingr   r   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dictr    r,   r0   r4   r3   r(   r!   r   <module>rQ      sm   '    - -  * < % N 1 G			8	$U	G	G(	G15d	GGJ	G
 "667	G GU# (,"&6(6(	#	$6( DJ6( 	6(
  "6676( $6(r GU#1
T	
1&)1
 "6671 $124
T	
4&)4
 "6674r!   