a
    ag                  	   @   sL  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eeee ee	eef dddZeddddeee eee  ee	eef dddZeddde	e ef ee	eef dddZ!e	e ef ee	eef d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   f/var/www/html/cobodadashboardai.evdpl.com/venv/lib/python3.9/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}|rT|du r0t d|du r@t dt| ||fi |S | d}|tvrvt d| d	t| }d
| v rt| d
| d
< n$d| v rt| d| d
< nt dd| v rtd | d= i | |}|f 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   loggerwarning)r   r   r   r   Zload_from_toolsr   r   r   r   r   r   load_agent_from_config"   s:    
r!   )pathr   r   c                 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(   )filer   r   c                 K   s   ddh}t | trt| }n| }|jdd dkrft|}t|}W d   q1 sZ0    Y  nX|jdd dkrt|d}t|}W d   q1 s0    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>   sB   


  

9


