
    D_i%                        S r SSKJr  SSKrSSKrSSKJrJr  SSKJ	r	  SSK
JrJrJrJr  SSKJrJr  SSKJr  SS	KJrJr  SS
KJrJr  SSKJrJrJrJrJrJ r J!r!  SSK"J#r#  \(       a  SSK$J%r%   " S S\5      r&SS jr'g)zStructured tool.    )annotationsN)	AwaitableCallable)	signature)TYPE_CHECKING	AnnotatedAnyLiteral)FieldSkipValidation)override)AsyncCallbackManagerForToolRunCallbackManagerForToolRun)RunnableConfigrun_in_executor)
_EMPTY_SETFILTERED_ARGS
ArgsSchemaBaseTool_get_runnable_config_param_is_injected_arg_typecreate_schema_from_function)is_basemodel_subclass)ToolCallc                  n  ^  \ rS rSr% SrSrS\S'   \" SSS9rS	\S
'    Sr	S\S'    Sr
S\S'    \ S       SU 4S jjj5       rSS.         SS jjrSS.         SU 4S jjjr\       SSSSS.                       SS jjj5       r\R$                  S S j5       rSrU =r$ )!StructuredTool(   z.Tool that can operate on any number of inputs. strdescription.zThe tool schema.)r    z'Annotated[ArgsSchema, SkipValidation()]args_schemaNzCallable[..., Any] | Nonefunc$Callable[..., Awaitable[Any]] | None	coroutinec                   >#    U R                   (       d  [        X R                  X40 UD6I S h  vN $ [        TU ]  " X40 UD6I S h  vN $  N N7fN)r$   r   invokesuperainvoke)selfinputconfigkwargs	__class__s       Y/home/james-whalen/.local/lib/python3.13/site-packages/langchain_core/tools/structured.pyr)   StructuredTool.ainvoke8   sH      ~~(eVvVVVW_U=f=== W=s!   ,AAAA	AA)run_managerc               <   U R                   (       a  U(       aF  [        U R                   5      R                  R                  S5      (       a  UR	                  5       US'   [        U R                   5      =n(       a  XU'   U R                   " U0 UD6$ Sn[        U5      e)a  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
	callbacksz0StructuredTool does not support sync invocation.)r"   r   
