
    Cji                      % S SK Jr  S SKrS SKrS SKrS SKJr  S SKJr  SSK	J
r
  SSKJr  SSKJr  SS	KJr  SS
KJrJrJrJrJr  SSKJr  SSKJrJrJr  SSKJr  SSKJr  SSK J!r!  SSK"J#r#J$r$  SSK%J&r&J'r'J(r(J)r)J*r*J+r+J,r,J-r-J.r.  SSK/J0r0J1r1  SSK2J3r3  SSK4J5r5  SSK6J7r7J8r8J9r9J:r:J;r;J<r<J=r=J>r>J?r?J@r@JArAJBrBJCrCJDrDJErEJFrFJGrGJHrH  SSKIJJrJ  SSKKJLrLJMrMJNrNJOrOJPrP  SSKQJRrRJSrS  SSKTJUrU  SSKVJWrW  SSKXJYrY  SSKZJ[r[J\r\J]r]J^r^J_r_J`r`JaraJbrbJcrcJdrdJere  SSKfJgrgJhrhJiriJjrj  SSKkJlrlJmrmJnrnJoroJprpJqrqJrrr  SSKsJtrtJuruJvrv  SS KwJxrx  SS!KyJzrz  SS"K{J|r|  SS#K}J~r~  SS$KJrJr  SS%KJrJrJrJrJrJr  SS&KJrJr  SS'KJrJr  SS(KJr  SqS)\S*'   / S+QrS3S, jrS4S- jr        S5S. jr        S6S/ jr " S0 S15      r " S2 S)5      r\" 5       qg)7    )annotationsN)cast)Unpack   )_debug)get_tool_trace_name_for_tool)Agent)set_agent_tool_state_scope)AgentsExceptionInputGuardrailTripwireTriggeredMaxTurnsExceededRunErrorDetails	UserError)InputGuardrailResult)ItemHelpersRunItemTResponseInputItem)RunHooks)logger)Session)	RunResultRunResultStreaming)	DEFAULT_MAX_TURNSCallModelDataCallModelInputFilterModelInputDataReasoningItemIdPolicy	RunConfig
RunOptionsToolErrorFormatterToolErrorFormatterArgs)RunContextWrapperTContext)RunErrorHandlers)bind_public_agent)append_model_response_if_new#apply_resumed_conversation_settingsattach_usage_to_spanbuild_interruption_result build_resumed_stream_debug_extraensure_context_wrapperfinalize_conversation_tracking.get_unsent_tool_call_ids_for_interrupted_stateinput_guardrails_triggeredresolve_processed_responseresolve_resumed_contextresolve_trace_settingssave_turn_items_if_needed9should_cancel_parallel_model_task_on_input_guardrail_tripsnapshot_usage!update_run_state_for_interruptionusage_delta&validate_session_conversation_settings)approvals_from_step)build_run_error_datacreate_message_output_itemformat_final_output_text resolve_run_error_handler_resultvalidate_handler_final_output)copy_input_itemsnormalize_resumed_input)OpenAIServerConversationTracker)PromptCacheKeyResolver)resolve_run_grouping_id)get_all_toolsget_handoffsget_output_schemainitialize_computer_toolsresolve_interrupted_turnrun_final_output_hooksrun_input_guardrailsrun_output_guardrailsrun_single_turnstart_streamingvalidate_run_hooks)NextStepFinalOutputNextStepHandoffNextStepInterruptionNextStepRunAgain)(persist_session_items_for_guardrail_tripprepare_input_with_sessionresumed_turn_itemssave_result_to_sessionsave_resumed_turn_itemssession_items_for_turnupdate_run_state_after_resume)AgentToolUseTrackerhydrate_tool_use_trackerserialize_tool_use_tracker)RunState)terminal_metadata_for_exception)SandboxRuntime)dispose_resolved_computers)ToolInputGuardrailResultToolOutputGuardrailResult)Span	SpanError
agent_spanget_current_trace	task_span	turn_span)TraceCtxManagercreate_trace_for_run)AgentSpanDataTaskSpanData)_error_tracingAgentRunnerDEFAULT_AGENT_RUNNER)rm   Runnerr   r   r\   r"   r   r   r   r   r    r!   r   set_default_agent_runnerget_default_agent_runnerc                *    U =(       d
    [        5       qg)d
WARNING: this class is experimental and not part of the public API
It should not be used directly.
N)rm   rn   )runners    \/home/rurouni/.local/share/pipx/venvs/strix-agent/lib/python3.13/site-packages/agents/run.pyrp   rp      s     "2[]    c                     [         $ )rs   )rn    rv   ru   rq   rq      s
      rv   c                H    U R                   c  g [        UUU R                  S9$ )N)conversation_idsessiongroup_id)sandboxrB   r|   
run_configrz   r{   s      ru   _sandbox_memory_rollout_idr      s/     !"'$$ rv   c                P    U b  [        U 5      $ Ub  [        U5      $ [        U5      $ N)listr>   "memory_input_items_for_persistenceoriginal_user_inputoriginal_inputs      ru   _sandbox_memory_inputr      s3     *5677& 344N++rv   c                  &   \ rS rSr\S\SSSSSSSS.	                       S
S jj5       r\S\SSSSSSSS.	                       S
S jj5       r\S\SSSSSS4SS.                       SS jjj5       rS	r	g)ro      NF	context	max_turnshooksr   error_handlersprevious_response_idauto_previous_response_idrz   r{   c       	        \   #    [         nUR                  UUUUUUUUU	U
US9I Sh  vN $  N7f)a'	  
Run a workflow starting at the given agent.

The agent will run in a loop until a final output is generated. The loop runs like so:

  1. The agent is invoked with the given input.
  2. If there is a final output (i.e. the agent produces something of type
     `agent.output_type`), the loop terminates.
  3. If there's a handoff, we run the loop again, with the new agent.
  4. Else, we run tool calls (if any), and re-run the loop.

In two cases, the agent may raise an exception:

  1. If the max_turns is exceeded, a MaxTurnsExceeded exception is raised unless handled.
  2. If a guardrail tripwire is triggered, a GuardrailTripwireTriggered
     exception is raised.

Note:
    Only the first agent's input guardrails are run.

