o
    Zh                     @   sh  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eZdZdededee dede	eef f
ddZeddd		ddedee deee  dede	eef f
ddZedddde	e ef dede	eef fddZ!de	e ef dede	eef fddZ"dS )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                 K   sJ   |  d}|tvrtd| dt| }i | |}|j||fi |S )N_typeLoading  agent not supported)popr   
ValueErrorZfrom_llm_and_tools)r   r   r   r   config_type	agent_clscombined_config r   O/var/www/html/lang_env/lib/python3.10/site-packages/langchain/agents/loading.py_load_agent_from_tools   s   
r   z0.1.0z1.0)Zremovalc                 K   s   d| vrt d| dd}|r*|du rt d|du r t dt| ||fi |S | d}|tvr;t d| d	t| }d
| v rMt| d
| d
< nd| v r[t| d| d
< nt dd| v rkt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 configZload_from_llm_and_toolsFNzFIf `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   Z	llm_chainZllm_chain_pathz<One of `llm_chain` and `llm_chain_path` should be specified.Zoutput_parserzZCurrently loading output parsers on agent is not supported, will just use the default one.r   )r   r   r   r   r   r   loggerwarning)r   r   r   r   Zload_from_toolsr   r   r   r   r   r   load_agent_from_config"   s:   
r!   pathc                 K   s,   t | tr| 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   r   r   r   
load_agent\   s
   r(   filec                 K   s   ddh}t | trt| }n| }|jdd dkr3t|}t|}W d   n1 s-w   Y  n,|jdd dkrWt|d}t|}W d   n1 sQw   Y  nt	d| dt
|fi |S )zLoad agent from file.jsonyaml   Nrz&Unsupported file type, must be one of .)r#   r$   r   suffixopenr*   loadr+   Z	safe_loadr   r!   )r)   r   Zvalid_suffixes	file_pathfr   r   r   r   r'   v   s    


r'   )NN)#__doc__r*   loggingpathlibr   typingr   r   r   r   r+   Zlangchain_core._apir   Zlangchain_core.language_modelsr   Zlangchain_core.toolsr	   Zlangchain.agents.agentr
   r   Zlangchain.agents.typesr   Zlangchain.chains.loadingr   r   	getLogger__file__r   ZURL_BASEdictr   r!   r$   r(   r'   r   r   r   r   <module>   sl    






9



