
    Ng                        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j        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"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                     |                      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          T/var/www/html/ai-engine/env/lib/python3.11/site-packages/langchain/agents/loading.py_load_agent_from_toolsr       sp     **W%%K.((EKEEEFFF{+I**6*O'9'UFFoFFF    z0.1.0z1.0)removalc                 Z   d| vrt          d          |                     dd          }|r1|t          d          |t          d          t          | ||fi |S |                     d          }|t          vrt          d| d	          t          |         }d
| v r&t	          |                     d
                    | d
<   n9d| v r&t          |                     d                    | d
<   nt          d          d| v rt                              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_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   	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,   "   s   * f?@@@jj!:EBBO D;,   =.   &fc5CCFCCC**W%%K.((EKEEEFFF{+If4VZZ5L5LMM{	V	#	#(4D)E)EFF{WXXX&  -	
 	
 	
 ?#**6*O9'''''r!   pathc                     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   s     r   
load_agentr4   ]   sX    " $ 
!9!9 

 
 	

 !00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           n# 1 swxY w Y   nc|j        dd         dk    r=t	          |d          5 }t          j        |          }ddd           n# 1 swxY w 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/   r0   r   suffixopenr7   loadr8   	safe_loadr   r,   )r5   r   valid_suffixes	file_pathfr   s         r   r3   r3   w   sp    f%N$ JJ			v%%)__ 	"Yq\\F	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	"		!""		'	')S!! 	'Q^A&&F	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' S.SSSTTT!&33F333s$   A//A36A3B??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      so   ' '         - - - - - - - - - - - -  * * * * * * < < < < < < % % % % % % N N N N N N N N 1 1 1 1 1 1 G G G G G G G G		8	$	$U	G	G(	G15d	GGJ	G
 "667	G 	G 	G 	G GU### (,"&7( 7(7(	#	$7( DJ7( 	7(
  "6677( 7( 7( $#7(t GU###1
T	
1&)1
 "6671 1 1 $#124
T	
4&)4
 "6674 4 4 4 4 4r!   