
    g3fiV                        d 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
 ddlmZ ddlmZmZ ddlmZmZ dd	lmZmZmZmZ e	rdd
lmZ  G d de      Zy)2Tool that takes in function or coroutine directly.    )annotations)	AwaitableCallable)	signature)TYPE_CHECKINGAny)override)AsyncCallbackManagerForToolRunCallbackManagerForToolRun)RunnableConfigrun_in_executor)
ArgsSchemaBaseToolToolException_get_runnable_config_param)ToolCallc                  6    e Zd ZU dZdZded<   ded<   	 dZded	<   	 e	 d	 	 	 	 	 	 	 d fd
       Ze	d fd       Z
	 	 	 	 	 	 d fdZdd	 	 	 	 	 	 	 	 	 ddZdd	 	 	 	 	 	 	 	 	 d fdZ	 	 	 	 	 	 	 	 	 	 d fdZe	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dd       Z xZS )Toolr    strdescriptionzCallable[..., str] | NonefuncNz$Callable[..., Awaitable[str]] | None	coroutinec                   K   | j                   s!t        || j                  ||fi | d {   S t        |   ||fi | d {   S 7 7 wN)r   r   invokesuperainvoke)selfinputconfigkwargs	__class__s       Y/var/www/auto_recruiter/arenv/lib/python3.12/site-packages/langchain_core/tools/simple.pyr   zTool.ainvoke*   sP      ~~(eVVvVVVW_UF=f=== W=s!   )AA
AAAAc                <    | j                   
t        |   S dddiiS )zdThe tool's input arguments.

        Returns:
            The input arguments for the tool.
        
tool_inputtypestring)args_schemar   args)r    r$   s    r%   r+   z	Tool.args9   s-     '7< vx011    c                    t         |   ||      \  }}t        |      t        |j                               z   }t	        |      dk7  rd| j
                   d| }t        |      t        |      i fS )a+  Convert tool input to Pydantic model.

        Args:
            tool_input: The input to the tool.
            tool_call_id: The ID of the tool call.

        Raises:
            ToolException: If the tool input is invalid.

        Returns:
            The Pydantic model args and kwargs.
           z(Too many arguments to single-input tool z?.
                Consider using StructuredTool instead. Args: )r   _to_args_and_kwargslistvalueslennamer   tuple)r    r'   tool_call_idr+   r#   all_argsmsgr$   s          r%   r/   zTool._to_args_and_kwargsF   s{     w2:|Lf:V]]_ 55x=A<TYYK H"% 
  $$X""r,   )run_managerc                  | j                   rq|rAt        | j                         j                  j                  d      r|j	                         |d<   t        | j                         x}r|||<    | j                   |i |S d}t        |      )aP  Use the tool.

        Args:
            *args: Positional arguments to pass to the tool
            config: Configuration for the run
            run_manager: Optional callback manager to use for the run
            **kwargs: Keyword arguments to pass to the tool

        Returns:
            The result of the tool execution
        	callbacksz&Tool does not support sync invocation.)r   r   
parametersget	get_childr   NotImplementedError)r    r"   r8   r+   r#   config_paramr7   s          r%   _runz	Tool._runa   s    $ 99y3>>BB;O&1&;&;&={#9$))DD|D'-|$499d-f--6!#&&r,   c               R  K   | j                   ry|rAt        | j                         j                  j                  d      r|j	                         |d<   t        | j                         x}r|||<    | j                   |i | d{   S t        |   |||d| d{   S 7 7 w)a_  Use the tool asynchronously.

        Args:
            *args: Positional arguments to pass to the tool
            config: Configuration for the run
            run_manager: Optional callback manager to use for the run
            **kwargs: Keyword arguments to pass to the tool

        Returns:
            The result of the tool execution
        r:   N)r"   r8   )r   r   r;   r<   r=   r   r   _arun)r    r"   r8   r+   r#   r?   r$   s         r%   rB   z
Tool._arun|   s     $ >>y8CCGGT&1&;&;&={#9$..II|I'-|$'8888 W]&k
=C
 
 	
	 9
s$   BB'B#B'B%B'%B'c                ,    t        |   d|||d| y)zInitialize tool.)r3   r   r   N )r   __init__)r    r3   r   r   r#   r$   s        r%   rE   zTool.__init__   s     	Qd;Q&Qr,   c           
     B    ||d}t        |       | d||||||d|S )aF  Initialize tool from a function.

        Args:
            func: The function to create the tool from.
            name: The name of the tool.
            description: The description of the tool.
            return_direct: Whether to return the output directly.
            args_schema: The schema of the tool's input arguments.
            coroutine: The asynchronous version of the function.
            **kwargs: Additional arguments to pass to the tool.

        Returns:
            The tool.

        Raises:
            ValueError: If the function is not provided.
        z*Function and/or coroutine must be provided)r3   r   r   r   return_directr*   rD   )
ValueError)	clsr   r3   r   rG   r*   r   r#   r7   s	            r%   from_functionzTool.from_function   sK    : <I->CS/! 
#'#
 
 	
r,   r   )r!   zstr | dict | ToolCallr"   zRunnableConfig | Noner#   r	   returnr	   )rK   dict)r'   z
str | dictr5   z
str | NonerK   ztuple[tuple, dict])
r+   r	   r"   r   r8   z CallbackManagerForToolRun | Noner#   r	   rK   r	   )
r+   r	   r"   r   r8   z%AsyncCallbackManagerForToolRun | Noner#   r	   rK   r	   )
r3   r   r   Callable | Noner   r   r#   r	   rK   None)FNN)r   rM   r3   r   r   r   rG   boolr*   zArgsSchema | Noner   z$Callable[..., Awaitable[Any]] | Noner#   r	   rK   r   )__name__
__module____qualname____doc__r   __annotations__r   r
   r   propertyr+   r/   r@   rB   rE   classmethodrJ   __classcell__)r$   s   @r%   r   r      s   <K
##66:I3:3  )-
>$
> &
> 	
>
 

> 
> 
2 
2#$#4>#	#> 9=	'' ' 6	'
 ' 
'> >B	

 
 ;	

 
 

@RR.R=@RLOR	R  $)-'
'
 '
 	'

 '
 ''
'
 '
 
'
 '
r,   r   N)rS   
__future__r   collections.abcr   r   inspectr   typingr   r	   typing_extensionsr
   langchain_core.callbacksr   r   langchain_core.runnablesr   r   langchain_core.tools.baser   r   r   r   langchain_core.messagesr   r   rD   r,   r%   <module>ra      sF    8 " / 
 ' E  0k
8 k
r,   