parametersget	get_childr   NotImplementedError)r*   r,   r1   argsr-   config_parammsgs          r/   _runStructuredTool._runG   s    $ 99y3>>BB;OO&1&;&;&={#9$))DD|D'-|$99d-f--@!#&&    c               x  >#    U R                   (       a  U(       aF  [        U R                   5      R                  R                  S5      (       a  UR	                  5       US'   [        U R                   5      =n(       a  XU'   U R                   " U0 UD6I Sh  vN $ [        TU ]  " X1US.UD6I Sh  vN $  N N7f)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
r3   N)r,   r1   )r$   r   r4   r5   r6   r   r(   _arun)r*   r,   r1   r8   r-   r9   r.   s         r/   r?   StructuredTool._arunb   s     $ >>y8CCGGTT&1&;&;&={#9$..II|I'-|$8888 W]k
=C
 
 	
	 9
s$   BB:B6B:1B82B:8B:Fcontent)response_formatparse_docstringerror_on_invalid_docstringc                  Ub  UnOUb  UnOSn[        U5      eU=(       d    UR                  nUc  U(       a  [        UUU	U
[        U5      S9nUnUc  U	(       d  UR                  =(       d    SnUc  U(       a  [        U[        5      (       a6  [        U5      (       a&  UR                  nU(       a	  SU;   a  SnOAU(       d  SnO7[        U[        5      (       a  UR                  S5      nOSU 3n[        U5      eUc  Sn[        U5      eUc$  [        R                  " U5      R                  5       nUR                  5        nU " S
UUUUUUUS	.UD6$ )a  Create tool from a given function.

A classmethod that helps to create a tool from a function.

Args:
    func: The function from which to create a tool.
    coroutine: The async function from which to create a tool.
    name: The name of the tool. Defaults to the function name.
    description: The description of the tool.
        Defaults to the function docstring.
    return_direct: Whether to return the result directly or as a callback.
    args_schema: The schema of the tool's input arguments.
    infer_schema: Whether to infer the schema from the function's signature.
    response_format: The tool response format.

        If `"content"` then the output of the tool is interpreted as the
        contents of a `ToolMessage`. If `"content_and_artifact"` then the output
        is expected to be a two-tuple corresponding to the `(content, artifact)`
        of a `ToolMessage`.
    parse_docstring: If `infer_schema` and `parse_docstring`, will attempt
        to parse parameter descriptions from Google Style function docstrings.
    error_on_invalid_docstring: if `parse_docstring` is provided, configure
        whether to raise `ValueError` on invalid Google Style docstrings.
    **kwargs: Additional arguments to pass to the tool

Returns:
    The tool.

Raises:
    ValueError: If the function is not provided.
    ValueError: If the function does not have a docstring and description
        is not provided.
    TypeError: If the `args_schema` is not a `BaseModel` or dict.

Examples:
    ```python
    def add(a: int, b: int) -> int:
        """Add two numbers"""
        return a + b
    tool = StructuredTool.from_function(add)
    tool.run(1, 2) # 3

    ```
Nz*Function and/or coroutine must be provided)rC   rD   filter_argsz)A base class for creating Pydantic modelsr   r    z5Invalid args_schema: expected BaseModel or dict, got z;Function must have a docstring if description not provided.)namer"   r$   r!   r    return_directrB    )
ValueError__name__r   _filter_schema_args__doc__
isinstancetyper   dictr5   	TypeErrortextwrapdedentstrip)clsr"   r$   rG   r    rH   r!   infer_schemarB   rC   rD   r-   source_functionr:   description_s                  r/   from_functionStructuredTool.from_function   st   x "O"'O>CS/!///<5 /+E/@K #*22:dLK+t,,1F{1S1S*22 C|S#%L%#'LK..*}=&-)   n$OCS/!#??<8>>@L ',,./ 	
#$'+	
 	
 		
r=   c                    U R                   =(       d    U R                  nUc  [        $ [        S [	        U5      R
                  R                  5        5       5      $ )Nc              3  b   #    U  H%  u  p[        UR                  5      (       d  M!  Uv   M'     g 7fr&   )r   
annotation).0kvs      r/   	<genexpr>5StructuredTool._injected_args_keys.<locals>.<genexpr>   s'      
8$Q\\2 A8s    /	/)r"   r$   r   	frozensetr   r4   items)r*   fns     r/   _injected_args_keys"StructuredTool._injected_args_keys   sL    YY($..: 
!"00668
 
 	
r=   rI   r&   )r+   zstr | dict | ToolCallr,   zRunnableConfig | Noner-   r	   returnr	   )
r8   r	   r,   r   r1   z CallbackManagerForToolRun | Noner-   r	   rh   r	   )
r8   r	   r,   r   r1   z%AsyncCallbackManagerForToolRun | Noner-   r	   rh   r	   )NNNNFNT)r"   zCallable | Noner$   r#   rG   
str | Noner    ri   rH   boolr!   zArgsSchema | NonerV   rj   rB   z*Literal['content', 'content_and_artifact']rC   rj   rD   rj   r-   r	   rh   r   )rh   zfrozenset[str])rK   
__module____qualname____firstlineno__rM   r    __annotations__r   r!   r"   r$   r   r)   r;   r?   classmethodrY   	functoolscached_propertyrf   __static_attributes____classcell__)r.   s   @r/   r   r   (   s   8K;@+<K8  '&*D
#*66:I3:3
  )-
>$
> &
> 	
>
 

> 
>$ 9=	'' ' 6	'
 ' 
'> >B	

 
 ;	

 
 

 
>  !%:>"&#)-!t
 GP %+0t
t
 8t
 	t

  t
 t
 't
 t
 Dt
 t
 %)t
 t
 
t
 t
l 
 
r=   r   c                j    [        [        5      n[        U 5      =n(       a  UR                  U5        U$ r&   )listr   r   append)r"   rF   r9   s      r/   rL   rL     s0    }%K1$77|7<(r=   )r"   r   rh   z	list[str])(rM   
__future__r   rp   rR   collections.abcr   r   inspectr   typingr   r   r	   r
   pydanticr   r   typing_extensionsr   langchain_core.callbacksr   r   langchain_core.runnablesr   r   langchain_core.tools.baser   r   r   r   r   r   r   langchain_core.utils.pydanticr   langchain_core.messagesr   r   rL   rI   r=   r/   <module>r      sc     "   /   + & E   @0Y
X Y
xr=   