
    .hy-                    $   d dl mZ d dlZd dlZd dlmZ d dlmZ d dlm	Z	m
Z
mZmZmZ d dlmZ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 d
dlmZ d
dlm Z mZ d
dl!m"Z" d
dl#m#Z# d
dl$m%Z% d
dl&m'Z' d
dl(m)Z) d
dl*m+Z+  ed          Z,e
e,e	f         Z-e
ee%e	         e,f         e	f         Z.ee-e,         e.e,         f         Z/e G d d                      Z0e G d d                      Z1e G d d                      Z2e G d d                      Z3e G d d                      Z4ee1e2e3e4f         Z5	 d;d&Z6e
e%e	         e7ge+e8         f         Z9edddd'dd'd(d<d5            Z:edddd'dd'd(d=d7            Z:	 d>dddd'e6d'd(d?d:Z:dS )@    )annotationsN)	Awaitable)	dataclass)AnyCallableLiteralUnionoverload)FiltersRankingOptions)UserLocation)ValidationError)Concatenate	ParamSpec   )_debug)AsyncComputerComputer)ModelBehaviorError)DocstringStylefunction_schema)RunItem)logger)RunContextWrapper)	SpanError)_error_tracing)MaybeAwaitable
ToolParamsc                  2    e Zd ZU ded<   	 ded<   	 ded<   dS )FunctionToolResultFunctionTooltoolr   outputr   run_itemN)__name__
__module____qualname____annotations__     H/var/www/FlaskApp/flask-venv/lib/python3.11/site-packages/agents/tool.pyr    r    !   s9          KKK!FFr*   r    c                  R    e Zd ZU dZded<   	 ded<   	 ded<   	 ded<   	 d	Zd
ed<   dS )r!   zA tool that wraps a function. In most cases, you should use  the `function_tool` helpers to
    create a FunctionTool, as they let you easily wrap a Python function.
    strnamedescriptionzdict[str, Any]params_json_schemaz7Callable[[RunContextWrapper[Any], str], Awaitable[Any]]on_invoke_toolTboolstrict_json_schemaN)r%   r&   r'   __doc__r(   r3   r)   r*   r+   r!   r!   -   sq           IIIX9&&&&4KKKK  $####= =r*   r!   c                  v    e Zd ZU dZded<   	 dZded<   	 dZded	<   	 dZd
ed<   	 dZded<   	 e	d             Z
dS )FileSearchToolzA hosted tool that lets the LLM search through a vector store. Currently only supported with
    OpenAI models, using the Responses API.
    z	list[str]vector_store_idsNz
int | Nonemax_num_resultsFr2   include_search_resultszRankingOptions | Noneranking_optionszFilters | Nonefiltersc                    dS )Nfile_searchr)   selfs    r+   r.   zFileSearchTool.namea   s    }r*   )r%   r&   r'   r4   r(   r8   r9   r:   r;   propertyr.   r)   r*   r+   r6   r6   L   s            1"&O&&&&2#(((((R-1O1111%"G""""5  X  r*   r6   c                  J    e Zd ZU dZdZded<   	 dZded<   	 ed             ZdS )	WebSearchToolz~A hosted tool that lets the LLM search the web. Currently only supported with OpenAI models,
    using the Responses API.
    NzUserLocation | Noneuser_locationmediumz Literal['low', 'medium', 'high']search_context_sizec                    dS )Nweb_search_previewr)   r>   s    r+   r.   zWebSearchTool.namer   s    ##r*   )	r%   r&   r'   r4   rC   r(   rE   r@   r.   r)   r*   r+   rB   rB   f   sd           *.M----d<DDDDD6$ $ X$ $ $r*   rB   c                  6    e Zd ZU dZded<   	 ed             ZdS )ComputerToolz3A hosted tool that lets the LLM control a computer.zComputer | AsyncComputercomputerc                    dS )Ncomputer_use_previewr)   r>   s    r+   r.   zComputerTool.name   s    %%r*   N)r%   r&   r'   r4   r(   r@   r.   r)   r*   r+   rI   rI   w   sH         ==&&&& & & X& & &r*   rI   ctxRunContextWrapper[Any]error	Exceptionreturnr-   c                &    dt          |           S )zLThe default tool error function, which just returns a generic error message.zCAn error occurred while running the tool. Please try again. Error: )r-   )rM   rO   s     r+   default_tool_error_functionrS      s    ]QTUZQ[Q[]]]r*   Tname_overridedescription_overridedocstring_styleuse_docstring_infofailure_error_functionstrict_modefuncToolFunction[...]rU   
