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