
    .hT                       d dl mZ d dlZd dlZd dlmZmZ d dlmZm	Z	 d dl
mZ ddlmZmZmZmZmZmZmZmZmZ ddlmZ dd	lmZmZ dd
lmZmZmZmZm Z  ddl!m"Z"m#Z#m$Z$m%Z% ddl&m'Z'm(Z(m)Z) ddl*m+Z+m,Z,m-Z-m.Z. ddl/m0Z0 ddl1m1Z1 ddl2m3Z3 ddl4m5Z5m6Z6 ddl7m8Z8 ddl9m:Z:m;Z; ddl<m=Z=m>Z> ddl?m@Z@mAZA ddlBmCZC ddlDmEZEmFZFmGZGmHZHmIZI ddlJmKZK ddlLmMZM ddlNmOZOmPZP dZQe G d d                      ZR G d d          ZSdS )     )annotationsN)	dataclassfield)Anycast)ResponseCompletedEvent   )	AgentToolUseTrackerNextStepFinalOutputNextStepHandoffNextStepRunAgainQueueCompleteSentinelRunImplSingleStepResultTraceCtxManagerget_model_tracing_impl)Agent)AgentOutputSchemaAgentOutputSchemaBase)AgentsExceptionInputGuardrailTripwireTriggeredMaxTurnsExceededModelBehaviorError OutputGuardrailTripwireTriggered)InputGuardrailInputGuardrailResultOutputGuardrailOutputGuardrailResult)HandoffHandoffInputFilterhandoff)ItemHelpersModelResponseRunItemTResponseInputItem)RunHooks)logger)ModelSettings)ModelModelProvider)MultiProvider)	RunResultRunResultStreaming)RunContextWrapperTContext)AgentUpdatedStreamEventRawResponsesStreamEvent)Tool)Span	SpanError
agent_spanget_current_tracetrace)AgentSpanData)Usage)_coro_error_tracing
   c                      e Zd ZU dZdZded<   	  ee          Zded<   	 dZ	ded	<   	 dZ