Args:
    starting_agent: The starting agent to run.
    input: The initial input to the agent. You can pass a single string for a
        user message, or a list of input items.
    context: The context to run the agent with.
    max_turns: The maximum number of turns to run the agent for. A turn is
        defined as one AI invocation (including any tool calls that might occur).
    hooks: An object that receives callbacks on various lifecycle events.
    run_config: Global settings for the entire agent run.
    error_handlers: Error handlers keyed by error kind. Currently supports max_turns.
    previous_response_id: The ID of the previous response. If using OpenAI
        models via the Responses API, this allows you to skip passing in input
        from the previous turn.
    conversation_id: The conversation ID
        (https://platform.openai.com/docs/guides/conversation-state?api-mode=responses).
        If provided, the conversation will be used to read and write items.
        Every agent will have access to the conversation history so far,
        and its output items will be written to the conversation.
        We recommend only using this if you are exclusively using OpenAI models;
        other model providers don't write to the Conversation object,
        so you'll end up having partial conversations stored.
    session: A session for automatic conversation history management.

Returns:
    A run result containing all the inputs, guardrail results and the output of
    the last agent. Agents may perform handoffs, so we don't know the specific
    type of the output.
r   N)rn   runclsstarting_agentinputr   r   r   r   r   r   r   rz   r{   rt   s                ru   r   
Runner.run   sN     B &ZZ!)!5&?+   
 
 	
 
s   #,*,c       	        @    [         nUR                  UUUUUUUUU
UU	S9$ )a2  
Run a workflow synchronously, starting at the given agent.

Note:
    This just wraps the `run` method, so it will not work if there's already an
    event loop (e.g. inside an async function, or in a Jupyter notebook or async
    context like FastAPI). For those cases, use the `run` method instead.

The agent will run in a loop until a final output is generated. The loop runs:

  1. The agent is invoked with the given input.
  2. If there is a final output (i.e. the agent produces something of type
     `agent.output_type`), the loop terminates.
  3. If there's a handoff, we run the loop again, with the new agent.
  4. Else, we run tool calls (if any), and re-run the loop.

In two cases, the agent may raise an exception:

  1. If the max_turns is exceeded, a MaxTurnsExceeded exception is raised unless handled.
  2. If a guardrail tripwire is triggered, a GuardrailTripwireTriggered
     exception is raised.

Note:
    Only the first agent's input guardrails are run.

Args:
    starting_agent: The starting agent to run.
    input: The initial input to the agent. You can pass a single string for a
        user message, or a list of input items.
    context: The context to run the agent with.
    max_turns: The maximum number of turns to run the agent for. A turn is
        defined as one AI invocation (including any tool calls that might occur).
    hooks: An object that receives callbacks on various lifecycle events.
    run_config: Global settings for the entire agent run.
    error_handlers: Error handlers keyed by error kind. Currently supports max_turns.
    previous_response_id: The ID of the previous response, if using OpenAI
        models via the Responses API, this allows you to skip passing in input
        from the previous turn.
    conversation_id: The ID of the stored conversation, if any.
    session: A session for automatic conversation history management.

Returns:
    A run result containing all the inputs, guardrail results and the output of
    the last agent. Agents may perform handoffs, so we don't know the specific
    type of the output.
)	r   r   r   r   r   r   rz   r{   r   )rn   run_syncr   s                ru   r   Runner.run_sync  sA    ~ &!)!5+&?  
 	
rv   )r   c               @    [         nUR                  UUUUUUUUUU	U
S9$ )a_  
Run a workflow starting at the given agent in streaming mode.

The returned result object contains a method you can use to stream semantic
events as they are generated.

The agent will run in a loop until a final output is generated. The loop runs like so:

  1. The agent is invoked with the given input.
  2. If there is a final output (i.e. the agent produces something of type
     `agent.output_type`), the loop terminates.
  3. If there's a handoff, we run the loop again, with the new agent.
  4. Else, we run tool calls (if any), and re-run the loop.

In two cases, the agent may raise an exception:

  1. If the max_turns is exceeded, a MaxTurnsExceeded exception is raised unless handled.
  2. If a guardrail tripwire is triggered, a GuardrailTripwireTriggered
     exception is raised.

Note:
    Only the first agent's input guardrails are run.

Args:
    starting_agent: The starting agent to run.
    input: The initial input to the agent. You can pass a single string for a
        user message, or a list of input items.
    context: The context to run the agent with.
    max_turns: The maximum number of turns to run the agent for. A turn is
        defined as one AI invocation (including any tool calls that might occur).
    hooks: An object that receives callbacks on various lifecycle events.
    run_config: Global settings for the entire agent run.
    error_handlers: Error handlers keyed by error kind. Currently supports max_turns.
    previous_response_id: The ID of the previous response, if using OpenAI
        models via the Responses API, this allows you to skip passing in input
        from the previous turn.
    conversation_id: The ID of the stored conversation, if any.
    session: A session for automatic conversation history management.

Returns:
    A result object that contains data about the run, as well as a method to
    stream events.