str | NonerV   rW   DocstringStyle | NonerX   r2   rY   ToolErrorFunction | NonerZ   c                   dS )z6Overload for usage as @function_tool (no parentheses).Nr)   )r[   rU   rV   rW   rX   rY   rZ   s          r+   function_toolra      s	     Cr*   +Callable[[ToolFunction[...]], FunctionTool]c                    dS )z*Overload for usage as @function_tool(...).Nr)   rT   s         r+   ra   ra      s	     Cr*   ToolFunction[...] | None:FunctionTool | Callable[[ToolFunction[...]], FunctionTool]c               j    dfdt          |           r |           S d	fd}|S )
aC  
    Decorator to create a FunctionTool from a function. By default, we will:
    1. Parse the function signature to create a JSON schema for the tool's parameters.
    2. Use the function's docstring to populate the tool's description.
    3. Use the function's docstring to populate argument descriptions.
    The docstring style is detected automatically, but you can override it.

    If the function takes a `RunContextWrapper` as the first argument, it *must* match the
    context type of the agent that uses the tool.

    Args:
        func: The function to wrap.
        name_override: If provided, use this name for the tool instead of the function's name.
        description_override: If provided, use this description for the tool instead of the
            function's docstring.
        docstring_style: If provided, use this style for the tool's docstring. If not provided,
            we will attempt to auto-detect the style.
        use_docstring_info: If True, use the function's docstring to populate the tool's
            description and argument descriptions.
        failure_error_function: If provided, use this function to generate an error message when
            the tool call fails. The error message is sent to the LLM. If you pass None, then no
            error message will be sent and instead an Exception will be raised.
        strict_mode: Whether to enable strict mode for the tool's JSON schema. We *strongly*
            recommend setting this to True, as it increases the likelihood of correct JSON input.
            If False, it allows non-strict JSON schemas. For example, if a parameter has a default
            value, it will be optional, additional properties are allowed, etc. See here for more:
            https://platform.openai.com/docs/guides/structured-outputs?api-mode=responses#supported-schemas
    the_funcr\   rQ   r!   c                     t           	          d fddfd	}t          j        j        pd
j        |          S )N)r[   rU   rV   rW   rX   r3   rM   rN   inputr-   rQ   r   c                  K   	 |rt          j        |          ni }nu# t          $ rh}t          j        rt          j        dj                    nt          j        dj         d|            t          dj         d|           |d }~ww xY wt          j        rt          j        dj                    nt          j        dj         d|            	 |r j	        d
i |n	                                }n-# t          $ r }t          dj         d|           |d }~ww xY w                    |          \  }}t          j        st          j        d| d|            t          j        	          r)j        r 	| g|R i | d {V }n+ 	|i | d {V }nj        r 	| g|R i |}n 	|i |}t          j        rt          j        dj         d           nt          j        dj         d	|            |S )NzInvalid JSON input for tool z: zInvoking tool z with input zTool call args: z
, kwargs: zTool z completed.z
 returned r)   )jsonloadsrP   r   DONT_LOG_TOOL_DATAr   debugr.   r   params_pydantic_modelr   to_call_argsinspectiscoroutinefunctiontakes_context)