d
ed<   	 dZded<   	 dZded<   	 dZded<   	 dZded<   	 dZded<   	 dZded<   	 dZded<   	 dZded<   dS )	RunConfigz-Configures settings for the entire agent run.Nzstr | Model | Nonemodel)default_factoryr*   model_providerzModelSettings | Nonemodel_settingszHandoffInputFilter | Nonehandoff_input_filterz list[InputGuardrail[Any]] | Noneinput_guardrailsz!list[OutputGuardrail[Any]] | Noneoutput_guardrailsFbooltracing_disabledTtrace_include_sensitive_datazAgent workflowstrworkflow_name
str | Nonetrace_idgroup_idzdict[str, Any] | Nonetrace_metadata)__name__
__module____qualname____doc__r?   __annotations__r   r+   rA   rB   rC   rD   rE   rG   rH   rJ   rL   rM   rN        G/var/www/FlaskApp/flask-venv/lib/python3.11/site-packages/agents/run.pyr>   r>   2   s7        77 $E$$$$ %*E-$H$H$HNHHHH[+/N//// 7;::::
 :>====E;?????L""""" *. ----
 *M))))  HaH
 -1N0000 rU   r>   c                     e Zd ZededddddHd            ZededddddHd            ZededddfdId            ZedJd            ZedKd$            Z	edLd,            Z
edMd0            ZedNd8            ZedOd:            ZedPd?            ZedQdB            ZedRdC            ZedSdD            ZedTdE            ZedUdG            ZdS )VRunnerNcontext	max_turnshooks
run_configprevious_response_idstarting_agentAgent[TContext]inputstr | list[TResponseInputItem]rZ   TContext | Noner[   intr\   RunHooks[TContext] | Noner]   RunConfig | Noner^   rK   returnr,   c                 K   |t          t                               }|t                      }t                      }t	          |j        |j        |j        |j        |j	                  5  d}	t          j        |          }
g }g }t          |          }g }d}|}d}	 	 |d |                     |          D             }|                     |          x}r|                                }nd}t!          |j        ||          }|                    d	           |                     |           d{V }d
 |D             |j        _        |	dz  }	|	|k    r9t+          j        |t/          dd|i                     t1          d| d          t3          j        d|j         d|	 d           |	dk    rst7          j        |                     ||j        |j        pg z   t          j        |          |          |                     |||
|||||||
  
                   d{V \  }}n%|                     |||
|||||||
  
         d{V }d}|                     |j!                   |j"        }
|j#        }tI          |j%        tL                    r|| '                    |j(        |j(        pg z   ||j%        j)        |           d{V }tU          |
|||j%        j)        ||||          |r|+                    d           cddd           S tI          |j%        tX                    rEt[          t\          t^                   |j%        j0                  }|+                    d           d}d}n?tI          |j%        tb                    rn$te          dtg          |j%                             # |r|+                    d           w w xY w# 1 swxY w Y   dS )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.
        2. If a guardrail tripwire is triggered, a GuardrailTripwireTriggered exception is raised.

        Note that 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.
            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.

        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.
        NrJ   rL   rM   metadatadisabledr   rZ   Tc                    g | ]	}|j         
S rT   
agent_name.0hs     rV   
<listcomp>zRunner.run.<locals>.<listcomp>   s    (`(`(`!(`(`(`rU   rI   namehandoffsoutput_typemark_as_currentc                    g | ]	}|j         
S rT   ru   rq   ts     rV   rs   zRunner.run.<locals>.<listcomp>   s    7R7R7R17R7R7RrU   r	   Max turns exceededr[   messagedatazMax turns (z
) exceededzRunning agent z (turn ))
agent	all_toolsoriginal_inputgenerated_itemsr\   context_wrapperr]   should_run_agent_start_hookstool_use_trackerr^   F)ra   	new_itemsraw_responsesfinal_output_last_agentinput_guardrail_resultsoutput_guardrail_resultsr   reset_currentzUnknown next step type: )4r&   r   r>   r
   r   rJ   rL   rM   rN   rG   copydeepcopyr.   _get_handoffs_get_output_schemaru   r5   start_get_all_tools	span_datatoolsr;   attach_error_to_spanr4   r   r'   debugasynciogather_run_input_guardrailsrD   _run_single_turnappendmodel_responser   r   
isinstance	next_stepr   _run_output_guardrailsrE   outputr,   finishr   r   r   r/   	new_agentr   r   type)clsr_   ra   rZ   r[   r\   r]   r^   r   current_turnr   r   model_responsesr   r   current_spancurrent_agentr   handoff_namesoutput_schemaoutput_type_namer   turn_resultr   s                           rV   runz
Runner.runn   s     T =SMOOE"J.00$2((.0
 
 
 A	< A	< L=A]5=Q=QN-/O35O;L< < <O CE#7;L*M+/(k<g $+(`(`s?P?PQ^?_?_(`(`(`,/,B,B=,Q,QQ= 5/</A/A/C/C,,/4,'1!.!3%2(8( ( (
 %**4*@@@*-*<*<]*K*K$K$K$K$K$K$K	7R7R	7R7R7R.4 A%L#i//&;(%(<&19%=     //RY/R/R/RSSSLS);SSLSSS   $q((EL^55 . . ?#-#>#D"!F $e 4 4 /   00&3*3/=0?&+0?+5=Y1A5I 1  F F @ @ @ @ @ @</, -0,@,@"/&/+9,;"',;'19U-=1E -A - - ' ' ' ' ' ' 490#**;+EFFF%0%?N&1&AO!+"79LMM 9<9S9S);z?[?a_ab)'18+	: : 4 4 4 4 4 40  )"0&5*9)4)>)E(54K5M,;	  	  	 ,   < ''d';;;CA	< A	< A	< A	< A	< A	< A	< A	<h $K$9?KK 
(,U8_k>S>](^(^$++$+???'+7;44#K$9;KLL -TtK<Q7R7RTT  KgR   < ''d';;;;<AA	< A	< A	< A	< A	< A	< A	< A	< A	< A	<s2   )3OIN-(OB N--OOOOc                   t          j                                        |                     |||||||                    S )a  Run a workflow synchronously, starting at the given agent. Note that 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 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.
        2. If a guardrail tripwire is triggered, a GuardrailTripwireTriggered exception is raised.

        Note that 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.
            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.

        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.
        rY   )r   get_event_looprun_until_completer   )r   r_   ra   rZ   r[   r\   r]   r^   s           rV   run_synczRunner.run_sync"  sQ    \ %''::GG#%%9   

 

 
	
rU   r-   c                   |t          t                               }|t                      }t                      rdn,t	          |j        |j        |j        |j        |j	                  }| 
                    |          }	t          |          }
t          t          j        |          g |g ddd|g g |	||
          }t          j        |                     ||||||
||                    |_        |S )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.
        2. If a guardrail tripwire is triggered, a GuardrailTripwireTriggered exception is raised.

        Note that 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.
            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.
        Returns:
            A result object that contains data about the run, as well as a method to stream events.
        Nri   rl   Fr   )ra   r   r   r   r   is_completer   r[   r   r   _current_agent_output_schemar7   r   )starting_inputstreamed_resultr_   r[   r\   r   r]   r^   )r&   r   r>   r6   r7   rJ   rL   rM   rN   rG   r   r.   r-   r   r   r   create_task_run_streamed_impl_run_impl_task)r   r_   ra   rZ   r[   r\   r]   r^   	new_tracer   r   r   s               rV   run_streamedzRunner.run_streamed\  s1   R =SMOOE"J !""DD(6#,#,#2#4   	 ..~>>7H8
 8
 8
 --&&($&%')6+
 
 
" *1)<""$ /-# /%%9 # 	 	*
 *
& rU   r   
Agent[Any]
guardrailslist[InputGuardrail[TContext]]RunContextWrapper[TContext]r   parent_span	Span[Any]c           
       K   |j         }fd|D             }g }		 t          j        |          D ]~}
|
 d {V }|j        j        r>t          j        |t          d|j        	                                dd                     |
                    |           |	                    |           n(# t          $ r |D ]}|                                  w xY w|	|_        d S )Nc           
     b    g | ]+}t          j        t          j        |                    ,S rT   r   r   r   run_single_input_guardrailrq   	guardrailr   rZ   ra   s     rV   rs   z;Runner._run_input_guardrails_with_queue.<locals>.<listcomp>  L     
 
 
  25)UGTT 
 
 
rU   Guardrail tripwire triggeredinput_guardrail)r   r   r   )_input_guardrail_queuer   as_completedr   tripwire_triggeredr;   r   r4   r   get_name
put_nowaitr   	Exceptioncancelr   )r   r   r   ra   rZ   r   r   queueguardrail_tasksguardrail_resultsdoneresultr}   s    ` ``        rV    _run_input_guardrails_with_queuez'Runner._run_input_guardrails_with_queue  sY       6
 
 
 
 
 
 (	
 
 
 	,_== 1 1#=3 
"7#!$B-3-=-F-F-H-H(9" "  	 	 	   (((!((00001  	 	 	$  



	
 3D///s   BB4 4%Cr   RunHooks[TContext]r   r>   c	                	  K   |j         r|j                             d           d }	|}
d}d}t                      }|j                            t          |
                     	 	 |j        rn|	d |                     |
          D             }|                     |
          x}r|	                                }nd}t          |
j	        ||          }	|	                    d           |                     |
           d {V }d |D             }||	j        _        |d	z  }||_        ||k    rNt          j        |	t#          d
d|i                     |j                            t%                                 n|d	k    rdt'          j        |                     ||j        |j        pg z   t/          j        t3          j        |                    |||	                    |_        	 |                     ||
|||||||	  	         d {V }d}|j        |j        gz   |_        |j        |_         |j!        |_"        tG          |j$        tJ                    rO|j$        j&        }
|	'                    d           d }	d}|j                            t          |
                     ntG          |j$        tP                    rt'          j        | )                    |
j*        |j*        pg z   |
|j$        j+        |                    |_,        	 |j,         d {V }n# tZ          $ r g }Y nw xY w||_.        |j$        j+        |_/        d|_        |j                            t%                                 ntG          |j$        t`                    r	 nu# tZ          $ rh}|	r3t          j        |	t#          ddtc          |          i                     d|_        |j                            t%                                  d }~ww xY wd|_        |	r|	'                    d           |j         r|j         '                    d           d S d S # |	r|	'                    d           |j         r|j         '                    d           w w xY w)NTrx   r   )r   c                    g | ]	}|j         
S rT   rn   rp   s     rV   rs   z-Runner._run_streamed_impl.<locals>.<listcomp>  s    $\$\$\aQ\$\$\$\rU   rI   rt   c                    g | ]	}|j         
S rT   r{   r|   s     rV   rs   z-Runner._run_streamed_impl.<locals>.<listcomp>  s    !<!<!<Q!&!<!<!<rU   r	   r~   r[   r   Fr   zError in agent runerror)2r7   r   r
   _event_queuer   r0   r   r   r   ru   r5   r   r   r   r   r;   r   r4   r   r   r   r   rD   r   r   r"   input_to_new_input_list_input_guardrails_task_run_single_turn_streamedr   r   r   ra   r   r   r   r   r   r   r   r   r   rE   r   _output_guardrails_taskr   r   r   r   rI   )r   r   r   r_   r[   r\   r   r]   r^   r   r   r   r   r   r   r   r   r   
tool_namesr   r   es                         rV   r   zRunner._run_streamed_impl  s        	>!'''===37&'+$.00$//0GR_0`0`0`aaaw	Ao".   '$\$\3;L;L];[;[$\$\$\M(+(>(>}(M(MM} 1+8+=+=+?+?((+0(#-*/!.$4$ $ $L
 !&&t&<<<&)&8&8&G&G G G G G G GI!<!<)!<!<!<J3=L*0!/;,)++"7$!$8"-y!9     $0;;<Q<S<STTT1$$=D=P<<**;z?Z?`^`a M+*Mn*]*]^^++( 	> 	>O:>(+(E(E'%'"4(!,
) 
) 
# 
# 
# 
# 
# 
#K 4904C4Q#2U 5O1 -8,FO)0;0KO-!+"7II (3(=(G$++$+???'+7;4'4??3mLLL    $K$9;NOO BIBU66 - ?#-#?#E2!G - + 5 < / C C?:=L=d7d7d7d7d7d7d44( : : :79444: D\@7B7L7S46:3'4??@U@W@WXXXX#K$9;KLL     # &;(%(<&-s1vv%6     37O/#0;;<Q<S<STTTIob +/O' 8##$#777$ A%,,4,@@@@@A A  8##$#777$ A%,,4,@@@@AsX   $FQ (DN L N L# N "L##A$N Q 
O:A#O55O::Q =Rr   rF   r   r
   r   
list[Tool]r   c
                l  K   |rbt          j        |                    ||          |j        r|j                            ||          nt          j                               d {V  |                     |          }
||_        |
|_	        |
                    |           d {V }|                     |          }|                     ||          }|j                            |j                  }t          j        |||          }d }t#          j        |j                  }|                    d |j        D                        |                    |||||
|t/          |j        |j                  |	          2 3 d {V }t5          |t6                    r|j        j        r@t=          d|j        j        j        |j        j        j         |j        j        j!                  nt=                      }tE          |j        j#        ||j        j$                  }|j        %                    |           |j&        '                    tQ          |                     6 |stS          d          | *                    ||j        |j        ||
||||||           d {V }t          j+        ||j&                   |S )	Nc                6    g | ]}|                                 S rT   to_input_item)rq   items     rV   rs   z4Runner._run_single_turn_streamed.<locals>.<listcomp>  s$    QQQtd((**QQQrU   )r^   r	   )requestsinput_tokensoutput_tokenstotal_tokens)r   usageresponse_id)r   z'Model did not produce a final response!r   r   pre_step_itemsnew_responser   r   rv   r\   r   r]   r   ),r   r   on_agent_startr\   on_startr:   noop_coroutiner   r   r   get_system_promptr   
_get_modelrB   resolver   maybe_reset_tool_choicer"   r   ra   extendr   stream_responser   rG   rH   r   r   responser   r9   r   r   r   r#   r   idaddr   r   r1   r   %_get_single_step_result_from_responsestream_step_result_to_queue)r   r   r   r\   r   r]   r   r   r   r^   r   system_promptrv   r?   rB   final_responsera   eventr   single_step_results                       rV   r   z Runner._run_single_turn_streamedx  sK      ( 	.$$_e<< {0EK((%@@@-//         ..u55(-%7D4#55oFFFFFFFF$$U++uj11-55j6OPP 8@PR`aa/33O4IJJQQ7PQQQRRR !00"+Z-T  "6 1 
 
 	Y 	Y 	Y 	Y 	Y 	Y 	Y% %!788 1 ~+!E!"%*^%9%F&+n&:&H%*^%9%F	      "/ >0 % 1" " "
  %))%000(334KQV4W4W4WXXXX=
B  	P$%NOOO $'#L#L*0*4''+!- $M $
 $
 
 
 
 
 
 
 	+,>@\]]]!!s   9Ir   r   list[RunItem]c       
        R  K   |rbt          j        |                    ||          |j        r|j                            ||          nt          j                               d {V  |                    |           d {V }|                     |          }| 	                    |          }t          j        |          }|                    d |D                        |                     |||||||||	|

  
         d {V }|                     |||||||||||	           d {V S )Nc                6    g | ]}|                                 S rT   r   )rq   generated_items     rV   rs   z+Runner._run_single_turn.<locals>.<listcomp>  s$    [[[n2244[[[rU   r   )r   r   r   r\   r   r:   r   r   r   r   r"   r   r   _get_new_responser  )r   r   r   r   r   r\   r   r]   r   r   r^   r  r   rv   ra   r   s                   rV   r   zRunner._run_single_turn  s       ( 	.$$_e<< {0EK((%@@@-//         $55oFFFFFFFF..u55$$U++3NCC[[?[[[\\\ 22 
 
 
 
 
 
 
 
 >>)*%'+!- ? 
 
 
 
 
 
 
 
 	
rU   r   r   r#   r   AgentOutputSchemaBase | Nonerv   list[Handoff]c                  K   t          j        |||||          }|                    ||j                   t          j        ||||||||	|
	  	         d {V S )N)r   r   r  r   rv   )	r   r   r   r   processed_responser   r\   r   r]   )r   process_model_responseadd_tool_use
tools_usedexecute_tools_and_side_effects)r   r   r   r   r   r   r   rv   r\   r   r]   r   r  s                rV   r  z,Runner._get_single_step_result_from_response  s        %;!'
 
 
 	%%e-?-JKKK;))%1'+!

 

 

 

 

 

 

 

 

 
	
rU   list[InputGuardrailResult]c           	       K   |sg S fd|D             }g }t          j        |          D ]}| d {V }|j        j        rd|D ]}	|	                                 t          j        t          dd|j        	                                i                     t          |          |                    |           |S )Nc           
     b    g | ]+}t          j        t          j        |                    ,S rT   r   r   s     rV   rs   z0Runner._run_input_guardrails.<locals>.<listcomp>D  r   rU   r   r   r   )r   r   r   r   r   r;   attach_error_to_current_spanr4   r   r   r   r   )
r   r   r   ra   rZ   r   r   r   r   r}   s
    ` ``     rV   r   zRunner._run_input_guardrails9  s       	I
 
 
 
 
 
 (	
 
 
 (99 	1 	1DZZZZZZF}/ 1(  AHHJJJJ; >)6+;+D+D+F+FG     6f===!((0000  rU   list[OutputGuardrail[TContext]]agent_outputr   list[OutputGuardrailResult]c           	       K   |sg S fd|D             }g }t          j        |          D ]}| d {V }|j        j        rd|D ]}	|	                                 t          j        t          dd|j        	                                i                     t          |          |                    |           |S )Nc           
     b    g | ]+}t          j        t          j        |                    ,S rT   )r   r   r   run_single_output_guardrail)rq   r   r   r  rZ   s     rV   rs   z1Runner._run_output_guardrails.<locals>.<listcomp>j  sM     
 
 
  3IulT[\\ 
 
 
rU   r   r   r   )r   r   r   r   r   r;   r  r4   r   r   r   r   )
r   r   r   r  rZ   r   r   r   r   r}   s
     ```     rV   r   zRunner._run_output_guardrails_  s       	I
 
 
 
 
 
 (	
 
 
 (99 	1 	1DZZZZZZF}/ 1(  AHHJJJJ; >)6+;+D+D+F+FG     7v>>>!((0000  rU   r  list[TResponseInputItem]c                T  K   |                      ||          }|j                            |j                  }t          j        ||	|          }|                    ||||||t          |j        |j                  |
           d {V }|j	        
                    |j	                   |S )N)system_instructionsra   rB   r   r   rv   tracingr^   )r   rB   r   r   r   get_responser   rG   rH   r   r  )r   r   r  ra   r   r   rv   r   r]   r   r^   r?   rB   r   s                 rV   r  zRunner._get_new_response  s       uj11-55j6OPP 8@PR`aa"// -)'*+Z-T  "6 0 
 
 
 
 
 
 
 
 	!!,"4555rU   c                    |j         |j         t          u rd S t          |j         t                    r|j         S t	          |j                   S N)rw   rI   r   r   r   r   r   s     rV   r   zRunner._get_output_schema  sM    $(9S(@(@4)+@AA 	%$$ !2333rU   c                    g }|j         D ]d}t          |t                    r|                    |           -t          |t                    r"|                    t          |                     e|S r'  )rv   r   r   r   r   r!   )r   r   rv   handoff_items       rV   r   zRunner._get_handoffs  sq    !N 	7 	7L,00 7----L%00 7 5 5666rU   c                :   K   |                                  d {V S r'  )get_all_toolsr(  s     rV   r   zRunner._get_all_tools  s*      ((*********rU   r)   c                6   t          |j        t                    r|j        S t          |j        t                    r|j                            |j                  S t          |j        t                    r|j        S |j                            |j                  S r'  )r   r?   r)   rI   rA   	get_model)r   r   r]   s      rV   r   zRunner._get_model  s    j&.. 	##
(#.. 	,66z7GHHHU++ 	;(225;???rU   )r_   r`   ra   rb   rZ   rc   r[   rd   r\   re   r]   rf   r^   rK   rg   r,   )r_   r`   ra   rb   rZ   rc   r[   rd   r\   re   r]   rf   r^   rK   rg   r-   )r   r   r   r   ra   rb   rZ   r   r   r-   r   r   )r   rb   r   r-   r_   r`   r[   rd   r\   r   r   r   r]   r>   r^   rK   )r   r-   r   r`   r\   r   r   r   r]   r>   r   rF   r   r
   r   r   r^   rK   rg   r   )r   r`   r   r   r   rb   r   r
  r\   r   r   r   r]   r>   r   rF   r   r
   r^   rK   rg   r   )r   r`   r   r   r   rb   r   r
  r   r#   r   r  rv   r  r\   r   r   r   r]   r>   r   r
   rg   r   )
r   r   r   r   ra   rb   rZ   r   rg   r  )
r   r  r   r`   r  r   rZ   r   rg   r  )r   r`   r  rK   ra   r!  r   r  r   r   rv   r  r   r   r]   r>   r   r
   r^   rK   rg   r#   )r   r   rg   r  )r   r   rg   r  )r   r   rg   r   )r   r   r]   r>   rg   r)   )rO   rP   rQ   classmethodDEFAULT_MAX_TURNSr   r   r   r   r   r   r   r  r   r   r  r   r   r   r   rT   rU   rV   rX   rX   m   sj        $(*+/'++/q< q< q< q< q< [q<f  $(*+/'++/7
 7
 7
 7
 7
 [7
r 
 $(*+/'++/^ ^ ^ ^ [^@ (D (D (D [(DT MA MA MA [MA^ \" \" \" [\"| 9
 9
 9
 [9
v #
 #
 #
 [#
J #! #! #! [#!J #! #! #! [#!J       [ D 4 4 4 [4    [ + + + [+ @ @ @ [@ @ @rU   rX   )T
__future__r   r   r   dataclassesr   r   typingr   r   openai.types.responsesr   	_run_implr
   r   r   r   r   r   r   r   r   r   r   r  r   r   
exceptionsr   r   r   r   r   r   r   r   r   r   rv   r   r    r!   itemsr"   r#   r$   r%   	lifecycler&   r'   rB   r(   models.interfacer)   r*   models.multi_providerr+   r   r,   r-   run_contextr.   r/   stream_eventsr0   r1   toolr2   r$  r3   r4   r5   r6   r7   tracing.span_datar8   r   r9   utilr:   r;   r0  r>   rX   rT   rU   rV   <module>r@     sU   " " " " " "   ( ( ( ( ( ( ( (         9 9 9 9 9 9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
       B B B B B B B B              d c c c c c c c c c c c : : : : : : : : : : J J J J J J J J J J J J             ) ) ) ) ) ) 2 2 2 2 2 2 2 2 0 0 0 0 0 0 1 1 1 1 1 1 1 1 4 4 4 4 4 4 4 4 K K K K K K K K       J J J J J J J J J J J J J J , , , , , ,       ' ' ' ' ' ' ' '  7 7 7 7 7 7 7 7t[@ [@ [@ [@ [@ [@ [@ [@ [@ [@rU   