
    Cj                    L   % S SK Jr  S SKrS SKrS SK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  S SKJ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"  S	SK#J$r$J%r%J&r&J'r'J(r(  S	SK)J*r*J+r+  S	SK,J-r-J.r.  S	SK/J0r0  S	SK1J1r1  S	SK2J3r3  S	SK4J5r5  S	SK6J7r7J8r8J9r9  S	SK:J;r;  S	SK<J=r=J>r>J?r?  S	SK@JArAJBrB  S	SKCJDrD  S	SKEJFrFJGrGJHrHJIrIJJrJJKrKJLrLJMrMJNrNJOrOJPrPJQrQ  S	SKRJSrS  S	SKTJUrU  S	SKVJWrW  \(       a:  S SKXJYrY  S	SKZJ[r[  S	SK\J]r]J^r^  S	S K2J_r_  S	S!K`Jara  S	S"KbJcrcJdrd  S	S#KeJfrf  S	S$KgJhrh  S	S%KiJjrj  \ " S& S'5      5       rk\\A\B   \l\G   /\W\k   4   rmS(\nS)'    S5S* jro " S+ S,\5      rp " S- S.\5      rq " S/ S0\5      rr\ " S1 S2\\B   5      5       rs\ " S3 S4\s\\B   5      5       rtg)6    )annotationsN)	AwaitableCallable)	dataclassfield)TYPE_CHECKINGAnyGenericLiteral	TypeAliascast)ResponsePromptParam)	BaseModelTypeAdapterValidationError)NotRequired	TypedDict   )get_function_tool_approval_keysAgentOutputSchemaBase)AgentAsToolInputStructuredToolInputBuilder"build_structured_input_schema_inforesolve_agent_tool_input)consume_agent_tool_run_resultget_agent_tool_state_scopepeek_agent_tool_run_resultrecord_agent_tool_run_resultset_agent_tool_state_scope)ModelBehaviorError	UserError)InputGuardrailOutputGuardrail)Handoff)logger)MCPUtil)ModelSettings)get_default_model_settings!gpt_5_reasoning_settings_requiredis_gpt_5_defaultModel)DynamicPromptFunctionPrompt