rM   ri   	json_dataeparsedargskwargs_dictresultschemarg   s
           r+   _on_invoke_tool_implzJfunction_tool.<locals>._create_function_tool.<locals>._on_invoke_tool_impl   s     	AF,NDJu,=,=,=B		   , XL!M!M!MNNNNL!V!V!Vu!V!VWWW(I6;II%II  ( P;fk;;<<<<NfkNNuNNOOOc !80F0==9===5577 
 # c c c()Z)Z)ZWX)Z)Z[[abbc !' 3 3F ; ;D+, OMMMMMNNN*844 	<' B#+8C#F$#F#F#F+#F#FFFFFFFFF#+8T#A[#A#AAAAAAAFF' <%Xc@D@@@K@@FF%Xt;{;;F( F=V[===>>>>DV[DDFDDEEEMs-    
BA#BB#D   
D*
D%%D*c           
     0  K   	  | |           d {V S # t           $ rt}  | |          }t          j        |          r| d {V cY d }~S t          j        t          dj        t          |          d                     |cY d }~S d }~ww xY w)NzError running tool (non-fatal))	tool_namerO   )messagedata)rP   rq   isawaitabler   attach_error_to_current_spanr   r.   r-   )rM   ri   ru   ry   r{   rY   rz   s       r+   _on_invoke_toolzEfunction_tool.<locals>._create_function_tool.<locals>._on_invoke_tool  s      11#u=========   )1//Q77&v.. (!'<<<<<<''''''; @)/%(VV      #s&    
B*BB9B
BB )r.   r/   r0   r1   r3   )rM   rN   ri   r-   rQ   r   )r   r!   r.   r/   r0   )
rg   r   r{   rz   rV   rW   rY   rU   rZ   rX   s
   ` @@r+   _create_function_toolz,function_tool.<locals>._create_function_tool   s     '!5+1*
 
 
/	 /	 /	 /	 /	 /	 /	b	 	 	 	 	 	 	 	, *0b%8**
 
 
 	
r*   	real_funcc                     |           S Nr)   )r   r   s    r+   	decoratorz function_tool.<locals>.decorator3  s    $$Y///r*   )rg   r\   rQ   r!   )r   r\   rQ   r!   )callable)	r[   rU   rV   rW   rX   rY   rZ   r   r   s	    `````` @r+   ra   ra      s    NW
 W
 W
 W
 W
 W
 W
 W
 W
 W
 W
t ~~ +$$T***0 0 0 0 0 0 r*   )rM   rN   rO   rP   rQ   r-   )r[   r\   rU   r]   rV   r]   rW   r^   rX   r2   rY   r_   rZ   r2   rQ   r!   )rU   r]   rV   r]   rW   r^   rX   r2   rY   r_   rZ   r2   rQ   rb   r   )r[   rd   rU   r]   rV   r]   rW   r^   rX   r2   rY   r_   rZ   r2   rQ   re   );
__future__r   rq   rk   collections.abcr   dataclassesr   typingr   r   r   r	   r
   -openai.types.responses.file_search_tool_paramr   r   ,openai.types.responses.web_search_tool_paramr   pydanticr   typing_extensionsr   r   r   r   rJ   r   r   
exceptionsr   r   r   itemsr   r   run_contextr   tracingr   utilr   util._typesr   r   ToolFunctionWithoutContextToolFunctionWithContextToolFunctionr    r!   r6   rB   rI   ToolrS   rP   r-   ToolErrorFunctionra   r)   r*   r+   <module>r      s   " " " " " "   % % % % % % ! ! ! ! ! ! : : : : : : : : : : : : : : Q Q Q Q Q Q Q Q E E E E E E $ $ $ $ $ $ 4 4 4 4 4 4 4 4       - - - - - - - - * * * * * * < < < < < < < <             * * * * * *                   ' ' ' ' ' 'Y|$$
%j#o6 ";/@/Ez/Q#RTW#WX /
;=TU_=``a G G G G G G G G = = = = = = = =<        2 $ $ $ $ $ $ $ $  
& 
& 
& 
& 
& 
& 
& 
& \>=,FG *^ ^ ^ ^
 /4i@.QTBUUV  
 !%'+-1#7;     
 
 !%'+-1#7;
 
 
 
 
 

 &*H !%'+-1#7RH H H H H H H Hr*   