r   )rn   run_streamed)r   r   r   r   r   r   r   r   r   rz   r{   r   rt   s                ru   r   Runner.run_streamed`  sC    x &""!)!5&?+ # 
 	
rv   rx   )r   Agent[TContext]r   3str | list[TResponseInputItem] | RunState[TContext]r   TContext | Noner   intr   RunHooks[TContext] | Noner   RunConfig | Noner   !RunErrorHandlers[TContext] | Noner   
str | Noner   boolrz   r   r{   Session | Nonereturnr   )r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rz   r   r{   r   r   r   r   r   )
__name__
__module____qualname____firstlineno__classmethodr   r   r   r   __static_attributes__rx   rv   ru   ro   ro      s-    $(*+/'+<@+/*/&*"&M
'M
 CM

 !M
 M
 )M
 %M
 :M
 )M
 $(M
 $M
  M
 
M
 M
^  $(*+/'+<@+/*/&*"&K
'K
 CK

 !K
 K
 )K
 %K
 :K
 )K
 $(K
 $K
  K
 
K
 K
Z 
 $(*+/'++/*/&*"&H
 =AH
'H
 CH
 !	H

 H
 )H
 %H
 )H
 $(H
 $H
  H
 :H
 
H
 H
rv   ro   c                  f    \ rS rSrSr        SS jr        SS jr        S	S jrSrg)
rm   i  zr
WARNING: this class is experimental and not part of the public API
It should not be used directly or subclassed.
c                I  ^^g^h^i^j^k^l^m#    UR                  S5      nUR                  S[        5      n[        [        [           [        UR                  S5      5      5      nUR                  S5      nUR                  S5      nUR                  S5      n	UR                  SS5      n
UR                  S	5      nUR                  S
5      nUc
  [        5       n[        U[        5      nS mjU(       d  UOS nS nUb	  U(       a  / OS nS nU(       a  [        [        [           U5      mj[        TjUU	U
S9u  nn	n
[        UUU	U
S9  TjR                  n[        TjR                  5      n[        U5      n[        TjUS9nUR                  nTjR                   nO[        ["        [$        [&           -  U5      nUn[        UUU	U
S9  US L=(       d    U	S L=(       d    U
nU(       a2  [)        UUUR*                  UR,                  SSS9I S h  vN u  nnUn/ nO/[)        UUUR*                  UR,                  5      I S h  vN u  nnUnUR.                  b  UR.                  OTjb  TjR0                  OS miTjb  TiTjl        Uc
  U	c  U
(       a  [3        UU	U
TiS9mlOS mlUS L=(       a    TlS L nU(       a  Ub  [%        U5      OS nTlbb  U(       a[  TjbX  S nUb   UR5                  5       I S h  vN nTlR9                  TjR                  TjR:                  TjR<                  U[?        Tj5      S9  [A        5       mmU(       a  Tjb  [C        TmTjT5        [E        TjUS9u  nnnnn[G        UUUUUURH                  Tjb  TjRJ                  OS US9   U(       a  Tjb  TjRM                  [O        5       5        TjRP                  n TjR                  n![        U!5      n"TjR:                  n#[%        TjRR                  5      n$TjR<                  n%[        [T        [           TjRV                  5      nOYSn [        W5      n"/ n#/ n$/ n%[Y        U5      n[[        US 5        [        UU"TUUU	U
S9mjTiTjl        TjRM                  [O        5       5        []        US9n&U&R_                  SS9  [a        URb                  5      n' [e        TU[g        UUUS9TjS9mk[h        Rj                  " TjS9n(S mhS n)S[UiUj4S jjmgS\UjUUm4S jjn*S[UgUhUjUkUlU4S jjn+S n,Tjb  [%        TjRl                  5      O/ n-Tjb  [%        [o        TjS/ 5      5      O/ n.Tjb  [%        [o        TjS/ 5      5      O/ n/S n0U(       a  Tjb  TjRp                  b  TjRp                  n1OTn1TkRs                  U15        Sn2U1Rt                  Rw                  URt                  5      Rx                  n3U(       d4  U(       a-  Ub*  Uc'  TkRs                  U15        [z        R|                  " U5      nU(       a:  U(       a3  TkR~                  (       d"  [%        U5      n[        UU/ TjU3S 9I S h  vN   / n  Un4U S:X  a)  U4(       d"  TR                  UR                  =(       d    / -   O/ n5U5 V6s/ s H  n6U6R                  (       a  M  U6PM     n7n6U5 V6s/ s H  n6U6R                  (       d  M  U6PM     n8n6/ n9TkR~                  (       a)  U7(       a"   [        TU7[        U"5      U5      I S h  vN n9/ n7[        U15      n:U:R                  n;TkR                  U1U"UU4S"9I S h  vN n<U<R                  n:U:R                  n;[        U<R                  5      n"Ub*  [        U[        5      (       d  [        U<R                  5      nTjb  [        U"5      Tjl        Ub  [        U[        5      (       d  UOS#n=U1Rt                  Rw                  URt                  5      Rx                  n3U(       a2  U(       a+  [%        U5      n[        U[%        U5      / TjU3S 9I S h  vN   / nTjGby  TjR                  Gbk  [        TjR                  [        5      (       GaK  [        R                  " S$5        TjR<                  (       a  TjR                  (       d  [        S%5      e[        U:U"U#TjR<                  S&   TjR                  UUUTlS LTjS'9
I S h  vN n>TjR                  b  TmR                  U1TjR                  5        U>R                  n"[        U>5      u  n#n?U$R                  U?5        Tjb  [        TjU>U#U$S(9  U(       aW  U>R                  (       aF  TjbC  [        UU?TjR                  U>R                  R                  TjR0                  U3S)9I S h  vN Tjl]        Sn[        U>R                  [        5      (       Ga  U"n@[        U%U>R                  5        [        TjU>R                  S*9nATjb  [        TjU%WAU#U$U U>R                  S+9  [        S]0 S,W@_S-U$_S.U%_S/U1_S0U-_S1U>R                  _S2U>R                  _S3U_S4[        U>R                  5      _S5WA_S6Tm_SU_S7U _S8U#_S9Tj_S:U"_6nBU+" UB5        [        UUU"S;9nCThb  TkR                  ThWCS<9I S h  vN   O=U)b:  [o        TjS=S 5      nDTkR                  WCU$S [        UD5      [        U)5      S>9I S h  vN   TkR                  5       I S h  vN nFThb  WFThlo        Thb  S Thlp         [        USA9I S h  vN   U0(       a  U0R                  SS!9  U&(       a/  [        U&[        U'URb                  5      5        U&R                  SS!9  sS S S 5        $ [        U>R                  [        5      (       a  GM2  [        U%U>R                  5        U.R                  U>R                  5        U/R                  U>R                  5        [        U>R                  [        5      (       Ga3  [        U1R                  UR                  =(       d    / -   U1U>R                  R                  U5      I S h  vN nG[o        TjS=S 5      nD[        UD5      nH[        U>R                  U$U%U>R                  R                  U1U-UGU.U/UUHU*" 5       USC9nBU UBl(        [%        U#5      UBlx        [%        U#5      [%        U$5      :g  UBly        Tjb  TjRJ                  WBl%        U(       a:  Ub  UO/ nI[        UUI[        U>5      TjU>R                  R                  U3SD9I S h  vN   [        U"5      WBl        U+" UB5        [        UUU"S;9nCThb  TkR                  ThWCS<9I S h  vN   O=U)b:  [o        TjS=S 5      nDTkR                  WCU$S [        UD5      [        U)5      S>9I S h  vN   TkR                  5       I S h  vN nFThb  WFThlo        Thb  S Thlp         [        USA9I S h  vN   U0(       a  U0R                  SS!9  U&(       a/  [        U&[        U'URb                  5      5        U&R                  SS!9  sS S S 5        $ [        U>R                  [        5      (       af  [        [        [           U>R                  R                  5      n1Tjb  U1Tjl8        U>R                  nU>R                  n"U0b  U0R                  SS!9  S n0Sn2GMV  GMY  Tjb  TjR                  c  [        5       TjlO        [        U;U5      I S h  vN nJ[        UJUSE9I S h  vN   U0c  G[        U;U5      I S h  vN  VKs/ s H  nKUKGR                  PM     nLnKG[        U;5      =nM(       a  WMGR                  5       nNOSFnNG[	        U1GR                  WLWNSG9n0U0R_                  SS9  WJ VOs/ s H  nOG[        UO5      =nPc  M  WPPM     snOU0GR                  l        U SH-  n U U:  Ga  G[        GR                  " U0G[        SISU0SJ95        G[        SKU SL35      nQG[        U"U$U%U1TiSM9nRG[        UUQUURSN9I S h  vN nSUSc  WQeG[        U1WSGR                  5      nTG[!        U1UT5      nUG[#        U1UU5      nVUSGR$                  nWUW(       a$  U#GR'                  WV5        U$GR'                  UV5        G[)        U1UUWT5      I S h  vN   [        U1R                  UR                  =(       d    / -   U1WTU5      I S h  vN nG[o        TjS=S 5      nD[        UD5      nH[        U"U$U%WTU1U-UGU.U/UUHU*" 5       USC9nBUUBl(        [%        U#5      UBlx        [%        U#5      [%        U$5      :g  UBly        Tjb  TjRJ                  WBl%        U(       a%  WW(       a  Ub  UO/ nX[        UUXWV/TjS U3SD9I S h  vN   [        U"5      WBl        U+" UB5        [        UUU"S;9nCThb  TkR                  ThWCS<9I S h  vN   O=U)b:  [o        TjS=S 5      nDTkR                  WCU$S [        UD5      [        U)5      S>9I S h  vN   TkR                  5       I S h  vN nFThb  WFThlo        Thb  S Thlp         [        USA9I S h  vN   U0(       a  U0R                  SS!9  U&(       a/  [        U&[        U'URb                  5      5        U&R                  SS!9  sS S S 5        $ Tjb  U4(       d  STjl]        [        R                  " SOU1GR                  U 5        U(       a   [z        R|                  " U"5      nTlb	  U,(       a  U,OU#nY[a        URb                  5      nZG[+        U U1GR                  SP9n[U[R_                  SS9   U SH::  a   U7(       a  [        TU7[        U"5      U5      I S h  vN n9/ n\G[,        GR.                  " G[1        U:WJU"WYUUUU2TmTlUU(       d	  U(       a  UOS TiU(SQ95      n]U8(       a;   G[,        GR2                  " [        TU8[        U"5      U5      W]5      I S h  vN u  n\n>O
W]I S h  vN n>U-R                  U95        U-R                  W\5        O/G[1        U:WJU"WYUUUU2TmTlUU(       d	  U(       a  UOS TiU(SQ9I S h  vN n>[        W[[        WZURb                  5      5        U[R                  SS!9  S nSn2U%GR'                  U>R                  5        U>R                  n"U>GR:                  U>R                  -   n#[        U>5      n?U$R                  U?5        Tlb1  [%        U>R                  5      n,TlGR=                  U>R                  5        U.R                  U>R                  5        U/R                  U>R                  5        [%        U?5      n^[        U>R                  [        5      (       Gd2  U(       a<  Tj(       a5  TjR                  S:  a%  W^ V_s/ s H  n_U_GR>                  SS:w  d  M  W_PM     n^n_U(       Ga  U>R                   V_s1 s Hk  n_U_GR>                  ST:X  d  M  [        W_GR@                  G[B        5      (       a  W_GR@                  R                  SU5      O[o        W_GR@                  SUS 5      iMm     n`n_U# H  n_U_GR>                  SS:w  a  M  [        W_GR@                  G[B        5      (       a  W_GR@                  R                  SU5      O[o        W_GR@                  SUS 5      naUaW`;   d  Ms  W_W^;  d  M{  Tj(       a  TjR                  S:  a  M  W^GR'                  W_5        M     W^(       a  [        R                  " SVW^ V_s/ s H  n_U_GR>                  PM     sn_5        U(       aN  TjbK  [        U/ W^S U>R                  R                  TjR0                  U3SW9I S h  vN nbTj=R                  Ub-  sl]        O*[        U/ W^TjU>R                  R                  U3SD9I S h  vN   Sn [        U>R                  [        5      (       Ga>  [        U1R                  UR                  =(       d    / -   U1U>R                  R                  U5      I S h  vN nGU=nc[        UcU$U%U>R                  R                  U1U-UGU.U/U/ U*" 5       USC9nBU UBl(        [%        U#5      UBlx        [%        U#5      [%        U$5      :g  UBly        Tjb  TjR                  WBl]        G[E        UTjUU-[        U>5      U>R                  R                  U3SX9I S h  vN   [        U"5      WBl        U+" UB5      U>GR:                  GRG                  5         U>R                  GRG                  5           [        UUU"S;9nCThb  TkR                  ThWCS<9I S h  vN   O=U)b:  [o        TjS=S 5      nDTkR                  WCU$S [        UD5      [        U)5      S>9I S h  vN   TkR                  5       I S h  vN nFThb  WFThlo        Thb  S Thlp         [        USA9I S h  vN   U0(       a  U0R                  SS!9  U&(       a/  [        U&[        U'URb                  5      5        U&R                  SS!9  sS S S 5        $ [        U>R                  [        5      (       Ga  U(       aK  G[I        U-5      (       d:  Ub  UO/ nd[        UUd[        U>5      TjU>R                  R                  U3SD9I S h  vN   [        U%U>R                  5        [        TjU>R                  S*9nATjb  [        TjU%WAU#U$U U>R                  S+9  U=ne[        S]0 S,Ue_S-U$_S.U%_S/U1_S0U-_S1U._S2U/_S3U_S4[        U>R                  5      _S5WA_S6Tm_SU_S7U _S8U#_S9Tj_S:U"_6nBU+" UB5      U>GR:                  GRG                  5         U>R                  GRG                  5           [        UUU"S;9nCThb  TkR                  ThWCS<9I S h  vN   O=U)b:  [o        TjS=S 5      nDTkR                  WCU$S [        UD5      [        U)5      S>9I S h  vN   TkR                  5       I S h  vN nFThb  WFThlo        Thb  S Thlp         [        USA9I S h  vN   U0(       a  U0R                  SS!9  U&(       a/  [        U&[        U'URb                  5      5        U&R                  SS!9  sS S S 5        $ [        U>R                  [        5      (       aa  [        [        [           U>R                  R                  5      n1Tjb  U1Tjl8        U>R                  nU>R                  n"U0R                  SS!9  S n0Sn2O[        U>R                  [        5      (       ap  G[E        UTjUU-[        U>5      U>R                  R                  U3SX9I S h  vN    U>GR:                  GRG                  5         U>R                  GRG                  5         GM  G[K        SYG[?        U>R                  5       35      e U>GR:                  GRG                  5         U>R                  GRG                  5         GM/   GND GN GNr! [6         a    S n GNf = f GNT! [         a1    [        U&[        U'URb                  5      5        U&R                  SS!9  e f = fs  sn6f s  sn6f  GN! [         a    [        UTlUUTjU3S 9I S h  vN  ne f = f GN GN GNG GN GN GNX! [6         a"  nE[        R                  " S?UE5         S nEAEGN}S nEAEff = f GNr! [6         a"  nE[        R                  " S@UE5         S nEAEGNS nEAEff = f! Thb  S Thlp        f f = f GN! [6         a"  nE[        R                  " SBUE5         S nEAEGNS nEAEff = f GN GN GN GNF! [6         a"  nE[        R                  " S?UE5         S nEAEGNkS nEAEff = f GN`! [6         a"  nE[        R                  " S@UE5         S nEAEGN{S nEAEff = f! Thb  S Thlp        f f = f GN|! [6         a"  nE[        R                  " SBUE5         S nEAEGNS nEAEff = f GN GN GNys  snKf s  snOf  GN GN GN GN/ GN GN! [6         a"  nE[        R                  " S?UE5         S nEAEGNS nEAEff = f GN! [6         a"  nE[        R                  " S@UE5         S nEAEGNS nEAEff = f! Thb  S Thlp        f f = f GN! [6         a"  nE[        R                  " SBUE5         S nEAEGNS nEAEff = f! [6         a    S n GNf = f GN! [         a    [        UTlUUTjU3S 9I S h  vN  ne f = f GN! [         ap    G[5        5       (       aG  W]GR7                  5       (       d  W]GR9                  5         G[,        GR2                  " W]SSR9I S h  vN    [        UTlUUTjU3S 9I S h  vN  ne f = f GN3 GN! [        W[[        WZURb                  5      5        U[R                  SS!9  f = fs  sn_f s  sn_f s  sn_f  G
N G	N G	Nk GN GNO GN! [6         a"  nE[        R                  " S?UE5         S nEAEGN9S nEAEff = f GN.! [6         a"  nE[        R                  " S@UE5         S nEAEGNIS nEAEff = f! Thb  S Thlp        f f = f GNJ! [6         a"  nE[        R                  " SBUE5         S nEAEGNoS nEAEff = f GN GN GN! [6         a"  nE[        R                  " S?UE5         S nEAEGNS nEAEff = f GN! [6         a"  nE[        R                  " S@UE5         S nEAEGNS nEAEff = f! Thb  S Thlp        f f = f GN! [6         a"  nE[        R                  " SBUE5         S nEAEGNS nEAEff = f GN! U>GR:                  GRG                  5         U>R                  GRG                  5         f = f! [         a3  nfUfn)[        UfG[J        5      (       a  G[M        U"U$U%U1UU-/ SZ9Wfl        e S nfAfff = f!   [        UUU"S;9nCThb  TkR                  ThWCS<9I S h  vN    OmU)b;  [o        TjS=S 5      nDTkR                  WCU$S [        UD5      [        U)5      S>9I S h  vN    O.! [6         a!  nE[        R                  " S?UE5         S nEAEOS nEAEff = fTkR                  5       I S h  vN  nFThb  WFThlo        O.! [6         a!  nE[        R                  " S@UE5         S nEAEOS nEAEff = fThb  S Thlp        O! Thb  S Thlp        f f = f [        USA9I S h  vN    O.! [6         a!  nE[        R                  " SBUE5         S nEAEOS nEAEff = fU0(       a  U0R                  SS!9  U&(       a0  [        U&[        U'URb                  5      5        U&R                  SS!9  f f = f! , (       d  f       g = f7f)^Nr   r   r   r   r   r   r   Frz   r{   	run_staterz   r   r   rz   r   r   r   r   T)!include_history_in_prepared_inputpreserve_dropped_new_items)rz   r   r   reasoning_item_id_policy)r   generated_itemsmodel_responsessession_itemsunsent_tool_call_idsr   r   workflow_nametrace_idr|   metadatatracingdisabledtrace_statereattach_resumed_tracer   r   r   r   r   rz   r   r   )name)mark_as_currentr~   r   r   
rollout_idr   )r   c                *   > TU l         Tb  TTl         U $ r   )_reasoning_item_id_policy)result!resolved_reasoning_item_id_policyr   s    ru   _with_reasoning_item_id_policy7AgentRunner.run.<locals>._with_reasoning_item_id_policy  s    7XF4 ,>_	;!Mrv   c                 T   > Tn Tb  TR                   b  TR                   n [        TU S9$ )N)r   )_starting_agentr[   )identity_root_agentr   r   tool_use_trackers    ru   _tool_use_tracker_snapshot3AgentRunner.run.<locals>._tool_use_tracker_snapshot  s9    *8' ,1J1J1V.7.G.G+5(': rv   c                   > Tb  TR                   b  TR                   OTU l        [        T" U 5      TTS9nTR                  U5        Tb  TR                  Ul        UmU$ )N)server_conversation_trackerr   )r   _starting_agent_for_stater,   apply_result_metadata_generated_prompt_cache_key)r   finalized_resultr   completed_resultr   sandbox_runtimer   r   s     ru   _finalize_result)AgentRunner.run.<locals>._finalize_result  s~     %0Y5N5N5Z "11+ 4
 (F6v>4O"+($
 $99:JK ,%AA )D (8$++rv   _tool_input_guardrail_results_tool_output_guardrail_results)store)reset_current)current_agentcurrent_inputcontext_wrapperis_resumed_state zContinuing from interruptionz)No model response found in previous state)
bindingsr   original_pre_step_itemsnew_responseprocessed_responser   r   r   server_manages_conversationr   )turn_resultr   r   )r{   itemspersisted_countresponse_idr   r   )r   r   )r   r   r   r   r   current_turn	next_stepresult_inputr   r   r   input_guardrail_resultstool_input_guardrail_resultstool_output_guardrail_resultsr   interruptionsr   r   r   r   r   r   r   )input_override_current_step)r   	new_itemsfinal_outputr   terminal_metadataz.Failed to enqueue sandbox memory after run: %sz2Failed to clean up sandbox resources after run: %s)run_contextz)Failed to dispose computers after run: %s)r   r   raw_responsesr   _last_agentr   output_guardrail_resultsr   r   r   r   r   r   )r   r   )toolsr   str)r   handoffsoutput_typer   zMax turns exceeded)messagedatazMax turns (z
) exceeded)r   r   r  
last_agentr   )r   errorr   run_datazRunning agent %s (turn %s))turn
agent_name)r   	all_toolsr   r   r   r   r   should_run_agent_start_hooksr   r   r{   session_items_to_rewindr   prompt_cache_key_resolver)return_exceptionstool_call_itemtool_call_output_itemcall_idz Persisting turn items (types=%s))r   r   r   )r{   r   session_persistence_enabledr   r   r   r   zUnknown next step type: )r   r   r  r
  r   r   r  )r   r   r   r   )r   zdict[str, list[str]]rx   )getr   r   r   r#   rM   r   