PromptUtil)RunContextWrapperTContext)ensure_strict_json_schema)FunctionToolFunctionToolResultToolToolErrorFunction
ToolOriginToolOriginType*_build_handled_function_tool_error_handler_build_wrapped_function_tool_log_function_tool_invocation_parse_function_tool_json_inputdefault_tool_error_function prune_orphaned_tool_search_toolsToolContext)_transforms)MaybeAwaitable)ResponseFunctionToolCall)ToolApprovalItem)
AgentHooksRunHooks)	MCPServer)Session)	RunResultRunResultStreaming)	RunConfig)RunState)StreamEventc                  0    \ rS rSr% S\S'    SrS\S'   Srg)ToolsToFinalOutputResultK   boolis_final_outputN
Any | Nonefinal_output )__name__
__module____qualname____firstlineno____annotations__rU   __static_attributes__rV       ^/home/rurouni/.local/share/pipx/venvs/strix-agent/lib/python3.13/site-packages/agents/agent.pyrP   rP   K   s      $L*#r]   rP   r   ToolsToFinalOutputFunctionc           
       ^ U  Vs1 s HC  n[        U[        5      (       d  M  [        [        USS5      5      (       d  M7  UR                  iME     nnU(       d  g 0 mU  HH  n[        USS 5      n[        U[
        5      (       d  M'  U(       d  M0  TR                  US5      S-   TU'   MJ     [        U4S jU 5       5      nU(       a   [        SSR                  U5      -   S	-   5      eg s  snf )
N_is_codex_toolFnamer   r   c              3  X   >#    U  H  nTR                  US 5      S:  d  M  Uv   M!     g7f)r   r   N)get).0rb   name_countss     r^   	<genexpr>7_validate_codex_tool_name_collisions.<locals>.<genexpr>p   s)      #)[__T1-E-I)s   *	*z"Duplicate Codex tool names found: z, z:. Provide a unique codex_tool(name=...) per tool instance.)

isinstancer4   rR   getattrrb   strrd   sortedr"   join)toolstoolcodex_tool_names	tool_nameduplicate_codex_namesrf   s        @r^   $_validate_codex_tool_name_collisionsrs   a   s     DdL) 	.274AQSX3Y.Z 			  
 "$KD&$/	i%%))%0__Y%BQ%FK	" 
 # #)#  0ii-./JK
 	
 #s   C'C' C'c                  <    \ rS rSr% SrS\S'    S\S'    S\S'   S	rg
)AgentToolStreamEvent{   z;Streaming event emitted when an agent is invoked as a tool.rN   eventz
Agent[Any]agentzResponseFunctionToolCall | None	tool_callrV   NrW   rX   rY   rZ   __doc__r[   r\   rV   r]   r^   ru   ru   {   s     E8...2r]   ru   c                       \ rS rSr% S\S'   Srg)StopAtTools   z	list[str]stop_at_tool_namesrV   N)rW   rX   rY   rZ   r[   r\   rV   r]   r^   r}   r}      s    !!Vr]   r}   c                  0    \ rS rSr% SrS\S'    S\S'   Srg)		MCPConfig   zConfiguration for MCP servers.zNotRequired[bool]convert_schemas_to_strictz%NotRequired[ToolErrorFunction | None]failure_error_functionrV   Nrz   rV   r]   r^   r   r      s    (00 BAr]   r   c                      \ rS rSr% SrS\S'    SrS\S'    \" \S9r	S	\S
'    \" \S9r
S\S'    \" S S9rS\S'    SS jrSS jrSrg)	AgentBase   z+Base class for `Agent` and `RealtimeAgent`.rk   rb   N
str | Nonehandoff_descriptiondefault_factory
list[Tool]rn   zlist[MCPServer]mcp_serversc                     [        5       $ N)r   rV   r]   r^   <lambda>AgentBase.<lambda>   s    )+r]   r   
mcp_configc                   #    U R                   R                  SS5      nU R                   R                  S[        5      n[        R                  " U R
                  UUU US9I Sh  vN $  N7f)z1Fetches the available tools from the MCP servers.r   Fr   )r   N)r   rd   r>   r'   get_all_function_toolsr   )selfrun_contextr   r   s       r^   get_mcp_toolsAgentBase.get_mcp_tools   sm     $(OO$7$78SUZ$[!!%!4!4$&A"
 33%#9
 
 	
 
s   A"A+$A)%A+c                b  ^ ^^#    T R                  T5      I Sh  vN nSUU 4S jjm[        R                  " U4S jT R                   5       6 I Sh  vN n[	        T R                  USS9 VVs/ s H  u  pEU(       d  M  UPM     nnn[        / UQUQ5      n[        U5        U$  N NTs  snnf 7f)z8All agent tools, including MCP tools and function tools.Nc                  >#    [        U [        5      (       d  gU R                  n[        U[        5      (       a  U$ U" TT5      n[        R
                  " U5      (       a  [        UI S h  vN 5      $ [        U5      $  N7f)NT)ri   r4   
is_enabledrR   inspectisawaitable)ro   attrresr   r   s      r^   _check_tool_enabled4AgentBase.get_all_tools.<locals>._check_tool_enabled   si     dL11??D$%%{D)C""3''#I&9 &s   A(B+A?,Bc              3  4   >#    U  H  nT" U5      v   M     g 7fr   rV   )re   tr   s     r^   rg   *AgentBase.get_all_tools.<locals>.<genexpr>   s     (TA)<Q)?)?s   F)strict)ro   r6   returnrR   )r   asynciogatherrn   zipr?   rs   )	r   r   	mcp_toolsresultsr   okenabled	all_toolsr   s	   ``      @r^   get_all_toolsAgentBase.get_all_tools   s     ,,[99	
	 
	  (T(TUU.1$**ge.T[.TUQXZq.T[ @AW9AWwAW X	,Y7% : V[s9   B/B%7B/B'B//B) B) B/'B/)B/rV   )r   RunContextWrapper[TContext]r   r   )rW   rX   rY   rZ   r{   r[   r   r   listrn   r   r   r   r   r\   rV   r]   r^   r   r      sd    5
I &** d3E:31#(#>K> "2EFJ	F(
r]   r   c                     \ rS rSr% SrSrS\S'    SrS\S'    \" \	S9r
S	\S
'    SrS\S'    \" \S9rS\S'    \" \	S9rS\S'    \" \	S9rS\S'    SrS\S'    SrS\S'    SrS\S'    SrS\S'    S rS$S jrSSSSSSSSS\SSSS4                                 S%S  jjrS&S! jr    S'S" jrS#rg)(Agent   a-  An agent is an AI model configured with instructions, tools, guardrails, handoffs and more.

We strongly recommend passing `instructions`, which is the "system prompt" for the agent. In
addition, you can pass `handoff_description`, which is a human-readable description of the
agent, used when the agent is used inside tools/handoffs.

Agents are generic on the context type. The context is a (mutable) object you create. It is
passed to tool functions, handoffs, guardrails, etc.

See `AgentBase` for base parameters that are shared with `RealtimeAgent`s.
NzZstr | Callable[[RunContextWrapper[TContext], Agent[TContext]], MaybeAwaitable[str]] | Noneinstructionsz%Prompt | DynamicPromptFunction | Nonepromptr   z)list[Agent[Any] | Handoff[TContext, Any]]handoffszstr | Model | Nonemodelr(   model_settingszlist[InputGuardrail[TContext]]input_guardrailszlist[OutputGuardrail[TContext]]output_guardrailsz(type[Any] | AgentOutputSchemaBase | Noneoutput_typezAgentHooks[TContext] | Nonehooksrun_llm_againzYLiteral['run_llm_again', 'stop_on_first_tool'] | StopAtTools | ToolsToFinalOutputFunctiontool_use_behaviorTrR   reset_tool_choicec                H   SSK Jn  [        U R                  [        5      (       d+  [        S[        U R                  5      R                   35      eU R                  bJ  [        U R                  [        5      (       d+  [        S[        U R                  5      R                   35      e[        U R                  [        5      (       d+  [        S[        U R                  5      R                   35      e[        U R                  [        5      (       d+  [        S[        U R                  5      R                   35      e[        U R                  [        5      (       d+  [        S[        U R                  5      R                   35      eU R                  bd  [        U R                  [        5      (       dE  [        U R                  5      (       d+  [        S[        U R                  5      R                   35      eU R                   b`  [        U R                   5      (       dF  [#        U R                   S	5      (       d+  [        S
[        U R                   5      R                   35      e[        U R$                  [        5      (       d+  [        S[        U R$                  5      R                   35      eU R&                  bk  [        U R&                  [        5      (       dL  SSKJn  [        U R&                  U5      (       d+  [        S[        U R&                  5      R                   35      e[        U R,                  [.        5      (       d+  [        S[        U R,                  5      R                   35      eU R&                  bi  [1        5       SL a\  [        U R&                  [        5      SL d  [3        U R&                  5      SL a'  U R,                  [5        5       :X  a  [/        5       U l        [        U R6                  [        5      (       d+  [        S[        U R6                  5      R                   35      e[        U R8                  [        5      (       d+  [        S[        U R8                  5      R                   35      eU R:                  bf  SSKJn  [        U R:                  [        U-  5      (       d>  U" U R:                  5      c+  [        S[        U R:                  5      R                   35      eU R@                  bL  SSK!J"n  [        U R@                  U5      (       d+  [        S[        U R@                  5      R                   35      e[        U RF                  [        5      (       a  U RF                  S;   dd  [        U RF                  [        5      (       dE  [        U RF                  5      (       d+  [        S[        U RF                  5      R                   35      e[        U RH                  [J        5      (       d+  [        S[        U RH                  5      R                   35      eg )Nr   )
get_originz!Agent name must be a string, got z8Agent handoff_description must be a string or None, got z Agent tools must be a list, got z&Agent mcp_servers must be a list, got z%Agent mcp_config must be a dict, got z<Agent instructions must be a string, callable, or None, got rd   zCAgent prompt must be a Prompt, DynamicPromptFunction, or None, got z#Agent handoffs must be a list, got r   r,   z2Agent model must be a string, Model, or None, got z;Agent model_settings must be a ModelSettings instance, got TFz+Agent input_guardrails must be a list, got z,Agent output_guardrails must be a list, got r   zFAgent output_type must be a type, AgentOutputSchemaBase, or None, got )AgentHooksBasez8Agent hooks must be an AgentHooks instance or None, got )r   stop_on_first_toolzjAgent tool_use_behavior must be 'run_llm_again', 'stop_on_first_tool', StopAtTools dict, or callable, got z/Agent reset_tool_choice must be a boolean, got )&typingr   ri   rb   rk   	TypeErrortyperW   r   rn   r   r   r   dictr   callabler   hasattrr   r   models.interfacer-   r   r(   r+   r*   r)   r   r   r   agent_outputr   r   	lifecycler   r   r   rR   )r   r   r-   r   r   s        r^   __post_init__Agent.__post_init__D  s   %$))S))?TYY@X@X?YZ[[##/
4C[C[]`8a8aD445>>?A 
 $**d++>tDJJ?O?X?X>YZ[[$**D118d>N>N9O9X9X8YZ  $//4007T__8M8V8V7WX 
 )t00#66T..//D--.778:  KK#T[[))DKK//DKK(1124 
 $--..A$t}}BUB^B^A_`aa::!*TZZ*E*E/djj%00HdjjIYIbIbHcd  $--}==D//099:<  JJ" !"d* tzz3/588DM ''+E+GG #0/D$//66=d4CXCX>Y>b>b=cd  $00$77D223<<=? 
 '; 4++T4I-IJJd../; 0 01::;= 
 ::!1djj.99

+4457  411377**.UUt55t<<T334466:4;Q;Q6R6[6[5\^ 
 $00$77D223<<=?  8r]   c                0    [         R                  " U 40 UD6$ )a  Make a copy of the agent, with the given arguments changed.
Notes:
    - Uses `dataclasses.replace`, which performs a **shallow copy**.
    - Mutable attributes like `tools` and `handoffs` are shallow-copied:
      new list objects are created only if overridden, but their contents
      (tool functions and handoff objects) are shared with the original.
    - To modify these independently, pass new lists when calling `clone()`.
Example:
    ```python
    new_agent = agent.clone(instructions="New instructions")
    ```
)dataclassesreplace)r   kwargss     r^   cloneAgent.clone  s     ""42622r]   Fc                  ^ ^^^^^^	^
^^^^^^^ SS jnU=(       d     [         R                  " T R                  5      mU=(       d    SnUSLn[        U=(       a    U5      n[        U=(       d    U=(       d    TSL5      mUc)  [	        [
        5      m[        TR                  5       5      nO<U" U5      (       d  [        S5      e[	        U5      m[        TR                  5       5      n[        UUS9mSU4S jjmSUU
UUUUUUU	UUU UUU4S jjn[        TUUU[        SS	S
S9USUU[        [        R                  T R                  TS9S9
nSUl        T Ul        U$ )a  Transform this agent into a tool, callable by other agents.

This is different from handoffs in two ways:
1. In handoffs, the new agent receives the conversation history. In this tool, the new agent
   receives generated input.
2. In handoffs, the new agent takes over the conversation. In this tool, the new agent is
   called as a tool, and the conversation is continued by the original agent.

Args:
    tool_name: The name of the tool. If not provided, the agent's name will be used.
    tool_description: The description of the tool, which should indicate what it does and
        when to use it.
    custom_output_extractor: A function that extracts the output from the agent. If not
        provided, the last message from the agent will be used. Nested run results expose
        `agent_tool_invocation` metadata when this agent is invoked via `as_tool()`.
    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.
    on_stream: Optional callback (sync or async) to receive streaming events from the nested
        agent run. The callback receives an `AgentToolStreamEvent` containing the nested
        agent, the originating tool call (when available), and each stream event. When
        provided, the nested agent is executed in streaming mode.
    failure_error_function: If provided, generate an error message when the tool (agent) run
        fails. The message is sent to the LLM. If None, the exception is raised instead.
    needs_approval: Bool or callable to decide if this agent tool should pause for approval.
    parameters: Structured input type for the tool arguments (dataclass or Pydantic model).
    input_builder: Optional function to build the nested agent input from structured data.
    include_input_schema: Whether to include the full JSON schema in structured input.
c                    [        U [        5      (       d  g[        R                  " U 5      (       a  g[	        U [
        5      $ )NFT)ri   r   r   is_dataclass
issubclassr   )values    r^   _is_supported_parameters/Agent.as_tool.<locals>._is_supported_parameters  s3    eT**''..eY//r]    NzAAgent tool parameters must be a dataclass or Pydantic model type.)include_json_schemac                n   >  TR                  U SS9$ ! [         a  n[        SU SU 35      UeS nAff = f)Njson)modez.Failed to serialize structured tool input for : )dump_python	Exceptionr!   )parsedrq   excparams_adapters      r^   _normalize_tool_input,Agent.as_tool.<locals>._normalize_tool_input*  sP    %11&v1FF (DYKrRUQVWs    
4/4c                  >^ ^$^%^&#    SSK JnJn  SSKJn  [        T U5      (       a  T R                  OT5n[        UUS9n[        XQS9   T.R                  U5      nT'" Xu5      n	[        U	T4(       a  T1OS T+S9I S h  vN n
[        U
[        5      (       d   [        U
[        5      (       d  [        S5      eT,b  T,OUnT0nUc  [        T U5      (       a  T R                  n[!        T 5      n[        T U5      (       aw  U" T R"                  T R$                  T R                  T R&                  T R(                  T R*                  T R,                  T R.                  US	9	n[1        X5        T4(       a  Xl        Or[        T [4        5      (       a9  T4(       a%  [5        T R"                  S
9n[1        X5        Xl        O1T R"                  nO$T4(       a  [5        T S
9n[1        X5        Xl        OT nS nS nSn    SU 4S jjn        SS jn[        T U5      (       a  T R*                  b  [7        T R*                  US9nU(       a  [9        USS 5      (       ar  U" UR:                  5      nUS:X  a  UnSnOUUS;   aO  UR=                  5       nUR>                  b  U" UR>                  T UR:                  5        [A        T R*                  US9  UGck  T-Gb  T-m&URC                  [E        [F        [H           T25      U=(       d    U
Ub  S O[E        [H        U5      UUT*Ub  S OT/Ub  S OT(T3S9	n[J        RL                  " 5       m%SU2U&4S jjm$SU$U%4S jjn[J        RN                  " U" 5       5      nSn SSK(J)n  URT                  n URQ                  5         S h  vN n[        UU5      (       a  URV                  nUUT R*                  S.nT%RY                  U5      I S h  vN   MQ  UR                  [E        [F        [H           T25      U=(       d    U
Ub  S O[E        [H        U5      UUT*Ub  S OT/Ub  S OT(T3S9	I S h  vN nUc   e[9        USS 5      n[        T U5      (       a0  T R*                  b#  U(       a  U(       a  [a        T R*                  UUS9  T)(       a  T)" U5      I S h  vN $ URb                  b;  [        URb                  [        5      (       a  URb                  S:w  a  URb                  $ SSK2J3nJ4n J5n!  [m        URn                  5       H  n"[        U"U 5      (       a  URq                  U"5      n#U#(       a  U#s  $ [        U"U!5      (       d  MC  [        U"Rr                  [        5      (       d  Md  U"Rr                  (       d  Mw  U"Rr                  s  $    URb                  $ ! [         a  n[        SU SU 35      UeS nAff = f GN; GN2 GN
 O! [J        RZ                   a    Sne f = f U(       a7  UR]                  5          UI S h  vN    O! [J        RZ                   a     Of = fT%RY                  S 5      I S h  vN    T%R_                  5       I S h  vN    UI S h  vN    O! U(       a7  UR]                  5          UI S h  vN    f ! [J        RZ                   a     f f = fT%RY                  S 5      I S h  vN    T%R_                  5       I S h  vN    UI S h  vN    f = fUnGN GN GNO7f)Nr   )DEFAULT_MAX_TURNSRunnerr@   )rq   
input_jsonzInvalid JSON input for tool r   )paramsschema_infoinput_builderz$Agent tool called with invalid input)	contextusagerq   tool_call_idtool_argumentsry   tool_namespacerx   
run_config)r   Tinterruptionsc                  > SnSnU  Hj  nUR                   nU(       d  SnM  [        R                  " U5      nTR                  UR                  =(       d    SUUUS9nUSL a    gUSL a  SnUb  Mh  SnMl     U(       a  gU(       a  gg)NFTr   r   existing_pendingrejectedapprovedpending)call_idr1   _resolve_tool_namespaceget_approval_statusrq   )r   has_pendinghas_decisioninterruptionr   r   statusr   s          r^   _nested_approvals_statusHAgent.as_tool.<locals>._run_agent_impl.<locals>._nested_approvals_statusu  s     $$$1L*22G"&* %6%N%N|%\N$88$..4"'5)5	 9 F )~'+~&*# %2$  %$!r]   c                (  ^       SU4S jjnU H  nUR                   nU(       d  M  [        R                  " U5      n[        R                  " U5      n[        R                  " U5      nTR                  UUUUS9n	U	c  Mq  TR                  R                  U5      n
U
c  U" UU	S9n
U	SL a2  [        U
=(       a    U
R                  SL 5      nU R                  UUS9  M  [        U
=(       a    U
R                  SL 5      nU R                  UUS9  M     g )Nc                 > [        [        R                  " U 5      5      n[        [        R                  " U 5      [        R
                  " U 5      [        R                  " U 5      SS9 H  nX2;  d  M
  UR                  U5        M     S nU H^  nTR                  R                  U5      nUc  M#  U(       a  UR                  SL a  Us  $ U(       d  UR                  SL a  Us  $ Ub  M\  UnM`     U$ )NT)rq   r   tool_lookup_keyinclude_legacy_deferred_key)r   r1   _resolve_approval_keysr   _resolve_tool_namer   _resolve_tool_lookup_keyappend
_approvalsrd   r   r   )r  r   candidate_keyscandidate_keyfallback	candidateparent_contexts         r^   _find_mirrored_approval_recordoAgent.as_tool.<locals>._run_agent_impl.<locals>._apply_nested_approvals.<locals>._find_mirrored_approval_record  s    
 &**;*R*RS_*`%aN)H"3"F"F|"T'8'P'PQ]'^(9(R(RS_(`48	* )>*11-@* ,0H)7$2$=$=$A$A-$P	$,$#	(:(:d(B#,,'I,>,>$,F#,,#+'0H *8 $Or]   r   )r   T)always_approve)always_reject)r  rE   r   rR   r   rT   )r   r1   r  r   _resolve_approval_keyr  r  rd   rR   r   approve_toolr   reject_tool)nested_contextr  r   r  r  r   rq   r   approval_keyr  approval_recordr  r  s    `           r^   _apply_nested_approvalsGAgent.as_tool.<locals>._run_agent_impl.<locals>._apply_nested_approvals  s<   
$"2$ #$  	$6 %2L*22G"  1 D D\ RI%6%N%N|%\N#4#J#J<#XL+??!'5)5	 @ F ~ &4&?&?&C&CL&QO&.*H(%++ ~)-o.b/BZBZ^bBb)c&33(+9 4 
 )-_-aAYAY]aAa(b&22(*7 3 ; %2r]   )scope_idr   F)r   r   )	starting_agentinputr   r   	max_turnsr   previous_response_idconversation_idsessionc                   >#     T" U 5      n[         R                  " U5      (       a  UI Sh  vN   gg N! [         a$    [        R                  " STR
                  5         gf = f7f)z5Execute the user callback while capturing exceptions.Nz7Error while handling on_stream event for agent tool %s.)r   r   r   r&   	exceptionrb   )payloadmaybe_resultr   stream_handlers     r^   _run_handler<Agent.as_tool.<locals>._run_agent_impl.<locals>._run_handler   s^     +9'+BL&22<@@&2 2 2  A 2( ",, Y $		s1   A'(6 46 A'6 +A$!A'#A$$A'c                    >#     TR                  5       I S h  vN n U S L n U b  T" U 5      I S h  vN   TR                  5         U(       a  g MJ   N6 N ! TR                  5         f = f7fr   )rd   	task_done)r+  is_sentinelr.  event_queues     r^   dispatch_stream_eventsFAgent.as_tool.<locals>._run_agent_impl.<locals>.dispatch_stream_events  sg     ",7OO,=&=G*1T/K8#*#6*6w*?$?$? + 5 5 7* % #&= %@ + 5 5 7s5   A(AA(A AA A(A A%%A()AgentUpdatedStreamEvent)rw   rx   ry   r   )ItemHelpersMessageOutputItemToolCallOutputItem)r   list[ToolApprovalItem]r   z*Literal['approved', 'pending', 'rejected'])r  RunContextWrapper[Any]r  r;  r   r:  r   None)r+  ru   r   r<  )r   r<  ):runr   r   tool_contextrA   ri   rq   r=   r<   validate_pythonr   r!   r   rk   r   r   r   r   r   r   r   ry   r   rx   r    
tool_inputr1   r   rj   r   to_state_contextr   run_streamedr   r   r	   r   Queuecreate_taskstream_eventsr6  current_agent	new_agentputCancelledErrorcancelrm   r   rU   itemsr7  r8  r9  reversed	new_itemstext_message_outputoutput)6r   r   r   r   rA   rq   	json_dataparsed_paramsr   params_dataresolved_inputresolved_max_turnsresolved_run_configtool_state_scope_idr  
run_resultresume_stateshould_record_run_resultr  r   pending_run_resultr  run_result_streamingr4  dispatch_taskstream_iteration_cancelledr6  rG  rw   r+  r   r7  r8  r9  itemtext_outputr.  r3  r-  r   r'  custom_output_extractorr   r   r%  	on_streamr   r&  r   r   r   r(  should_capture_tool_inputtool_name_resolveds6   `                                   @@@r^   _run_agent_impl&Agent.as_tool.<locals>._run_agent_impl3  s    61 &0%E%E!!K]  8#%I *IUe . > >y I 0IK#;"+DK$+$ N
 nc22:nVZ;[;[()OPP.7.CIZ","*z';/O/O&-&8&8#"<W"E';//!,#OO!--%//!(!5!5#*#9#9%//#*#9#9!--2
" +>O,0;-G%677,%6w%ON.~S0;-%,__N,%6w%GN.~S0;-%,N@DJ,0L'+$"5";":@ 6@ 6@  6@ 	@D ';//G4E4E4Q%?%%0&" &'2DoW[*\*\56H6V6VWF*%7
380#;;'9'B'B'D'00<3 , 5 5 ' 2 @ @
 6#--%8
 !(%.N+1+>+>'+E#J'=*<n(4(@d3P^F_#6"4#'3 .210<0Ho ' ,? ,( OVmmoK
 
& & %,$7$78N8P$QM16.0J(<(J(J"/C/Q/Q/S 	?e#-e5L#M#M49OOM .3-:181B1BA"
 '2oog&> > >" (.zz'+E#J'=*<n(4(@d3P^F_#6"4#'3 .210<0Ho ' (2 ( "J ))) $JFM';//G4E4E4QVc+0))"!4 '4Z@@@&&2z66<<
@W@W[]@]!...QQ !5!56d$566"-"A"A$"GK"** t%788"4;;44;;& 7 ***S	 # e(+G	{RTUXTY)Z[addev	? !? 0T  '55 "9=6!" 0T 6)002%&3 3 3#*#9#9 % $% #.//$"777"-"2"2"444"/// 6)002%&3 3 3#*#9#9 % $% #.//$"777"-"2"2"444"///!5J"4 As  A[#	V [#9V4:K#[#Y 1V? V=V7V=	AV? V:V? A[#'[(A)[#[ B*[# [#![#4[#
V1V,,V11[#7V=:V? =V? >Y ?WY [#3W? 8W;9W? >[#?X[#X[#-X0.[#Y	
[#Y[#[1Y=6Y97Y=<[=Z[Z[+Z.,[[
[[[[# [#zError running tool (non-fatal)zError running toolr6   )span_message"span_message_for_json_decode_error	log_labelT)r   
agent_nameagent_tool_name)
rb   descriptionparams_json_schemainvoke_tool_implon_handled_errorr   strict_json_schemar   needs_approvaltool_origin)r   r	   r   rR   )r   r	   rq   rk   r   r	   )r   rA   r   rk   r   r	   )rB   transform_string_function_stylerb   rR   r   r   r3   json_schemar   r   r;   r:   r8   r9   AGENT_AS_TOOL_is_agent_tool_agent_instance)r   rq   tool_descriptionra  r   rb  r   r%  r   r&  r'  r(  r   rq  
parametersr   include_input_schemar   tool_description_resolvedhas_custom_parametersinclude_schemaparams_schemare  run_agent_toolr   r   r   rc  rd  s   `  ` ```````   `        @@@@@r^   as_toolAgent.as_tool  sY   j	0 '`+*U*UVZV_V_*`$4$:! *$ 62L7LM$(!P^P}D7P%
! ()9:N5n6P6P6RSM+J77 cdd(4N5n6P6P6RSM8 .

	x	+ x	+ x	+t	 6#1,,G=3G 
 $:#!)"#1199 2
( )-%)-&r]   c           	       #    [        U R                  [        5      (       a  U R                  $ [        U R                  5      (       a  [        R
                  " U R                  5      n[        UR                  R                  5       5      n[        U5      S:w  a4  [        S[        U5       SU Vs/ s H  oDR                  PM     sn 35      e[        R                  " U R                  5      (       a.  [        [        [           U R                  X5      5      I S h  vN $ [        [        U R                  X5      5      $ U R                  b6  [        R                   " S[#        U R                  5      R$                   35        g s  snf  Nl7f)N   zR'instructions' callable must accept exactly 2 arguments (context, agent), but got r   z:Instructions must be a string or a callable function, got )ri   r   rk   r   r   	signaturer   ry  valueslenr   rb   iscoroutinefunctionr   r   r&   errorr   rW   )r   r   sigr   ps        r^   get_system_promptAgent.get_system_prompt  sC    d''--$$$d''((##D$5$56C#..//12F 6{a"6{m2v.Fv!vvv.F-GI  **4+<+<==!)C.$2C2CK2VWWWC!2!2;!EFF*LLD--.778:
  /G
 Xs    B.F0FAFF	A-Fc           
        #    SSK Jn  [        R                  " U R                  U[        [        [           U" U 5      5      5      I Sh  vN $  N7f)zGet the prompt for the agent.r   )get_public_agentN)_public_agentr  r0   to_model_inputr   r   r   r2   )r   r   r  s      r^   
get_promptAgent.get_prompt  sE      	4..KKx"24"89
 
 	
 
s   AA	A
A)r   )r   r	   r   zAgent[TContext])"rq   r   rx  r   ra  zACallable[[RunResult | RunResultStreaming], Awaitable[str]] | Noner   zObool | Callable[[RunContextWrapper[Any], AgentBase[Any]], MaybeAwaitable[bool]]rb  z=Callable[[AgentToolStreamEvent], MaybeAwaitable[None]] | Noner   zRunConfig | Noner%  z
int | Noner   zRunHooks[TContext] | Noner&  r   r'  r   r(  zSession | Noner   zToolErrorFunction | Nonerq  zObool | Callable[[RunContextWrapper[Any], dict[str, Any], str], Awaitable[bool]]ry  ztype[Any] | Noner   z!StructuredToolInputBuilder | Nonerz  rR   r   r4   )r   r   r   r   )r   r   r   zResponsePromptParam | None)rW   rX   rY   rZ   r{   r   r[   r   r   r   r   r   r)   r   r   r   r   r   r   r   r   r   r>   r  r  r  r\   rV   r]   r^   r   r      s	   
& 	 	 59F18
 ;@PT:UH7U
 !%E$ %*:T$UNMU 8=T7R4R :?t9T6T =AK9@ *.E&-
 	 a& #t"ZCJ3* UYSW'+ $+/+/&*"&;VUZ'+;?%*+ll %l
 NlSl Ql %l l )l )l $l  l  !9!l"S#l& %'l( 9)l* #+l, 
-l\:

6

	#

r]   r   )rn   r   r   r<  )u
__future__r   r   r   r   collections.abcr   r   r   r   r   r   r	   r
   r   r   r   ,openai.types.responses.response_prompt_paramr   pydanticr   r   r   typing_extensionsr   r   _tool_identityr   r   r   agent_tool_inputr   r   r   r   agent_tool_stater   r   r   r   r    
exceptionsr!   r"   	guardrailr#   r$   r   r%   r&   mcpr'   r   r(   models.default_modelsr)   r*   r+   r   r-   promptsr.   r/   r0   r   r1   r2   strict_schemar3   ro   r4   r5   r6   r7   r8   r9   r:   r;   r<   r=   r>   r?   r>  rA   utilrB   util._typesrC   2openai.types.responses.response_function_tool_callrD   rL  rE   r   rF   rG   rH   memory.sessionrI   resultrJ   rK   r=  rL   	run_staterM   rF  rN   rP   r   r_   r[   rs   ru   r}   r   r   r   rV   r]   r^   <module>r     ss   "    / ( H H L < < 4 ; /   6 6    ) 
 $ > > 4 4    &  '['/'5#* 	 	 	 )1x $'9":;+,.) I 

4
39 
3W) W
	  >! > >B N
Iwx( N
 N
r]   