
    Cj                      % S SK Jr  S SKrS SKrS SKrS SKrS SKrS SKrS SKrS SK	r	S SK
JrJrJr  S SKJrJr  S SKJr  S SKJr  S SKJrJrJrJrJrJrJrJrJrJrJrJ r 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-  S SK.J/r/J0r0J1r1  S SK2J&r3  S SK4J5r5  S SK6J7r7J8r8J9r9J:r:  S SK;J<r<J=r=J>r>  SSK?J@r@  SSKAJBrBJCrCJDrDJErE  SSKFJGrGJHrH  SSKIJJrJJKrK  SSKLJMrMJNrNJOrO  SSKPJQrQJPrP  SSKRJRrR  SSKSJTrT  SSKUJVrV  SSKWJXrX  SSKYJZrZJ[r[  SSK\J]r]  SSK^J_r_  SSK`Jara  \(       a  SS KbJcrcJdrd  SS!KeJfrfJgrg  \=" S"5      rh\\h\4   ri\\\T\   \h4   \4   rj\\\X\h4   \4   rk\i\h   \j\h   -  \k\h   -  rlS#rm\S$   rn\\T\   \o/\a\p   4   rq\\X\   \p/\a\   4   rr\\T\   \p\p/\a\s   4   rtS%ru\v" 5       rw " S& S'\75      rx " S( S)\>S*S+9ry " S, S-\75      rz " S. S/\>S*S+9r{ " S0 S1\75      r| " S2 S3\>S*S+9r}\x\z-  \|-  r~\8" \~5      rS4\S5'    " S6 S7\p\5      r\" S8S99 " S: S;5      5       r\H\G-  r\" S<\S=9r\" S>\S8S?9r\" S@\S8SA9r " SB SC\\   5      r " SD SE\\   5      r\ " SF SG\\   5      5       r\\\   -  \\   -  r\ " SH SI5      5       r\ " SJ SK5      5       r " SL SM5      r      SSN jr\wS8S8SSS*SSOSS*S*SSSP.                                     SSQ jjrSSR jr\ " SS ST5      5       r\ " SU SV5      5       r\" S*SW9 " SX SY\\   5      5       r\ " SZ S[5      5       r\	GR*                  " 5       rS\\S]'   \	GR*                  " 5       rS^\S_'   \	GR*                  " 5       rS`\Sa'         SSb jrSSc jr\ " Sd Se5      5       r\ " Sf Sg5      5       r " Sh Si\>5      r\\/\a\   4   r \\T\   Sj\p/\a\s   4   r  " Sk Sl\>5      r\\T\   Sm/\a\   4   r \\T\   \K\p/\a\s   4   r  " Sn So\>5      r\\T\   Sm/\a\   4   r  " Sp Sq\>5      r\\T\   Sm/\a\   4   r \ " Sr Ss5      5       r\ " St Su5      5       r\ " Sv Sw5      5       r\ " Sx Sy5      5       r\\/\a\p   4   r \ " Sz S{5      5       r " S| S}\>5      r " S~ S\>5      r " S S\>5      r " S S\>5      r\\-  r  " S S\>5      r " S S\>5      r " S S\>5      r\\-  r  " S S\>5      r " S S\>5      r " S S\>5      r\\-  r \\-  r \ " S S5      5       r\ " S S5      5       r\ " S S5      5       r\ " S Sj5      5       r\ " S S5      5       r\ " S S5      5       r\\/\a\p\-     4   r     SS jr\ " S S5      5       r\ " S S5      5       r\ " S S5      5       r\ " S S5      5       r\\-  \-  \\   -  \-  \-  \-  \-  \-  \-  \-  \-  r         SS jrSS jr      SS jr      SS jrSS jrSS jrSS jrSS jrS*S.     SS jjrSS jrSS jrSS jrSS8S8S.           SS jjrSS jrSS jrSS jrS$rS\S'   SS jr\w4     SS jjr    SS jr " S S\o5      rSS jr        SS jrSS jrSS jrSS jrSS jr      SS jr        SS jr\"SSSS8SS8S8S*SSSSOSS*S.                               SS jj5       r\"SSSS8SS8S8S*SSSSOSS*S.                             SS jj5       r SSSSS8\wS8S8S*SSSSOSS*S.                               SS jjjrSS jrSS jrSS jrSS jr        SS jrg)    )annotationsN)	AwaitableCallableMapping)	dataclassfield)Enum)	UnionType)TYPE_CHECKING	AnnotatedAnyConcatenateGenericLiteralProtocolTypeVarUnioncastget_args
get_originget_type_hintsoverload)CustomToolParam)FiltersRankingOptions)PendingSafetyCheckResponseComputerToolCall)LocalShellCallMcpApprovalRequest)CodeInterpreterImageGenerationMcp)r   )UserLocation)	BaseModelTypeAdapterValidationErrormodel_validator)NotRequired	ParamSpec	TypedDict   )_debug)$get_explicit_function_tool_namespacetool_qualified_name+validate_function_tool_lookup_configuration&validate_function_tool_namespace_shape)AsyncComputerComputer)ApplyPatchEditorApplyPatchOperation)ModelBehaviorErrorToolTimeoutError	UserError)DocstringStylefunction_schema)logger)RunContextWrapper)ensure_strict_json_schema)ToolContext)ToolInputGuardrailToolOutputGuardrail)	SpanError)_error_tracing)MaybeAwaitable)Agent	AgentBase)RunItemToolApprovalItem
ToolParamsz Tool execution was not approved.)error_as_resultraise_exception__agents_sync_function_tool__c                  2    \ rS rSr% SrSrS\S'   S\S'   Srg)	ToolOutputText[   zBRepresents a tool output that should be sent to the model as text.textLiteral['text']typestr N)__name__
__module____qualname____firstlineno____doc__rP   __annotations____static_attributes__rR       ]/home/rurouni/.local/share/pipx/venvs/strix-agent/lib/python3.13/site-packages/agents/tool.pyrL   rL   [   s    L"D/"
IrZ   rL   c                  .    \ rS rSr% SrS\S'   S\S'   Srg)	ToolOutputTextDictb   z(TypedDict variant for text tool outputs.rO   rP   rQ   rN   rR   NrS   rT   rU   rV   rW   rX   rY   rR   rZ   r[   r]   r]   b   s    2

IrZ   r]   F)totalc                  n    \ rS rSr% SrSrS\S'   SrS\S'   SrS\S	'   Sr	S
\S'   \
" SS9SS j5       rSrg)ToolOutputImagei   zRepresents a tool output that should be sent to the model as an image.

You can provide either an `image_url` (URL or data URL) or a `file_id` for previously uploaded
content. The optional `detail` can control vision detail.
imageLiteral['image']rP   N
str | None	image_urlfile_idz%Literal['low', 'high', 'auto'] | Nonedetailaftermodec                P    U R                   c  U R                  c  [        S5      eU $ )z?Validate that at least one of image_url or file_id is provided.z5At least one of image_url or file_id must be provided)rg   rh   
ValueErrorselfs    r[   !check_at_least_one_required_field1ToolOutputImage.check_at_least_one_required_fieldu   s(     >>!dll&:TUUrZ   rR   )returnrb   )rS   rT   rU   rV   rW   rP   rX   rg   rh   ri   r'   rq   rY   rR   rZ   r[   rb   rb   i   sJ     %D
$ Iz GZ48F18'" #rZ   rb   c                  B    \ rS rSr% SrS\S'   S\S'   S\S'   S\S	'   S
rg)ToolOutputImageDict}   z)TypedDict variant for image tool outputs.re   rP   NotRequired[str]rg   rh   z+NotRequired[Literal['low', 'high', 'auto']]ri   rR   Nr_   rR   rZ   r[   ru   ru   }   s    3
77rZ   ru   c                  |    \ rS rSr% SrSrS\S'   SrS\S'   SrS\S	'   Sr	S\S
'   Sr
S\S'   \" SS9SS j5       rSrg)ToolOutputFileContent   zRepresents a tool output that should be sent to the model as a file.