isinstancer\   r'   r7   _original_inputr>   r?   r0   r   
_max_turnsr  r   r   rS   session_input_callbacksession_settingsr   r   r@   	get_items	Exceptionhydrate_from_state_generated_items_model_responsesr-   rY   rZ   r1   rh   tracing_disabled_trace_state	set_tracere   _current_turn_session_itemsr"   _contextr+   r
   rf   startr4   usager^   r   rA   from_run_state_input_guardrail_resultsgetattr_current_agentassert_agent_supportedmodel_settingsresolver   r   input_to_new_input_listenabledrU   BaseExceptionr(   r6   finishinput_guardrailsrun_in_parallelrI   r   rR   r%   execution_agentprepare_agentr   r   r   rP   r   debug_last_processed_responser   rG   record_processed_responser   rT   extendrX   new_step_itemsrV   "_current_turn_persisted_item_countmodel_responser   r   r&   r/   r   r5   r)   r   r   r8   r   enqueue_memory_resultenqueue_memory_payloadr]   warningcleanup_sandbox_resume_state_sandbox_sessionr_   rQ   rN   rJ   output_guardrailsoutputr   _model_input_items_replay_from_model_input_itemsrW   rO   r	   	new_agentrC   rF   rD   r  rE   r   rd   r   	span_datar  rl   attach_error_to_spanrc   r   r9   r<   r=   r   r;   r:   include_in_historyappendrH   rg   asynciocreate_taskrK   gatherr3   donecancelpre_step_itemstrack_server_itemstyperaw_itemdictr2   clearr.   r   r   r  )nselfr   r   kwargsr   r   r   r   r   r   r   rz   r{   r   starting_inputr   #session_input_items_for_persistence$last_saved_input_snapshot_for_rewindprepared_inputr   	raw_inputr   _original_input_for_stater  r   session_input_itemstrace_workflow_namer   trace_group_idtrace_metadatatrace_configr   raw_original_inputr   r   r   r   current_task_spantask_usage_startr  run_exceptionr   r   pending_server_itemsr   r   r   current_spanr   r  store_settingresuming_turnall_input_guardrailsgsequential_guardrailsparallel_guardrailssequential_resultscurrent_bindingsr8  prepared_sandboxnormalized_starting_inputr   turn_session_itemsinterruption_result_inputprocessed_response_for_stater   memory_inputcurrent_stepr  sandbox_resume_stater  approvals_from_stateinput_items_for_save_1r  hhandoff_namesoutput_schemaoutput_type_nametool	tool_namemax_turns_errorrun_error_datahandler_resultvalidated_outputoutput_textsynthesized_itemrN  handler_input_items_for_saveitems_for_modelturn_usage_startcurrent_turn_spanparallel_results
model_taskitems_to_save_turnitemoutput_call_idsr  saved_countfinal_output_result_input!input_items_for_save_interruptioninterruption_result_input2excr   r   r   r   r   r   r   sn    `                                                                                                     @@@@@@@ru   r   AgentRunner.run  s(     **Y'JJ{,=>	Xh');FJJw<O)PQZZ-
$45%zz*@A$*JJ/JE$R! **%67**Y'"J%eX6/3	&6DEI&+;B$ 	,
 QU,Xh/7I
 4# /%9*C		$) 3 /%9*C	 '66N"293L3L"M45HIN5#O &--G!,,IS4(:#;;UCI"+2 /%9*C	  t+ -'t3-, ( +*D55//6;/3+ %! ,5(683
 555//	 "7 ,:( 22> //9B9N)55TX 	*
  2SI/ '#/(*I /%9*C)J	+' +/'&-T&9&a>Y]a>a# +/R/^ 45 	+ '27GILaCG"/070A0A0C*C' (::(88 ) : : ) : :1%ST]%^ ;  /0	 5$%5y.Q #Y:N	
 -## 002;2G	..T#3	
  I$9##$5$78(66%.%>%>"!89K!L"+"<"< $Y%=%= >"+"<"<"&'8'BIDVDV"W !12J!K"$ ""$"8"A*?DA$+#1#1'$3)=.G	 7X	3##$5$784=CV4W##D#9-o.C.CDt"0#1)9#-(7 ' 
 (	# -C,Q,Q'-) 6: 6:" " , ,( >B$@I@UD;;<[] (
 !, ,KRPQ - !, ,LbQR . <@$!-!00<$-$<$<M$2M66}E/3, - < < D D--!% 
 )3+7;C#::=I:E:]:]+;7
 0;+33 <@@c;d80;!+   ;=7YA$4M (1,] '77:;V;V;\Z\] ) $8-#7aq?P?P#7 * - 7K*`6JaN_N_16J'*`EG&&..3H"7K . 5 0 @ /	8 2.$ 13-'8'G$&6&F&FO-<-J-J&3&4(7)6	 .K . ($ (8'@'@$&6&F&FO%56F6L6L%MN%1*^U]:^:^)9:J:P:P)Q ,4D^4T	1 *5jYa>b>b ' .
 %2$@$@$H$H"11%e "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;%k&;&;=PQQ=R - ? ?#-#?#?#E2!G - + 5 5 < < /> 84 !: 6 &/&?*7.=-8-B-B-I-I,98O9Q=Y>[0?.0;U;W*3&F 4@F08<_8MF5DHDY]a -^ EFA  )4$-$P$P !' I #<(/*3<W8O&<[&I,7,F,F,R,R&3#   6Fn5UF2#3F#;r $2288:#2288:A`'<?a0C+9(
 ,7"1"G"G 0/; #H #   +6+29ot+TL"1"H"H&2*7-1.A,.O2QR_2` #I #   2A1H1H1J+J( (3AU(>'3<@(9W4QQQ   ''d';$()#$4o6K6KL &,,4,@w	
 	
P ((=(=?STT:'ABY'Z'Z ,O+Z )L-/ %F
 +A(/(I(>{(K(14?4N4N4Z4Z.;+& %& %& 9 /1K1K <V*33>3Q3Q<8  )4 A.74C7S4C2?1=.9.C.C!" !: 7 &? &-G&.;& 1@& /<	&
 9P& >Z& ?\& 1@& /B+BWBW.X& 4P& 2B& +4& .:& 1@& +4&  0>!&F$ $4F#;@ $2288:#2288:A`'<?a0C+9(
 ,7"1"G"G 0/; #H #   +6+29ot+TL"1"H"H&2*7-1.A,.O2QR_2` #I #   2A1H1H1J+J( (3AU(>'3<@(9W4QQQ   ''d';$()#$4o6K6KL &,,4,@w	
 	
B ((=(=OO,0x+BWBWBaBa,bM(4;H	 8 .9-G-GN-8-G-GN(//d/C+/L;?8'(=(=?OPP";(/*3<W8O&<[&I,7,F,F,R,R&3#   % $2288:#2288: #2":4@U@U;V:W X#  9* $2288:#2288:} c%R +D  /*.'/P ! $% 0/2G2GH "((t(< - +a2  ? "&N$+$?$G$7$-*7'" !" !" @ "" (4"+H%&@ % `'WY^__`+J  `NN#WY^__` (3<@(9 4 R  WNN#NPUVVW[<"N%&X % `'WY^__`+J  `NN#WY^__` (3<@(9 4 R  WNN#NPUVVWS !V &Z)8.*&4HL % `'WY^__`+J  `NN#WY^__` (3<@(9 4 R  WNN#NPUVVWW  ) HCG@H&:& $C &*R(/(C(K(;(1.;+& %& %& !D !&&NE& (G !*'`'b'b/9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7Q7BQ:Q:
BRRBRc                   UR                  S5      nUR                  S[        5      nUR                  S5      nUR                  S5      nUR                  S5      nUR                  S5      n	UR                  SS5      n
UR                  S	5      nUR                  S
5      n [        R                  " 5       nUb  [	        S5      e[        R
                  " 5       n[        R                  " 5          [        R                  " S[        5         UR                  5       nS S S 5        WR                  U R                  UUUUUUUUU	U
US95      n UR                  U5      UR!                  5       (       dC  ["        R$                  " [        5         UR                  UR'                  5       5        S S S 5        $ $ ! [         a    S n GNf = f! [         a$    UR                  5       nUR                  U5         Nf = f! , (       d  f       N= f! , (       d  f       $ = f! [(         aw    UR+                  5       (       d`  UR-                  5         ["        R$                  " [        R.                  5         UR                  U5        S S S 5        e ! , (       d  f       e = fe f = f! UR!                  5       (       dT  ["        R$                  " [        5         UR                  UR'                  5       5        S S S 5        f ! , (       d  f       f = ff = f)Nr   r   r   r   r   r   r   Frz   r{   zNAgentRunner.run_sync() cannot be called when an event loop is already running.ignore)	r{   r   r   r   r   r   r   r   rz   )r  r   rP  get_running_loopRuntimeErrorget_event_loop_policywarningscatch_warningssimplefilterDeprecationWarningget_event_loopnew_event_loopset_event_looprQ  r   run_until_complete	is_closed
contextlibsuppressshutdown_asyncgensr4  rS  rT  CancelledError)r[  r   r   r\  r   r   r   r   r   r   r   rz   r{   already_running_looppolicydefault_looptasks                    ru   r   AgentRunner.run_sync
  s    **Y'JJ{,=>	

7#ZZ-
$45%zz*@A$*JJ/JE$R! **%67**Y'	(#*#;#;#=   + `  ..0$$&!!(,>?4%446 ' ''HH#%-%9*C /  
 	W2248  ))++  ((6 33L4S4S4UV 76 ,i  	(#' 	(    4%446%%l34	 '&V 76  	 99;;(()?)?@ 33D9 A A@E	  ))++  ((6 33L4S4S4UV 766 ,s   !F5 .G9GH  H
5GG+G63G95G66G99
H

H	AJ.J	 	J	
J		JJ 0L
 K8/	L
8
LL
c                
   UR                  S5      nUR                  S[        5      n[        [        [           [        UR                  S5      5      5      nUR                  S5      nUR                  S5      nUR                  S5      n	UR                  SS5      n
UR                  S	5      nUR                  S
5      nUc
  [        5       n[        U[        5      nS nU(       d  UOS nU(       a  [        [        [           U5      n[        UUU	U
S9u  nn	n
[        UUU	U
S9  UR                  n[        R                  " S[        U[        R                   (       + S9S9  UR                  n[#        U5      n[%        UUS9nUR&                  nUR(                  nO[[        [*        [,        [.           -  U5      n[        UUU	U
S9  [1        U5      n[3        US 5        Un[        U[5        U5      UUUU	U
S9nUR6                  b  UR6                  OUb  UR8                  OS nUb  UUl        [;        XS9u  nnnnn[=        UUUUUUR>                  Ub  UR@                  OS US9nUb"  URC                  U=(       d
    [E        5       5        [G        UU[I        UUUS9US9nU(       a  URJ                  (       a  URJ                  OUnURM                  U5        [O        U5      nUb  [        U[        5      (       d  UOSn[Q        S,0 S[5        U5      _SU(       a  URR                  O/ _SU_SU(       a  URT                  O/ _SS _SS_SU(       a  URV                  OS_SU_SU(       a  [-        URX                  5      O/ _S U(       a  [-        URZ                  5      O/ _S!U(       a  [-        []        US"/ 5      5      O/ _S#U(       a  [-        []        US$/ 5      5      O/ _S%U_S&U_S'U_S(/ _S)U(       a  UR^                  OS_S*U(       a"  UR                  b  [5        UR                  5      O
[5        U5      _6nUb  [-        UR`                  5      O/ Ul1        Ub+  [-        UR`                  5      [-        URR                  5      :g  OSUl2        UUl        Ub  UR@                  Ul         UUl3        U	Ul4        U
Ul5        UUl6        Ub  URo                  5       Ul8        URr                  (       a  URu                  U5        [v        Rx                  " [{        UUUUUUUUU	U
UUUUUS+95      Ul>        URr                  (       a  UR                  5         U$ )-Nr   r   r   r   r   r   r   Frz   r{   r   r   z)Resuming from RunState in run_streaming())include_tool_output)extrar   r   r   r   r~   r   r   r   r   r   r  r   is_completer   r   r   r  r   r   r   r   _current_agent_output_schematracer   r   r?  r  )r]  streamed_resultr   r   r   r   r   r   r   r   rz   r{   r   r   r   rx   )@r  r   r   r   r#   rM   r   r  r\   r'   r7   r  r   r:  r*   r   DONT_LOG_TOOL_DATAr?   r0   r   r  r  r   r   r+   r
   r>   r   r   r1   ri   r#  r$  r%  re   r^   r   r.  r/  rE   r   r'  r"  r&  r,  _output_guardrail_resultsr-  r?  r!  rI  rJ  _conversation_id_previous_response_id_auto_previous_response_id_stateget_tool_use_tracker_snapshotr   r3  r   rP  rQ  rL   run_loop_task$ensure_sandbox_cleanup_on_completion) r[  r   r   r\  r   r   r   r   r   r   r   rz   r{   r   r   r]  raw_input_for_resultinput_for_resultr   input_for_stater   re  r   rf  rg  rh  	new_tracer   schema_agentr  streamed_inputr  s                                    ru   r   AgentRunner.run_streamed]  s    **Y'JJ{,=>	Xh');FJJw<O)PQZZ-
$45%zz*@A$*JJ/JE$R! **%67**Y'"J &eX6/3	&6DXh/7I
 4# /%9*C		$) 3 /%9*C	 '66NLL;6,2,E,E(E $-#<#< 67KL5#O &--G ",,I
  $C$/A*B$BEJ2 /%9*C	 5W=O&=.O '/@-# /%9*CI 22> //9B9N)55TX 	*
  2SI/ #YN	
 )-## 002;2G	..T#3	
	  	 @->-@A()!1% /
  	
 )2i6N6NI$$Tb 	 	..|<),7 )*^X2V2V  	
 - &
">2&
 3<i..	&

 '&
 9B)44r&
 &
 &
 5>001&
  &
 R[T)*L*L%M`b&
 >GY889B&
  R[WY(GLM`b!&
& S\WY(H"MNac'&
* *7+&
, -&
. ,/&
0 1&
: AJ	<<q;&
F !:!:!F !!:!:;%n5I&
P 1:0ED++,2 	*
 $ ++,Y5M5M0NN 	6
 5V1 +4+A+AO( ,;(0D-5N2!* 9B9`9`9bO6""11/B )0(;(;/ /-# /%-%9*C /#!1 /)
%& ""@@Brv   rx   N)r   r   r   r   r\  Unpack[RunOptions[TContext]]r   r   )r   r   r   r   r\  r  r   r   )	r   r   r   r   __doc__r   r   r   r   rx   rv   ru   rm   rm     s    
VA'VA CVA /	VA
 
VAp"QW'QW CQW /	QW
 
QWfe'e Ce /	e
 
erv   )rt   zAgentRunner | Noner   None)r   rm   )r   r   rz   r   r{   r   r   r   )r   zlist[TResponseInputItem] | Noner   z%str | list[TResponseInputItem] | Noner   str | list[TResponseInputItem]r   r  )
__future__r   rP  r  r  typingr   typing_extensionsr   r   r   _tool_identityr   agentr	   agent_tool_stater
   
exceptionsr   r   r   r   r   	guardrailr   r   r   r   r   	lifecycler   r   memoryr   r   r   r   r   r   r   r   r   r   r   r   r    r!   r   r"   r#   run_error_handlersr$   run_internal.agent_bindingsr%   !run_internal.agent_runner_helpersr&   r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r2   r3   r4   r5   r6   r7   run_internal.approvalsr8   run_internal.error_handlersr9   r:   r;   r<   r=   run_internal.itemsr>   r?   run_internal.oai_conversationr@   run_internal.prompt_cache_keyrA   run_internal.run_groupingrB   run_internal.run_looprC   rD   rE   rF   rG   rH   rI   rJ   rK   rL   rM   run_internal.run_stepsrN   rO   rP   rQ    run_internal.session_persistencerR   rS   rT   rU   rV   rW   rX   run_internal.tool_use_trackerrY   rZ   r[   r   r\   sandbox.memory.rolloutsr]   sandbox.runtimer^   r  r_   tool_guardrailsr`   ra   r   rb   rc   rd   re   rf   rg   tracing.contextrh   ri   tracing.span_datarj   rk   utilrl   rn   __annotations____all__rp   rq   r   r   ro   rm   rx   rv   ru   <module>r     s   "     $  8  8  
     1
 
 
 5 0 :    ( 8  K A >       
   D + , P Y Y B :  $( k (&3    	
 
,(G
, ?
, 3	
,
 $
,h
 h
VV Vr, #} rv   