Provide one of `file_data` (base64), `file_url`, or `file_id`. You may also
provide an optional `filename` when using `file_data` to hint file name.
fileLiteral['file']rP   Nrf   	file_datafile_urlrh   filenamerj   rk   c                j    U R                   c%  U R                  c  U R                  c  [        S5      eU $ )zJValidate that at least one of file_data, file_url, or file_id is provided.z@At least one of file_data, file_url, or file_id must be provided)r}   r~   rh   rn   ro   s    r[   rq   7ToolOutputFileContent.check_at_least_one_required_field   s1     >>!dmm&;@T_``rZ   rR   )rs   ry   )rS   rT   rU   rV   rW   rP   rX   r}   r~   rh   r   r'   rq   rY   rR   rZ   r[   ry   ry      sR     #D/" Iz HjGZHj'" #rZ   ry   c                  L    \ rS rSr% SrS\S'   S\S'   S\S'   S\S'   S\S	'   S
rg)ToolOutputFileContentDict   z0TypedDict variant for file content tool outputs.r|   rP   rw   r}   r~   rh   r   rR   Nr_   rR   rZ   r[   r   r      s#    :
rZ   r   z*TypeAdapter[ValidToolOutputPydanticModels](ValidToolOutputPydanticModelsTypeAdapterc                  $    \ rS rSrSrSrSrSrSrg)ToolOriginType   zAEnumerates the runtime source of a function-tool-backed run item.functionmcpagent_as_toolrR   N)	rS   rT   rU   rV   rW   FUNCTIONMCPAGENT_AS_TOOLrY   rR   rZ   r[   r   r      s    KH
C#MrZ   r   T)frozenc                  l    \ rS rSr% SrS\S'   SrS\S'   SrS\S'   SrS\S	'   SS
 jr	\
SS j5       rSrg)
ToolOrigin   zMSerializable metadata describing where a function-tool-backed item came from.r   rP   Nrf   mcp_server_name
agent_nameagent_tool_namec                    SU R                   R                  0nU R                  b  U R                  US'   U R                  b  U R                  US'   U R                  b  U R                  US'   U$ )z/Convert the metadata to a JSON-compatible dict.rP   r   r   r   )rP   valuer   r   r   )rp   results     r[   to_json_dictToolOrigin.to_json_dict   sk    "($))//!:+(,(<(<F$%??&#'??F< +(,(<(<F$%rZ   c                   ^ [        T[        5      (       d  gTR                  S5      n[        U[        5      (       d  g [	        U5      nSU4S jjnU " UU" S5      U" S5      U" S5      S9$ ! [
         a     gf = f)	z;Deserialize tool origin metadata from JSON-compatible data.NrP   c                X   > TR                  U 5      n[        U[        5      (       a  U$ S $ N)get
isinstancerQ   )keyr   datas     r[   _optional_string3ToolOrigin.from_json_dict.<locals>._optional_string   s'    HHSME&uc225<<rZ   r   r   r   )rP   r   r   r   )r   rQ   rs   rf   )r   r   r   rQ   r   rn   )clsr   raw_typeorigin_typer   s    `   r[   from_json_dictToolOrigin.from_json_dict   s     $((88F#(C((	(2K	= ,->?'5,->?	
 	
  		s    A. .
A;:A;rR   )rs   zdict[str, str])r   r   rs   ToolOrigin | None)rS   rT   rU   rV   rW   rX   r   r   r   r   classmethodr   rY   rR   rZ   r[   r   r      sB    W
"&OZ&!J
!"&OZ&	 
 
rZ   r   	ComputerT)boundComputerT_co)r   	covariantComputerT_contra)r   contravariantc                  "    \ rS rSrSrSS jrSrg)ComputerCreate   z3Initializes a computer for the current run context.c                   g r   rR   )rp   run_contexts     r[   __call__ComputerCreate.__call__   s    `crZ   rR   N)r   RunContextWrapper[Any]rs   zMaybeAwaitable[ComputerT_co]rS   rT   rU   rV   rW   r   rY   rR   rZ   r[   r   r      s    =crZ   r   c                  .    \ rS rSrSr      SS jrSrg)ComputerDispose   z3Cleans up a computer initialized for a run context.c                   g r   rR   )rp   r   computers      r[   r   ComputerDispose.__call__   s    
  #rZ   rR   N)r   r   r   r   rs   zMaybeAwaitable[None]r   rR   rZ   r[   r   r      s(    =# ,# #	#
 
#rZ   r   c                  2    \ rS rSr% SrS\S'   SrS\S'   Srg)	ComputerProvider   zJConfigures create/dispose hooks for per-run computer lifecycle management.zComputerCreate[ComputerT]createNz!ComputerDispose[ComputerT] | NonedisposerR   )rS   rT   rU   rV   rW   rX   r   rY   rR   rZ   r[   r   r      s    T%%15G.5rZ   r   c                  `    \ rS rSr% S\S'    S\S'    S\S'    \" \S9rS	\S
'    SrS\S'   Sr	g)FunctionToolResulti  FunctionTooltoolr   outputzRunItem | Nonerun_itemdefault_factoryzlist[ToolApprovalItem]interruptionsNagent_run_resultrR   )
rS   rT   rU   rV   rX   r   listr   r   rY   rR   rZ   r[   r   r     sA    
 K!
 -2$,GM)GC c 6rZ   r   c                     \ rS rSr% SrS\S'    S\S'    S\S'    S\S	'    S
rS\S'    S
rS\S'    SrS\S'    Sr	S\S'    Sr
S\S'    SrS\S'    SrS\S'    SrS\S'    SrS\S'    \" SS
SS9rS\S '    \" S
S
SS9rS\S!'    \" SS
SS9rS\S"'    \" SS
SS9rS\S#'    \" SS
SS9rS$\S%'    \" SS
SS9rS&\S''    \" SS
SS9rS&\S('    \" SS
SS9rS&\S)'    \" SS
SS9rS*\S+'    \" S
S
SS9rS\S,'    \S1S- j5       rS. rS2S/ jrS0rg)3r   i  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.
rQ   namedescriptiondict[str, Any]params_json_schema1Callable[[ToolContext[Any], str], Awaitable[Any]]on_invoke_toolTboolstrict_json_schemaJbool | Callable[[RunContextWrapper[Any], AgentBase], MaybeAwaitable[bool]]
is_enabledN$list[ToolInputGuardrail[Any]] | Nonetool_input_guardrails%list[ToolOutputGuardrail[Any]] | Nonetool_output_guardrailsFObool | Callable[[RunContextWrapper[Any], dict[str, Any], str], Awaitable[bool]]needs_approvalfloat | Nonetimeout_secondsrH   ToolTimeoutBehaviortimeout_behaviorToolErrorFunction | Nonetimeout_error_functiondefer_loading)defaultkw_onlyrepr_failure_error_function#_use_default_failure_error_function_is_agent_tool_is_codex_toolr   _agent_instancerf   _tool_namespace_tool_namespace_description
_mcp_titler   _tool_origin_emit_tool_originc                f    [        U R                  [        U 5      5      =(       d    U R                  $ )zEReturn the public qualified name used to identify this function tool.)r.   r   r-   ro   s    r[   qualified_nameFunctionTool.qualified_name  s*      		+OPT+UVcZ^ZcZc	
rZ   c                    [        U R                  SS 5      n[        U5      (       a  U" U 5      U l        U R                  (       a  [	        U R
                  5      U l        [        U 5        g )N__agents_bind_function_tool__)getattrr   callabler   r<   r   &_validate_function_tool_timeout_config)rp   bind_to_function_tools     r[   __post_init__FunctionTool.__post_init__  sV     '(;(;=\^b c)**"7"=D""&?@W@W&XD#.t4rZ   c           	        [         R                  " U 5      n[         R                  " [        5       Vs1 s H  o"R                  iM     nn[         R                  " [        5       H?  nUR
                  (       a  M  [        XR                  [        XR                  5      5        MA     U R                  R                  5        H  u  pEXC;  d  M  [        XU5        M     U$ s  snf r   )
dataclassesreplacefieldsr   r   initsetattrr   __dict__items)rp   copied_tool
tool_fielddataclass_field_names	attr_name
attr_values         r[   __copy__FunctionTool.__copy__  s    !))$/CNCUCUVbCc dCcZCc d%,,\:JK'$2PQ ; &*]]%8%8%:!I5
; &;  !es   C)r   r   rs   rQ   )rs   r   )rS   rT   rU   rV   rW   rX   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   propertyr   r   r  rY   rR   rZ   r[   r   r     s    IX9&&4EE
  $#= ^bJZa$ CG?FMDHAHM 	 W% %)O\(>,=)= 8<4;[M4`8=95 
 U051' 
 T 5INDID 5INDIH t%HOSHO"'d"OOZOY.3D$UZ.[[V"4EJJ
JD&+D$U&SL#SW#D$UKtKY
 
5
rZ   r   c                  T    \ rS rSrSrSS.       S	S jjr    S
S jrSS jrSrg)#_FailureHandlingFunctionToolInvokeri  zOInternal callable that rebinds wrapper error handling for copied FunctionTools.Nfunction_toolc               (    Xl         X l        X0l        g r   )_invoke_tool_impl_on_handled_error_function_tool)rp   invoke_tool_implon_handled_errorr  s       r[   __init__,_FailureHandlingFunctionToolInvoker.__init__  s     "2!1+rZ   c                    U R                   UL a  U $ [        U R                  U R                  US9n[	        U [
        S5      (       a  [        U[
        S5        U$ )Nr  FT)r  r  r  r  r   _SYNC_FUNCTION_TOOL_MARKERr  )rp   r  bound_invokers      r[   r   A_FailureHandlingFunctionToolInvoker.__agents_bind_function_tool__  s[     -/K;""""'

 43U;;M#=tDrZ   c                  #     U R                  X5      I S h  vN $  N! [         aY  nU R                  c   e[        U R                  UUS9I S h  vN  nUc  e U R	                  U R                  X25        Us S nA$ S nAff = f7f)N)r  contexterror)r  	Exceptionr  1maybe_invoke_function_tool_failure_error_functionr  )rp   ctxinputer   s        r[   r   ,_FailureHandlingFunctionToolInvoker.__call__  s     	//;;;; 	&&222L"11  F
 ~""4#6#6AM	sH   B  B 
B'A=A&A=7B8B=BB)r  r  r  )r  r   r  .Callable[[FunctionTool, Exception, str], None]r  zFunctionTool | Noners   None)r  r   rs   r  r&  ToolContext[Any]r'  rQ   rs   r   )	rS   rT   rU   rV   rW   r  r   r   rY   rR   rZ   r[   r  r    sP    Y .2	,K	, I	,
 +	, 
	,)	,rZ   r  c                    [        X5      $ )zVWrap a tool invoker so copied FunctionTools resolve failure policy against themselves.)r  )r  r  s     r[   (with_function_tool_failure_error_handlerr/    s    
 //?RRrZ   rH   )failure_error_functionr   r   r   r   r   r   r   r   r   sync_invoker	mcp_titletool_originc                    [        UU5      nU(       a  [        U[        S5        [        [	        U UUUUUUU	U
UUUUUUS9U5      $ )zQCreate a FunctionTool with copied-tool-aware failure handling bound in one place.T)r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   )r/  r  r  (set_function_tool_failure_error_functionr   )r   r   r   r  r  r0  r   r   r   r   r   r   r   r   r   r1  r2  r3  r   s                      r[   _build_wrapped_function_toolr6    sm    0 >N  :DA3#1)1!"7#9)+-#9' $	
" 	% rZ   c                z    U R                   (       d  gU R                  =(       d    [        [        R                  S9$ )z2Return scalar origin metadata for a function tool.NrP   )r   r   r   r   r   r  s    r[   get_function_tool_originr9    s*    **%%Q9P9P)QQrZ   c                  v    \ rS rSr% SrS\S'    SrS\S'    SrS	\S
'    SrS\S'    Sr	S\S'    \
S 5       rSrg)FileSearchTooli  zA hosted tool that lets the LLM search through a vector store. Currently only supported with
OpenAI models, using the Responses API.
	list[str]vector_store_idsN
int | Nonemax_num_resultsFr   include_search_resultszRankingOptions | Noneranking_optionszFilters | Nonefiltersc                    g)Nfile_searchrR   ro   s    r[   r   FileSearchTool.name)      rZ   rR   )rS   rT   rU   rV   rW   rX   r?  r@  rA  rB  r  r   rY   rR   rZ   r[   r;  r;    sZ      1"&OZ&2#(D(R-1O*1%"G^"5 rZ   r;  c                  j    \ rS rSr% SrSrS\S'    SrS\S'    SrS	\S
'    Sr	S\S'    \
S 5       rSrg)WebSearchTooli.  zvA hosted tool that lets the LLM search the web. Currently only supported with OpenAI models,
using the Responses API.
NzUserLocation | Noneuser_locationzWebSearchToolFilters | NonerB  mediumz Literal['low', 'medium', 'high']search_context_sizezbool | Noneexternal_web_accessc                    g)N
web_searchrR   ro   s    r[   r   WebSearchTool.nameD      rZ   rR   )rS   rT   rU   rV   rW   rI  rX   rB  rK  rL  r  r   rY   rR   rZ   r[   rH  rH  .  sX     *.M&-d+/G(/5<D9D6'++  rZ   rH  )eqc                  `    \ rS rSr% SrS\S'    SrS\S'    SS jr\S	 5       r	\S
 5       r
Srg)ComputerTooliI  zIA local computer harness exposed through the Responses API computer tool.zCComputerT | ComputerCreate[ComputerT] | ComputerProvider[ComputerT]r   NzDCallable[[ComputerToolSafetyCheckData], MaybeAwaitable[bool]] | Noneon_safety_checkc                    [        U 5        g r   )_store_computer_initializerro   s    r[   r   ComputerTool.__post_init__S  s
    #D)rZ   c                    g)Ncomputer_use_previewrR   ro   s    r[   r   ComputerTool.nameV  s    
 &rZ   c                    g)Nr   rR   ro   s    r[   
trace_nameComputerTool.trace_name]  s     rZ   rR   rs   r+  )rS   rT   rU   rV   rW   rX   rT  r   r  r   r\  rY   rR   rZ   r[   rS  rS  I  sI    SQQU\`OY`G* & &  rZ   rS  c                  .    \ rS rSr% S\S'   SrS\S'   Srg)_ResolvedComputeric  ComputerLiker   Nz$ComputerDispose[ComputerLike] | Noner   rR   )rS   rT   rU   rV   rX   r   rY   rR   rZ   r[   r`  r`  c  s    48G18rZ   r`  zrweakref.WeakKeyDictionary[ComputerTool[Any], weakref.WeakKeyDictionary[RunContextWrapper[Any], _ResolvedComputer]]_computer_cachez<weakref.WeakKeyDictionary[ComputerTool[Any], ComputerConfig]_computer_initializer_mapz]weakref.WeakKeyDictionary[RunContextWrapper[Any], dict[ComputerTool[Any], _ResolvedComputer]]_computers_by_run_contextc                z  #    [         R                  U 5      nUc  [        R                  " 5       nU[         U '   UR                  U5      nUb  [	        XUS9  UR
                  $ [        U 5      n[        U5      (       a  [        [        [           U5      OSnSnU(       a  UR                  OSnUb  UR                  nOf[        U5      (       a  UnOS[        U R
                  5      (       a9  [        [        [           U R
                  5      nUR                  nUR                  nU(       a.  U" US9n	[        R                  " U	5      (       a
  U	I Sh  vN OU	n
O[        [         U R
                  5      n
[#        U
[$        [&        -  5      (       d  [)        S5      e[+        XS9nXU'   [	        XUS9  Xl        U
$  Ng7f)zFResolve a computer for a given run context, initializing it if needed.N)r   r   resolved)r   z6The computer tool did not provide a computer instance.)r   r   )rb  r   weakrefWeakKeyDictionary_track_resolved_computerr   _get_computer_initializer_is_computer_providerr   r   r   r   r   r   inspectisawaitablera  r   r2   r1   r7   r`  )r   r   per_contextcachedinitializer_config	lifecycleinitializerdisposerlifecycle_providercomputer_candidater   rf  s               r[   resolve_computerrv  u  s     "%%d+K//1 +__[)F dfU248 !!344 	c"$67 
 /3KAJI,=,=PTH&&	$	%	%(	t}}	-	-!"23"7G(//%--([A ""#566 %$$# 	 dmm4h= 899PQQ (EH'$(SMO %s   EF;F9A(F;c                :  #    [         R                  U S5      nU(       d  g/ nUR                  5        Hy  u  p4[        R	                  U5      nUb  UR                  U S5        [        U5      nUb  Xcl        UR                  c  MR  UR                  UR                  UR                  45        M{     U H3  u  px U" XS9n	[        R                  " U	5      (       a  U	I Sh  vN   M3  M5     g N! [         a"  n
[        R                  " SU
5         Sn
A
Ma  Sn
A
ff = f7f)zDDispose any computer instances created for the provided run context.N)r   r   z.Failed to dispose computer for run context: %s)rd  popr  rb  r   rj  r   r   appendrl  rm  r$  r:   warning)r   resolved_by_tool	disposersr   	_resolvedrn  rr  r   r   r   excs              r[   dispose_resolved_computersr    s     044[$GJLI+113%))$/"OOK./5"'M(i//1C1CDE 4 '	RHF""6** + '  	RNNKSQQ	RsH   A?D2D8&C,C*C,#D*C,,
D6DDDDc                  H    \ rS rSr% SrS\S'    S\S'    S\S'    S	\S
'   Srg)ComputerToolSafetyCheckDatai  z/Information about a computer tool safety check.r   ctx_wrapperz
Agent[Any]agentr   	tool_callr   safety_checkrR   Nr_   rR   rZ   r[   r  r    s)    9''3''!$$2rZ   r  c                  0    \ rS rSr% SrS\S'    S\S'   Srg)	MCPToolApprovalRequesti  z!A request to approve a tool call.r   r  r   r   rR   Nr_   rR   rZ   r[   r  r    s    +''
6rZ   r  c                  0    \ rS rSr% SrS\S'    S\S'   Srg)	MCPToolApprovalFunctionResulti  z,The result of an MCP tool approval function.r   approverw   reasonrR   Nr_   rR   rZ   r[   r  r    s    6M+*rZ   r  ShellActionRequestc                  0    \ rS rSr% SrS\S'    S\S'   Srg)	ShellOnApprovalFunctionResulti  z0The result of a shell tool on_approval callback.r   r  rw   r  rR   Nr_   rR   rZ   r[   r  r    s    :M+*rZ   r  rF   c                  0    \ rS rSr% SrS\S'    S\S'   Srg)	"ApplyPatchOnApprovalFunctionResulti  z7The result of an apply_patch tool on_approval callback.r   r  rw   r  rR   Nr_   rR   rZ   r[   r  r    s    AM+*rZ   r  c                  0    \ rS rSr% SrS\S'    S\S'   Srg)	"CustomToolOnApprovalFunctionResulti&  z1The result of a custom tool on_approval callback.r   r  rw   r  rR   Nr_   rR   rZ   r[   r  r  &  s    ;M+*rZ   r  c                  F    \ rS rSr% SrS\S'    SrS\S'    \S 5       rS	r	g)
HostedMCPTooli8  a  A tool that allows the LLM to use a remote MCP server. The LLM will automatically list and
call tools, without requiring a round trip back to your code.
If you want to run MCP servers locally via stdio, in a VPC or other non-publicly-accessible
environment, or you just prefer to run tool calls locally, then you can instead use the servers
in `agents.mcp` and pass `Agent(mcp_servers=[...])` to the agent.r"   tool_configNzMCPToolApprovalFunction | Noneon_approval_requestc                    g)N
hosted_mcprR   ro   s    r[   r   HostedMCPTool.nameH  rP  rZ   rR   )
rS   rT   rU   rV   rW   rX   r  r  r   rY   rR   rZ   r[   r  r  8  s8    I P:>7>   rZ   r  c                  6    \ rS rSr% SrS\S'    \S 5       rSrg)CodeInterpreterTooliM  zFA tool that allows the LLM to execute code in a sandboxed environment.r    r  c                    g)Ncode_interpreterrR   ro   s    r[   r   CodeInterpreterTool.nameT      !rZ   rR   N	rS   rT   rU   rV   rW   rX   r  r   rY   rR   rZ   r[   r  r  M  s     P  K" "rZ   r  c                  6    \ rS rSr% SrS\S'    \S 5       rSrg)ImageGenerationTooliY  z.A tool that allows the LLM to generate images.r!   r  c                    g)Nimage_generationrR   ro   s    r[   r   ImageGenerationTool.name`  r  rZ   rR   Nr  rR   rZ   r[   r  r  Y  s     8  ;" "rZ   r  c                  0    \ rS rSr% SrS\S'    S\S'   Srg)	LocalShellCommandRequestie  z*A request to execute a command on a shell.r   r  r   r   rR   Nr_   rR   rZ   r[   r  r  e  s    4''
2rZ   r  c                  6    \ rS rSr% SrS\S'    \S 5       rSrg)LocalShellToolit  zA tool that allows the LLM to execute commands on a shell.

For more details, see:
https://platform.openai.com/docs/guides/tools-local-shell
LocalShellExecutorexecutorc                    g)Nlocal_shellrR   ro   s    r[   r   LocalShellTool.name  rF  rZ   rR   Nr  rR   rZ   r[   r  r  t  s$     ! 8 rZ   r  c                  8    \ rS rSr% SrS\S'   S\S'   S\S'   Srg)	ShellToolLocalSkilli  z,Skill metadata for local shell environments.rQ   r   r   pathrR   Nr_   rR   rZ   r[   r  r    s    6
I
IrZ   r  c                  8    \ rS rSr% SrS\S'   S\S'   S\S'   S	rg
)ShellToolSkillReferencei  z"Reference to a hosted shell skill.zLiteral['skill_reference']rP   rQ   skill_idrw   versionrR   Nr_   rR   rZ   r[   r  r    s    ,
$$MrZ   r  c                  8    \ rS rSr% SrS\S'   S\S'   S\S'   S	rg
)ShellToolInlineSkillSourcei  zInline skill source payload.rQ   r   zLiteral['application/zip']
media_typezLiteral['base64']rP   rR   Nr_   rR   rZ   r[   r  r    s    &
I**
rZ   r  c                  B    \ rS rSr% SrS\S'   S\S'   S\S'   S\S	'   S
rg)ShellToolInlineSkilli  z!Inline hosted shell skill bundle.rQ   r   r   r  sourcezLiteral['inline']rP   rR   Nr_   rR   rZ   r[   r  r    s    +
I&&
rZ   r  c                  8    \ rS rSr% SrS\S'   S\S'   S\S'   Srg)	+ShellToolContainerNetworkPolicyDomainSecreti  z4A secret bound to a single domain in allowlist mode.rQ   domainr   r   rR   Nr_   rR   rZ   r[   r  r    s    >K
IJrZ   r  c                  8    \ rS rSr% SrS\S'   S\S'   S\S'   S	rg
)(ShellToolContainerNetworkPolicyAllowlisti  z/Allowlist network policy for hosted containers.r<  allowed_domainszLiteral['allowlist']rP   z>NotRequired[list[ShellToolContainerNetworkPolicyDomainSecret]]domain_secretsrR   Nr_   rR   rZ   r[   r  r    s    9
RRrZ   r  c                  $    \ rS rSr% SrS\S'   Srg)'ShellToolContainerNetworkPolicyDisabledi  z.Disabled network policy for hosted containers.zLiteral['disabled']rP   rR   Nr_   rR   rZ   r[   r  r    s    8
rZ   r  c                  .    \ rS rSr% SrS\S'   S\S'   Srg)	ShellToolLocalEnvironmenti  z"Local shell execution environment.zLiteral['local']rP   z&NotRequired[list[ShellToolLocalSkill]]skillsrR   Nr_   rR   rZ   r[   r  r    s    ,
22rZ   r  c                  L    \ rS rSr% SrS\S'   S\S'   S\S'   S	\S
'   S\S'   Srg)!ShellToolContainerAutoEnvironmenti  z.Auto-provisioned hosted container environment.zLiteral['container_auto']rP   zNotRequired[list[str]]file_idsz5NotRequired[Literal['1g', '4g', '16g', '64g'] | None]memory_limitz,NotRequired[ShellToolContainerNetworkPolicy]network_policyz*NotRequired[list[ShellToolContainerSkill]]r  rR   Nr_   rR   rZ   r[   r  r    s#    8
##$$GG@@66rZ   r  c                  .    \ rS rSr% SrS\S'   S\S'   Srg)	&ShellToolContainerReferenceEnvironmenti  z*Reference to an existing hosted container.zLiteral['container_reference']rP   rQ   container_idrR   Nr_   rR   rZ   r[   r  r    s    4
((rZ   r  c                  2    \ rS rSr% SrS\S'   SrS\S'   Srg)	ShellCallOutcomei  z4Describes the terminal condition of a shell command.zLiteral['exit', 'timeout']rP   Nr>  	exit_coderR   )rS   rT   rU   rV   rW   rX   r  rY   rR   rZ   r[   r  r    s    >
$$ Iz rZ   r  c                      \ rS rSr% SrSrS\S'   SrS\S'   \" S S9r	S	\S
'   Sr
S\S'   SrS\S'   \SS j5       r\SS j5       rSrg)ShellCommandOutputi  z7Structured output for a single shell command execution. rQ   stdoutstderrc                     [        SS9$ )Nexitr8  )r  rR   rZ   r[   <lambda>ShellCommandOutput.<lambda>  s    >NTZ>[rZ   r   r  outcomeNrf   commanddict[str, Any] | Noneprovider_datac                .    U R                   R                  $ r   )r  r  ro   s    r[   r  ShellCommandOutput.exit_code  s    ||%%%rZ   c                >    U R                   R                  S:X  a  S$ S$ )Ntimeout	completed)r  rP   ro   s    r[   statusShellCommandOutput.status  s     LL--:yKKrZ   rR   )rs   r>  )rs   zLiteral['completed', 'timeout'])rS   rT   rU   rV   rW   r  rX   r  r   r  r  r  r  r  r  rY   rR   rZ   r[   r  r    sg    AFCFC %6[ \G\GZ+/M(/& & L LrZ   r  c                  @    \ rS rSr% SrS\S'   SrS\S'   SrS\S	'   S
rg)ShellResulti  z$Result returned by a shell executor.zlist[ShellCommandOutput]r   Nr>  max_output_lengthr  r  rR   )	rS   rT   rU   rV   rW   rX   r  r  rY   rR   rZ   r[   r  r    s!    .$$$(z(+/M(/rZ   r  c                  @    \ rS rSr% SrS\S'   SrS\S'   SrS\S'   S	rg)
r  i
  z0Action payload for a next-generation shell call.r<  commandsNr>  
timeout_msr  rR   )	rS   rT   rU   rV   rW   rX   r  r  rY   rR   rZ   r[   r  r  
  s     :!J
!$(z(rZ   c                  J    \ rS rSr% SrS\S'   S\S'   SrS\S	'   SrS
\S'   Srg)ShellCallDatai  z7Normalized shell call data provided to shell executors.rQ   call_idr  actionNz*Literal['in_progress', 'completed'] | Noner  z
Any | NonerawrR   )	rS   rT   rU   rV   rW   rX   r  r  rY   rR   rZ   r[   r  r    s%    AL9=F6=CrZ   r  c                  .    \ rS rSr% SrS\S'   S\S'   Srg)	ShellCommandRequesti  z)A request to execute a modern shell call.r   r  r  r   rR   Nr_   rR   rZ   r[   r  r    s    3''
rZ   r  c                    U c  SS0$ [        U [        5      (       d  [        S5      e[        U 5      nSU;  a  SUS'   [	        [
        U5      $ )z=Normalize shell environment into a predictable mapping shape.rP   localz(ShellTool environment must be a mapping.)r   r   r7   dictr   ShellToolEnvironment)environment
normalizeds     r[   !_normalize_shell_tool_environmentr  )  sX       k7++BCCk"JZ$
6$j11rZ   c                      \ rS rSr% SrSrS\S'   SrS\S'   S	rS
\S'    Sr	S\S'    Sr
S\S'    SS jr\SS j5       rSrg)	ShellTooli8  zONext-generation shell tool. LocalShellTool will be deprecated in favor of this.NzShellExecutor | Noner  shellrQ   r   Fzbool | ShellApprovalFunctionr   zShellOnApprovalFunction | Noneon_approvalShellToolEnvironment | Noner  c                   [        U R                  5      nXl        US   nUS:X  a  U R                  c  [        S5      egU R                  b  [        S5      eU R                  SLd  U R
                  b  [        S5      eSU l        SU l        g)zCValidate shell tool configuration and normalize environment fields.rP   r  Nz6ShellTool with local environment requires an executor.z>ShellTool with hosted environment does not accept an executor.FzQShellTool with hosted environment does not support needs_approval or on_approval.)r  r  r  r7   r   r  )rp   normalized_environmentenvironment_types      r[   r   ShellTool.__post_init__O  s    !B4CSCS!T11&9w&}}$ XYY==$\]]e+t/?/?/Kc  $rZ   c                    g)Nr  rR   ro   s    r[   rP   ShellTool.typec  s    rZ   )r  r   r  r^  r  )rS   rT   rU   rV   rW   r  rX   r   r   r  r  r   r  rP   rY   rR   rZ   r[   r  r  8  sg    Y%)H")D#38N08 37K/6 04K,3
 (  rZ   r  c                  f    \ rS rSr% SrS\S'   SrS\S'   SrS	\S
'    SrS\S'    \	SS j5       r
Srg)ApplyPatchToolih  zQHosted apply_patch tool. Lets the model request file mutations via unified diffs.r3   editorapply_patchrQ   r   Fz!bool | ApplyPatchApprovalFunctionr   Nz#ApplyPatchOnApprovalFunction | Noner  c                    g)Nr	  rR   ro   s    r[   rP   ApplyPatchTool.typez  rF  rZ   rR   r  )rS   rT   rU   rV   rW   rX   r   r   r  r  rP   rY   rR   rZ   r[   r  r  h  sK    [D#8=N5= 8<K4;  rZ   r  c                      \ rS rSr% SrS\S'   S\S'   S\S'   SrS	\S
'   SrS\S'    SrS\S'    Sr	S\S'   \
" SSS9rS\S'   SS jrSS jrSS jr\SS j5       rSrg)
CustomTooli  zQA Responses custom tool that uses one raw string input instead of JSON arguments.rQ   r   r   CustomToolExecutorr   Nobject | NoneformatF!bool | CustomToolApprovalFunctionr   #CustomToolOnApprovalFunction | Noner  r   r   )r  r   r   r  c                    SU R                   U R                  S.nU R                  b  U R                  US'   U R                  (       a  SUS'   Xl        g )Ncustom)rP   r   r   r  Tr   )r   r   r  r   r  )rp   r  s     r[   r   CustomTool.__post_init__  sO    II++(

 ;;"$(KKK!+/K(&rZ   c                    U R                   $ )zDReturn the callable/bool approval setting used by runtime execution.)r   ro   s    r[   runtime_needs_approval!CustomTool.runtime_needs_approval  s    """rZ   c                    U R                   $ )z7Return the approval callback used by runtime execution.)r  ro   s    r[   runtime_on_approvalCustomTool.runtime_on_approval  s    rZ   c                    g)Nr  rR   ro   s    r[   rP   CustomTool.type  s    rZ   )r  r^  )rs   r  )rs   r  r  )rS   rT   rU   rV   rW   rX   r  r   r  r   r   r  r   r  r  r  rP   rY   rR   rZ   r[   r  r    sz    [
I&& FM 8=N5=K7;K4;OM4#(e%#@K@
'#   rZ   r  c                  X    \ rS rSr% SrSrS\S'   SrS\S'   SrS\S	'   \	SS
 j5       r
Srg)ToolSearchTooli  zA hosted Responses API tool that lets the model search deferred tools by namespace.

`execution="client"` is supported for manual Responses orchestration, but the standard
OpenAI Agents runner does not auto-execute client tool search calls.
Nrf   r   z"Literal['server', 'client'] | None	executionr  
parametersc                    g)Ntool_searchrR   ro   s    r[   r   ToolSearchTool.name  rF  rZ   rR   r  )rS   rT   rU   rV   rW   r   rX   r   r!  r  r   rY   rR   rZ   r[   r  r    s:     #K"48I18 $J$ rZ   r  c                   [        U [        5      (       a  U R                  5       (       d  [        S5      e[        U[        5      (       a  UR                  5       (       d  [        S5      e[	        S U 5       5      (       a  [        S5      eU R                  5       nUR                  5       n/ nU HL  n[        UR                  U5        [        R                  " U5      nX7l        XGl	        UR                  U5        MN     U$ )zMAttach namespace metadata to function tools for OpenAI Responses tool search.z5tool_namespace() requires a non-empty namespace name.z2tool_namespace() requires a non-empty description.c              3  L   #    U  H  n[        U[        5      (       + v   M     g 7fr   )r   r   .0r   s     r[   	<genexpr>!tool_namespace.<locals>.<genexpr>  s     
@%$z$---%s   "$z6tool_namespace() only supports FunctionTool instances.)r   rQ   stripr7   anyr0   r   copyr   r   ry  )r   r   toolsnamespace_namenormalized_descriptionnamespaced_toolsr   namespaced_tools           r[   tool_namespacer3    s     dC  

OPPk3''{/@/@/B/BLMM

@%
@@@PQQZZ\N(..0+-.tyy.I))D/*8'6L30  rZ   c                    / n[        U 5      b  UR                  S5        U R                  (       a  UR                  S5        [        U5      $ )z7Return Responses-only features used by a function tool.ztool_namespace()zdefer_loading=True)r-   ry  r   tuple)r   featuress     r[   )get_function_tool_responses_only_featuresr7    s?    H+D1=*+,-?rZ   c          	         [        U 5      nU(       d  gU R                  n[        SSR                  U5       SU SU S35      e)zEReject Responses-only function-tool features on unsupported backends.NzVThe following function-tool features are only supported with OpenAI Responses models: , z. Tool `z` cannot be used with .)r7  r   r7   join)r   backend_nameunsupported_features	tool_names       r[   5ensure_function_tool_supports_responses_only_featuresr?    s\     ETJ##I
	99123 41,q	B rZ   c                   g)zBBackend-specific converters should validate reserved tool choices.NrR   )tool_choicer<  s     r[   #ensure_tool_choice_supports_backendrB     s     rZ   c                    [        U [        5      (       a   U R                  =(       d    [        U 5      SL$ [        U [        5      (       a$  [        U R                  R                  S5      5      $ g)zLReturn True when a tool can be exposed through hosted Responses tool search.Nr   F)r   r   r   r-   r  r   r  r   r   s    r[    is_responses_tool_search_surfacerE  	  sX    $%%!![%I$%OW[%[[$&&D$$((9::rZ   c                &    [        S U  5       5      $ )zJReturn True when tool search has at least one eligible searchable surface.c              3  8   #    U  H  n[        U5      v   M     g 7fr   )rE  r'  s     r[   r)  4has_responses_tool_search_surface.<locals>.<genexpr>  s     H%$/55%   r,  r.  s    r[   !has_responses_tool_search_surfacerL    s    H%HHHrZ   c                    [        U [        5      (       a  U R                  $ [        U [        5      (       a$  [	        U R
                  R                  S5      5      $ g)zDReturn True when a tool requires ToolSearchTool() to stay reachable.r   F)r   r   r   r  r   r  r   rD  s    r[   is_required_tool_search_surfacerN    sG    $%%!!!$&&D$$((9::rZ   c                &    [        S U  5       5      $ )z?Return True when any enabled surface requires ToolSearchTool().c              3  8   #    U  H  n[        U5      v   M     g 7fr   )rN  r'  s     r[   r)  3has_required_tool_search_surface.<locals>.<genexpr>"  s     G.t44rI  rJ  rK  s    r[    has_required_tool_search_surfacerR     s    GGGGrZ   )allow_opaque_search_surfacec               Z   U  Vs/ s H  n[        U[        5      (       d  M  UPM     nn[        U5      nUS:  n[        U 5      n[	        U 5      nUS:  a  [        S5      e[        U 5        U(       a  U(       d  [        S5      eU(       a  U(       d  U(       d  [        S5      egggs  snf )zCValidate the Responses-only tool_search and defer-loading contract.r   r+   zHOnly one ToolSearchTool() is allowed when using OpenAI Responses models.z]Deferred-loading Responses tools require ToolSearchTool() when using OpenAI Responses models.a  ToolSearchTool() requires at least one searchable Responses surface: a tool_namespace(...) function tool, a deferred-loading function tool (`function_tool(..., defer_loading=True)`), or a deferred-loading hosted MCP server (`HostedMCPTool(tool_config={..., 'defer_loading': True})`).N)r   r  lenrL  rR  r7   r/   )r.  rS  r   tool_search_toolstool_search_counthas_tool_searchhas_tool_search_surfacehas_required_tool_searchs           r[   ,validate_responses_tool_search_configurationr[  %  s     +0T%$:dN3S%T-.'!+O?F?F1bcc/6 
 	
 6?ZR
 	
 @[6 Us
   B(B(c                    U $ )a  Preserve explicit ToolSearchTool entries until request conversion validates them.

Whether a tool_search definition is valid can depend on prompt-managed surfaces that are
only known during request conversion, so pruning here hides misconfiguration instead of
surfacing a clear error.
rR   rK  s    r[    prune_orphaned_tool_search_toolsr]  B  s	     LrZ   c                    U nUbE  [        U[        R                  5      (       a  U$ UR                  =(       d    UR                  nUb  ME  g r   )r   jsonJSONDecodeError	__cause____context__)r#  currents     r[   _extract_json_decode_errorrd  L  sH    $)G

gt3344N##:w':': 
 rZ   c                    [        U [        5      (       d  g [        U 5      R                  S5      (       d  g [	        U 5      $ )NzInvalid JSON input for tool)r   r5   rQ   
startswithrd  r#  s    r[   !_extract_tool_argument_json_errorrh  U  s7    e/00u:  !>??%e,,rZ   )"span_message_for_json_decode_errorinclude_input_json_in_logs!include_tool_name_in_log_messagesc                (   ^ ^^^^ SUUUU U4S jjnU$ )zECreate a consistent handled-error reporter for wrapped FunctionTools.c                  > [        U5      nUb  Tb  Tn[        U5      nOT
n[        U5      n[        R                  " [	        UU R
                  US.S95        T(       a  T	 SU R
                   3OT	n[        R                  (       a  [        R                  " U S35        g T(       a  [        R                  " U SU SU 3US9  g [        R                  " U SU 3US9  g )N)r>  r#  )messager    z failedz	 failed: )exc_info)rh  rQ   rA   attach_error_to_current_spanr@   r   r,   DONT_LOG_TOOL_DATAr:   debugr#  )r  r#  
input_jsonjson_decode_errorresolved_span_messagespan_error_detail
log_prefixrj  rk  	log_labelspan_messageri  s          r[   r  E_build_handled_function_tool_error_handler.<locals>._on_handled_errorg  s    =eD(-O-[$F! #$5 6$0! #E
33-!.!3!3.	
 4Uyk=--./Zc 	 $$LLJ<w/0%LLJ<yAeWEPUVLLJ<y85IrZ   )r  r   r#  r$  rt  rQ   rs   r+  rR   )rz  ry  ri  rj  rk  r  s   ````` r[   *_build_handled_function_tool_error_handlerr|  ]  s    J J> rZ   c                     U(       a  [         R                  " U5      $ 0 $ ! [         ab  n[        R                  (       a  [
        R                  " SU  35        O[
        R                  " SU  SU 35        [        SU  SU 35      UeSnAff = f)z6Decode raw tool arguments with consistent diagnostics.Invalid JSON input for tool : N)r_  loadsr$  r,   rr  r:   rs  r5   )r>  rt  r~  s      r[   _parse_function_tool_json_inputr    s    d)3tzz*%;; d$$LL7	{CDLL7	{"ZLQR #?	{"ZL!YZ`ccds   ! ! 
BABBc                    [         R                  (       a  [        R                  " SU  35        g[        R                  " SU  SU 35        g)zELog the start of a tool invocation with the current redaction policy.zInvoking tool z with input N)r,   rr  r:   rs  r>  rt  s     r[   _log_function_tool_invocationr    s7      ~i[12~i[ZLIJrZ   c                D    [        U5      nUb  SU 3$ S[        U5       3$ )zLThe default tool error function, which just returns a generic error message.zYAn error occurred while parsing tool arguments. Please try again with valid JSON. Error: zCAn error occurred while running the tool. Please try again. Error: )rh  rQ   )r&  r#  ru  s      r[   default_tool_error_functionr    s@    9%@$'(*	

 QQTUZQ[P\]]rZ   ztuple[ToolTimeoutBehavior, ...] _FUNCTION_TOOL_TIMEOUT_BEHAVIORSc                    SU  SUS S3$ )zFBuild the default message returned to the model when a tool times out.zTool 'z' timed out after gz	 seconds.rR   r>  r   s     r[   "default_tool_timeout_error_messager    s    I;00C9MMrZ   c                t    U[         L U l        U[         L a	  SU l        U $ [        [        S-  U5      U l        U $ )zPStore internal failure formatter config for tool wrappers and runtime fallbacks.N)_UNSET_FAILURE_ERROR_FUNCTIONr   r   ToolErrorFunctionr   )r  r0  s     r[   r5  r5    sX     	"?? 5
 "%BB 	 )
  #d*,BC )
 rZ   c                H    U R                   (       a  [        $ U R                  $ )zRReturn the configured tool failure formatter for runtime-generated error handling.)r   r  r   r  s    r[   ,resolve_function_tool_failure_error_functionr    s     88**000rZ   c                  <   ^  \ rS rSr% SrS\S'   SU 4S jjrSrU =r$ )_FunctionToolCancelledErrori  zWAdapter that preserves the public ToolErrorFunction Exception contract on cancellation.asyncio.CancelledErrorcancelled_errorc                X   > Xl         [        U5      =(       d    Sn[        TU ]  U5        g )NzTool execution cancelled.)r  rQ   superr  )rp   r  rn  	__class__s      r[   r  $_FunctionToolCancelledError.__init__  s&    .o&E*E!rZ   )r  )r  r  )	rS   rT   rU   rV   rW   rX   r  rY   __classcell__)r  s   @r[   r  r    s    a++" "rZ   r  c                    [        U [        5      (       a  U $ [        U [        R                  5      (       a  [	        U 5      $ [        [        U 5      =(       d    U R                  R                  5      $ )zXConvert runtime failures into the public Exception contract expected by tool formatters.)r   r$  asyncioCancelledErrorr  rQ   r  rS   rg  s    r[   -_coerce_tool_error_for_failure_error_functionr    sP    %##%//00*511SZ;5??#;#;<<rZ   c                   #    [        U 5      nUc  g[        U5      nU" X5      n[        R                  " U5      (       a
  UI Sh  vN $ U$  N7f)z7Invoke the configured failure formatter, if one exists.N)r  r  rl  rm  )r  r"  r#  r0  formatter_errorr   s         r[   r%  r%    sS      J-X%CEJO#G=F6""|M s   AAAAc                    [        U [        R                  5      (       a  U R                  $ [        U [        R                  5      (       a  U R
                  $ g)zIReturn the unqualified type name for a string annotation expression node.N)r   astNameid	Attributeattr)exprs    r[   _annotation_expr_namer    s:    $!!ww$&&yyrZ   c               t     [         R                  " U SS9R                  n[	        X!S9$ ! [         a     gf = f)zTReturn True when a string annotation structurally references the given context type.evalrk   F	type_name)r  parsebodySyntaxError&_annotation_expr_mentions_context_type)
annotationr  
expressions      r[   (_string_annotation_mentions_context_typer    s>    YYz7<<
 2*RR  s   * 
77c               `  ^ [        U [        R                  5      (       a3  [        U R                  [        5      (       a  [        U R                  TS9$ [        U 5      T:X  a  g[        U [        R                  5      (       aX  [        U R                  [        R                  5      (       a/  [        U R                  TS9=(       d    [        U R                  TS9$ [        U [        R                  5      (       a  [        U R                  5      n[        U R                  [        R                  5      (       a  U R                  R                   OU R                  4nUS:X  a  [#        U5      =(       a    [        US   TS9$ US;   a  [%        U4S jU 5       5      $ [        U R                  TS9$ g)zYReturn True when an annotation expression structurally references the given context type.r  Tr   r   >   r   Optionalc              3  8   >#    U  H  n[        UTS 9v   M     g7f)r  N)r  )r(  argr  s     r[   r)  9_annotation_expr_mentions_context_type.<locals>.<genexpr>  s      \`UX6siP\`   F)r   r  Constantr   rQ   r  r  BinOpopBitOrr  leftright	SubscriptsliceTupleeltsr   r,  )r  r  wrapper_nameargss    `  r[   r  r    sD   $%%*TZZ*E*E7

iXXT"i/$		""z$''399'E'E5II
 U3DJJ)T	U $&&,TZZ8",TZZ"C"Ctzz$**;&: "HQ9#  00 \`   6djjIVVrZ   c                 ^ U [         R                  R                  L a  g[        U [        5      (       a  [        U TR                  S9$ [        U 5      nU TL d  UTL a  gU[        L a*  [        U 5      n[        U5      =(       a    [        US   TS9$ U[        [        4;   a  [        U4S j[        U 5       5       5      $ g)zNReturn True when an annotation structurally references the given context type.Fr  Tr   context_typec              3  8   >#    U  H  n[        UTS 9v   M     g7f)r  N)!_annotation_mentions_context_type)r(  r  r  s     r[   r)  4_annotation_mentions_context_type.<locals>.<genexpr>8  s      
+ .cM+r  )rl  	Signatureemptyr   rQ   r  rS   r   r   r   r   r  r   r
   r,  )r  r  originr  s    `  r[   r  r  &  s    W&&,,,*c""7
lNcNcdd
#F\!V|%;
#Dzc?QVbcc%## 

+
 
 	

 rZ   c                    [        [        R                  " U R                  5      R                  R                  5       5      nU(       d  U$ US   R                  n [        U R                  SS9nUR                  US   R                  U5      n[        U[        S9(       a  U$ [        U[        S9(       a  UR!                  UR"                  5      $ U$ ! [        [        4 a    Us $ f = f! [         a     Nif = f)a  Choose the runtime context object to pass into a function tool wrapper.

Third-party wrappers may declare a narrower `RunContextWrapper` contract and then serialize
that object downstream. In those cases, passing the richer `ToolContext` can leak runtime-only
metadata such as agents or run config into incompatible serializers. When the wrapper
explicitly declares `RunContextWrapper`, preserve only the base context state.
r   T)include_extrasr  )r5  rl  	signaturer   r!  values	TypeErrorrn   r  r   r   r   r$  r  r=   r;   _fork_with_tool_input
tool_input)r  r"  r!  context_annotationresolved_annotationss        r[   !_get_function_tool_invoke_contextr  @  s    7,,]-I-IJUU\\^_
 #A11^-m.J.J[_` 255jm6H6HJ\]();+V();J[\,,W-?-?@@N% z"   s$   AC C, C)(C),
C98C9c                *  #    [        X5      nU R                  nUc(  U R                  [        [        U5      U5      I Sh  vN $ [
        R                  " U R                  [        [        U5      U5      5      n [
        R                  " XTS9I Sh  vN $  NU N! [
        R                   a  nUR                  5       (       a@  UR                  5       (       d+  UR                  5       nUc  UR                  5       s SnA$ USe[        U R                  US9nU R                  S:X  a  XeU R                   n	U	c  [#        U R                  US9s SnA$ U	" X5      n
[$        R&                  " U
5      (       a  U
I Sh  vN  s SnA$ U
s SnA$ SnAff = f7f)zFInvoke a function tool, enforcing timeout configuration when provided.N)r  r  rI   )r  r   r   r   r   r  ensure_futurewait_forTimeoutErrordone	cancelled	exceptionr   r6   r   r   r   r  rl  rm  )r  r"  	argumentsinvoke_contextr   	tool_taskr~  tool_exceptiontimeout_errorr   timeout_results              r[   invoke_function_toolr  b  sm     7}NN#33O"11$sN2KYWWW%,%:%:$$T#~%>	J&I%%iIII X J >>I$7$7$9$9&002N% '')) d*(#((+
 ))->>(!.!E!E!)5',, / 
 0G~..''''1s   >F B8F:B BB FB F.AF:F;F AFFF(F9E<:F>F?FFFFFFname_overridedescription_overridedocstring_styleuse_docstring_infor0  strict_moder   r   r   r   r  r   r   r   c                   g)z6Overload for usage as @function_tool (no parentheses).NrR   )funcr  r  r  r  r0  r  r   r   r   r   r  r   r   r   s                  r[   r  r    s    * rZ   c                    g)z*Overload for usage as @function_tool(...).NrR   r  s                 r[   r  r    s    ( rZ   c                  ^^^^^^^^^	^
^^^^^ SUUUUUUUUUUUU	U
U4S jjm[        U 5      (       a  T" U 5      $ SU4S jjnU$ )a  
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
    is_enabled: Whether the tool is enabled. Can be a bool or a callable that takes the run
        context and agent and returns whether the tool is enabled. Disabled tools are hidden
        from the LLM at runtime.
    needs_approval: Whether the tool needs approval before execution. If True, the run will
        be interrupted and the tool call will need to be approved using RunState.approve() or
        rejected using RunState.reject() before continuing. Can be a bool (always/never needs
        approval) or a function that takes (run_context, tool_parameters, call_id) and returns
        whether this specific call needs approval.
    tool_input_guardrails: Optional list of guardrails to run before invoking the tool.
    tool_output_guardrails: Optional list of guardrails to run after the tool returns.
    timeout: Optional timeout in seconds for each tool call.
    timeout_behavior: Timeout handling mode. "error_as_result" returns a model-visible message,
        while "raise_exception" raises ToolTimeoutError and fails the run.
    timeout_error_function: Optional formatter used for timeout messages when
        timeout_behavior="error_as_result".
    defer_loading: Whether to hide this tool definition until Responses API tool search
        explicitly loads it.
c                F  >^ ^^ [         R                  " T 5      (       + m[        T T
TTTTS9mSUUU 4S jjn[        S0 STR                  _STR
                  =(       d    S_STR                  _SU_S[        S	S
SS9_ST_ST_ST	_ST_ST_ST_ST_ST_ST_ST_ST_6nU$ )N)r  r  r  r  r  r   c                D  >#    U R                   n[        X!S9n[        X!S9   U(       a  T
R                  " S	0 UD6OT
R                  5       nT
R                  U5      u  pg[        R                  (       d  [        R                  " SU SU 35        T	(       d7  T
R                  (       a  T" U /UQ70 UD6I S h  vN nOhT" U0 UD6I S h  vN nOWT
R                  (       a$  [        R                  " TU /UQ70 UD6I S h  vN nO"[        R                  " T/UQ70 UD6I S h  vN n[        R                  (       a  [        R                  " SU S35        U$ [        R                  " SU SU 35        U$ ! [         a  n[        SU SU 35      UeS nAff = f N N N N}7f)
Nr  r~  r  zTool call args: z
, kwargs: zTool z completed.z
 returned rR   )r>  r  r  params_pydantic_modelr&   r5   to_call_argsr,   rr  r:   rs  takes_contextr  	to_thread)r&  r'  r>  	json_dataparsedr(  r  kwargs_dictr   is_sync_function_toolschemathe_funcs            r[   _on_invoke_tool_implJfunction_tool.<locals>._create_function_tool.<locals>._on_invoke_tool_impl	  s    I7)^I)IPa ! 00=9=557  !' 3 3F ;D,,/vZ}MN(''#+C#F$#F+#FFF#+T#A[#AAF''#*#4#4Xs#YT#Y[#YYF#*#4#4X#T#T#TTF((uYK{;< M uYKz&BCM1 # a(+G	{RTUVTW)XY_``a GA ZTsl   F )E4 A+F 7F8F F	4F =F>"F  F!AF 4
F>FFF F F F r   r   r  r   r  r  zError running tool (non-fatal)zError running toolTool)rz  ri  ry  r0  r   r   r   r   r   r   r   r   r   r1  r,  rR   )rl  iscoroutinefunctionr9   r6  r   r   r   r|  )r  r  r  r  r  r   r  r  r0  r   r  r   r  r  r   r   r   r   r  s   `  @@r[   _create_function_tool,function_tool.<locals>._create_function_tool  s   $+$?$?$I I '!5+1*
#	 #	J 5 

**0b
  &88
 2	

 H=3G 
 $:
  +
 "
 *
 #8
 $:
  $!
" .#
$ $:%
& ('
( /)
, rZ   c                   > T" U 5      $ r   rR   )	real_funcr   s    r[   	decorator function_tool.<locals>.decoratorK  s    $Y//rZ   )r  ToolFunction[...]rs   r   )r  r  rs   r   )r   )r  r  r  r  r  r0  r  r   r   r   r   r  r   r   r   r  r   s    `````````````` @r[   r  r    s;    BF F FR ~~$T**0 rZ   c                    [        U [        5      =(       d(    [        U S5      =(       a    [        U R                  5      $ )Nr   )r   r   hasattrr   r   )	candidates    r[   rk  rk  V  s1    i!12 	8$C)2B2B)CrZ   c                P   U R                   nUb  [        U[        5      (       d  [        U[        [        -  5      (       d  [        S5      e[	        U5      n[        R                  " U5      (       d  [        S5      eUS::  a  [        S5      e[        U R                  [        S5      (       a  [        S5      eXl         U R                  [        ;  a!  [        SSR                  [        5      -   5      eU R                  b&  [!        U R                  5      (       d  [        S	5      eg g )
NzJFunctionTool timeout_seconds must be a positive number in seconds or None.z5FunctionTool timeout_seconds must be a finite number.r   z4FunctionTool timeout_seconds must be greater than 0.FzQFunctionTool timeout_seconds is only supported for async @function_tool handlers.z.FunctionTool timeout_behavior must be one of: r9  z=FunctionTool timeout_error_function must be callable or None.)r   r   r   intfloatr  mathisfinitern   r   r   r  r   r  r;  r   r   )r   r   s     r[   r   r   \  s   **O"ot,,JPSV[P[4\4\\   0}}_--TUUaSTT4&&(BEJJc   /$DD<ii89:
 	

 "".x@[@[7\7\WXX 8].rZ   c                p    U R                   n[        U5      (       d  [        U5      (       a
  U[        U '   g g r   )r   r   rk  rc  )r   configs     r[   rV  rV  x  s1    ]]F088*0!$' 9rZ   c                    U [         ;   a	  [         U    $ [        U R                  5      (       d  [        U R                  5      (       a  U R                  $ g r   )rc  r   r   rk  rD  s    r[   rj  rj  ~  sA    (((.."7"F"F}}rZ   c                R    [         R                  U5      nUc  0 nU[         U'   X#U '   g r   )rd  r   )r   r   rf  resolved_by_runs       r[   ri  ri    s2     033K@O1@!+.$DrZ   )r  r   r  r*  rs   r   )&r   rQ   r   rQ   r   r   r  r   r  r*  r0  !ToolErrorFunction | None | objectr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r1  r   r2  rf   r3  r   rs   r   )r  r   rs   r   )r   ComputerTool[Any]r   r   rs   ra  )r   r   rs   r+  )r  r  rs   r  )r   rQ   r   rf   r.  list[FunctionTool]rs   r  )r   r   rs   ztuple[str, ...])r   r   r<  rQ   rs   r+  )rA  z6Literal['auto', 'required', 'none'] | str | Any | Noner<  rQ   rs   r+  )r   r  rs   r   )r.  
list[Tool]rs   r   )r.  r  rS  r   rs   r+  )r.  r  rs   r  )r#  BaseExceptionrs   json.JSONDecodeError | None)r#  r$  rs   r  )rz  rQ   ry  rQ   ri  rf   rj  r   rk  r   rs   r*  )r>  rQ   rt  rQ   rs   r   )r>  rQ   rt  rQ   rs   r+  )r&  r   r#  r$  rs   rQ   )r>  rQ   r   r  rs   rQ   )r  r   r0  r  rs   r   )r  r   rs   r   )r#  r  rs   r$  )r  r   r"  r   r#  r  rs   rf   )r  ast.exprrs   rf   )r  rQ   r  rQ   rs   r   )r  r  r  rQ   rs   r   )r  r   r  z	type[Any]rs   r   )r  r   r"  r-  rs   z)ToolContext[Any] | RunContextWrapper[Any])r  r   r"  r-  r  rQ   rs   r   ) r  r  r  rf   r  rf   r  DocstringStyle | Noner  r   r0  r   r  r   r   r   r   r   r   r   r   r   r  r   r   r   r   r   r   r   rs   r   )r  rf   r  rf   r  r  r  r   r0  r   r  r   r   r   r   r   r   r   r   r   r  r   r   r   r   r   r   r   rs   z+Callable[[ToolFunction[...]], FunctionTool]r   ) r  zToolFunction[...] | Noner  rf   r  rf   r  r  r  r   r0  r  r  r   r   r   r   r   r   r   r   r   r  r   r   r   r   r   r   r   rs   z:FunctionTool | Callable[[ToolFunction[...]], FunctionTool])r	  objectrs   r   )r   r   rs   r+  )r   r  rs   r+  )r   r  rs   zComputerConfig | None)r   r  r   r   rf  r`  rs   r+  )
__future__r   r  r  r-  r  rl  r_  r  rg  collections.abcr   r   r   r   r   enumr	   typesr
   typingr   r   r   r   r   r   r   r   r   r   r   r   r   r   openai.types.responsesr   -openai.types.responses.file_search_tool_paramr   r   2openai.types.responses.response_computer_tool_callr   r   +openai.types.responses.response_output_itemr   r   !openai.types.responses.tool_paramr    r!   r"   &openai.types.responses.web_search_toolWebSearchToolFilters,openai.types.responses.web_search_tool_paramr#   pydanticr$   r%   r&   r'   typing_extensionsr(   r)   r*   r  r,   _tool_identityr-   r.   r/   r0   r   r1   r2   r  r3   r4   
exceptionsr5   r6   r7   r9   r8   r:   r   r;   strict_schemar<   tool_contextr=   tool_guardrailsr>   r?   tracingr@   utilrA   util._typesrB   r  rC   rD   r  rE   rF   rG   ToolFunctionWithoutContextToolFunctionWithContextToolFunctionWithToolContextToolFunction"DEFAULT_APPROVAL_REJECTION_MESSAGEr   r$  rQ   r  r  r   CustomToolApprovalFunctionr  r  r  rL   r]   rb   ru   ry   r   ValidToolOutputPydanticModelsr   rX   r   r   ra  r   r   r   r   r   r   ComputerConfigr   r   r  r/  r6  r9  r;  rH  rS  r`  rh  rb  rc  rd  rv  r  r  r  r  MCPToolApprovalFunctionShellApprovalFunctionr  ShellOnApprovalFunctionApplyPatchApprovalFunctionr  ApplyPatchOnApprovalFunctionr  CustomToolOnApprovalFunctionr  r  r  r  r  r  r  r  r  r  ShellToolContainerSkillr  r  r  ShellToolContainerNetworkPolicyr  r  r  ShellToolHostedEnvironmentr  r  r  r  r  r  r  ShellExecutorr  r  r  r  r  r  r3  r7  r?  rB  rE  rL  rN  rR  r[  r]  rd  rh  r|  r  r  r  r  r  r5  r  r  r  r%  r  r  r  r  r  r  r  rk  r   rV  rj  ri  rR   rZ   r[   <module>rF     s   " 
        8 8 (     " 3 Q [ S S R E M M ? ?   . 9 G G <  * 4 % D    ''0 |$
%j#o6 ";/@/Ez/Q#RTW#WX &{;
3J'KS'PQ  z*j)*!*-.  &H "BC /4i@.QTBUUV {3/5~c7JJK %'8'=sC&H.Y]J^&^_ <  & Y % i (8)5 8I *	  !/ @CX X Wb!X (*T 
$S$ $ $+
 +
 +
\ -'K|4	~\TJ-\QUV dXl+ d#h/0 # 6wy) 6 6 s 336Fs6KK 7 7 7( F F FR* *ZSGSDS 7S A^#]aBFDH 	$(,=7; %)+2
2 2 '	2
 H2 E2 >2 2 [2 @2 B2 	X2 "2  *!2" 5#2$ %2& '2( )2* #+2, -2jR   2   4 e79%  2 9 9 9     
  W 
     
11-C11hR: 3 3 3  7 7 7+I + #n-JKK  7 !s1379MM 
+I + #s/0.A^2__ 
 &s0#6t8LL 
+ +  (s/0.Ac2dd  
+ +  (s/0.Ac2dd  
   ( " " " " " " 3 3 3 78.:MMN  4   ) i  9  24HH  $) Sy Si  -/VV   @3	 37	 7Y  &(NN  )03MM  ' ! ! ! L L L$ 0 0 0 ) ) )       -.s[?P0QQR U2,22 , , ,^   , % % %P   "  3 	
     	 
   +
  	
 4
  
	$G  
	I
H ).

 "&
 
	
:- 6:'+.2)) ) )3	)
 !%) (,) 4)X	dK	^E  "A N A^=  111") "= $ 	
 $S@4 /D)) ) 	)
 	)X 
 !%'+-1#7;]aQVBFDH ,=7;#
  %	
 +  5  [O @ B  *  5!" #$ % 
. 
 !%'+-1#7;]aQVBFDH ,=7;! % +	
  5  [O @ B  * 5  !" 1# 
. &*Q !%'+-1#@]]aQVBFDH ,=7;#Q
"Q Q %	Q
 +Q Q >Q Q [QOQ @Q BQ Q *Q  5!Q" #Q$ @%QrY81
%

% (
%  	
%
 

%rZ   