+
    ~j                    @   ^ RI Ht ^ RIt^ RIt^ RIt^ RIt^ RIt^ RIt^ RIH	t	H
t
 ^ RIHt ^ RIHt ^ RIHtHtHtHtHtHt ^ RIHt ^RIHt ^R	IHtHt ^R
IHtHt ^RIH t H!t! ^RIH"t" ^RI#H$t$ ]'       d   ^RI%H&t& ]'! ]PP                  ! R^ 4      4      t)]! R4      t*] ! R R4      4       t+] ! R R4      4       t,] ! R R4      4       t-] ! R R4      4       t.]+],,          ]-,          ].,          t/ ! R R]]*,          4      t0 ! R R4      t1 ! R R4      t2 ! R R 4      t3 ! R! R"4      t4 ! R# R$4      t5 ! R% R&4      t6 ! R' R(4      t7]'       d   ]8]9]&,          ]8]:]	3,          3,          t;]Px                  R),          ! R*4      t=]R+ R, l4       t>R-R/R. R/ llt?R# )0    )annotationsN)Callable	Generator)contextmanager)	dataclass)TYPE_CHECKINGAnyGenericLiteralTypeVaroverload)trace)llm)function_toolutils)trace_typestracer)	NOT_GIVEN
NotGivenOr)is_given)SpeechHandle)AgentLIVEKIT_EVALS_VERBOSERun_Tc                  0    ] tR t^'t$ R]R&   RtR]R&   RtR# )ChatMessageEventzllm.ChatMessageitemmessageLiteral['message']type N__name__
__module____qualname____firstlineno____annotations__r    __static_attributes__r!       t/Users/mitch_tango/dev/rabbit-r1-livekit/agent/.venv/lib/python3.14/site-packages/livekit/agents/voice/run_result.pyr   r   '   s    
(D
(r)   r   c                  0    ] tR t^-t$ R]R&   RtR]R&   RtR# )FunctionCallEventzllm.FunctionCallr   function_callLiteral['function_call']r    r!   Nr"   r!   r)   r*   r,   r,   -   s    
%4D
"4r)   r,   c                  0    ] tR t^3t$ R]R&   RtR]R&   RtR# )FunctionCallOutputEventzllm.FunctionCallOutputr   function_call_outputLiteral['function_call_output']r    r!   Nr"   r!   r)   r*   r0   r0   3   s    
  ,BD
)Br)   r0   c                  D    ] tR t^9t$ R]R&   R]R&   R]R&   RtR]R	&   R
tR# )AgentHandoffEventllm.AgentHandoffr   Agent | None	old_agentr   	new_agentagent_handoffLiteral['agent_handoff']r    r!   Nr"   r!   r)   r*   r4   r4   9   s    
%4D
"4r)   r4   c                      ] tR t^DtRR/R R llt]R R l4       t]P                  R R l4       t	]R	 R
 l4       t
R R ltR R ltR R ltR R ltR R ltR R ltR R ltR R ltR R ltRtR# )	RunResult
user_inputNc               $    V ^8  d   QhRRRRRR/# )   r=   z
str | Noneoutput_typeztype[Run_T] | NonereturnNoner!   )formats   "r*   __annotate__RunResult.__annotate__E   s#     	> 	>j 	>FX 	>]a 	>r)   c               	    \        4       V n        \        P                  R ,          ! 4       V n        Wn        W n        . V n        R V n        R V n	        R # N)
set_handlesasyncioFuture	_done_fut_user_input_output_type_recorded_items_final_output_RunResult__last_speech_handle)selfr=   r@   s   &$$r*   __init__RunResult.__init__E   sB    :=% -/%'/1+/9=!r)   c                   V ^8  d   QhRR/# )r?   rA   list[RunEvent]r!   )rC   s   "r*   rD   rE   Q   s     $ $ $r)   c                    V P                   # )ar  
List of recorded run events in chronological order.

This surface is intended for assertions in tests. Events may include
`ChatMessageEvent`, `FunctionCallEvent`,
`FunctionCallOutputEvent`, and `AgentHandoffEvent`.

Use `RunResult.events` when validating what happened in a run instead
of depending on lower-level session internals, room state, or raw media
artifacts.
)rO   rR   s   &r*   eventsRunResult.eventsP   s     ###r)   c                   V ^8  d   QhRR/# )r?   rA   	RunAssertr!   )rC   s   "r*   rD   rE   `   s      	 r)   c                    \         '       dA   RP                  \        V P                  4      4      p\	        RV P
                   RV R24       \        V 4      # )zy
Provides an assertion helper for verifying the run events.

Returns:
    RunAssert: Assertion interface for run events.
z
    z
+ RunResult(
   user_input=`z`
   events:
    z
))lk_evals_verbosejoin_format_eventsrY   printrM   r\   )rR   
events_strs   & r*   expectRunResult.expect_   sZ     !~dkk'BCJ""&"2"2!3 4##-, / r)   c                   V ^8  d   QhRR/# )r?   rA   r   r!   )rC   s   "r*   rD   rE   t   s     " "e "r)   c                    V P                   P                  4       '       g   \        R4      hV P                  '       g   \        R4      hV P                  # )z
Returns the final output of the run after completion.

Raises:
    RuntimeError: If the run is not complete or no output is set.

Returns:
    Run_T: The final result output.
z3cannot retrieve final_output, RunResult is not donezno final output)rL   doneRuntimeErrorrP   rX   s   &r*   final_outputRunResult.final_outputs   sG     ~~""$$TUU!!!011!!!r)   c                   V ^8  d   QhRR/# )r?   rA   boolr!   )rC   s   "r*   rD   rE      s     % %d %r)   c                6    V P                   P                  4       # )z=Indicates whether the run has finished processing all events.)rL   rg   rX   s   &r*   rg   RunResult.done   s    ~~""$$r)   c                   V ^8  d   QhRR/# )r?   rA   z'Generator[None, None, RunResult[Run_T]]r!   )rC   s   "r*   rD   rE      s     ) )B )r)   c                	@   a  R  V 3R llpV! 4       P                  4       # )c                   V ^8  d   QhRR/# )r?   rA   zRunResult[Run_T]r!   )rC   s   "r*   rD   )RunResult.__await__.<locals>.__annotate__   s     	 	#3 	r)   c                 d   <"   \         P                  ! S P                  4      G R j  xL
  S #  L5irG   )rJ   shieldrL   rX   s   r*   _await_impl(RunResult.__await__.<locals>._await_impl   s&     ..000K 1s   $0.0)	__await__)rR   ru   s   f r*   rw   RunResult.__await__   s     	 	 }&&((r)   c               (    V ^8  d   QhRRRRRRRR/# )	r?   r   r5   r7   r6   r8   r   rA   rB   r!   )rC   s   "r*   rD   rE      s,     2 2'24@2MR2	2r)   c               	    V P                   P                  4       '       d   R # \        WVR7      pV P                  VP                  P
                  R7      pV P                  P                  WT4       R # )N)r   r7   r8   
created_at)rL   rg   r4   _find_insertion_indexr   r|   rO   insert)rR   r   r7   r8   eventindexs   &$$$  r*   _agent_handoffRunResult._agent_handoff   sW     >>  !tIV**ejj6K6K*L##E1r)   c                    V ^8  d   QhRRRR/# )r?   r   zllm.ChatItemrA   rB   r!   )rC   s   "r*   rD   rE      s     6 6 6 6r)   c                	   V P                   P                  4       '       d   R # R pVP                  R8X  d   \        VR7      pM;VP                  R8X  d   \	        VR7      pMVP                  R8X  d   \        VR7      pVeD   V P                  VP                  P                  R7      pV P                  P                  W24       R # R # )Nr   )r   r-   r1   r{   )rL   rg   r    r   r,   r0   r}   r   r|   rO   r~   )rR   r   r   r   s   &&  r*   _item_addedRunResult._item_added   s    >>  !%99	!$$/EYY/)%40EYY00+6E..%**:O:O.PE  ''5 r)   c                    V ^8  d   QhRRRR/# )r?   handleSpeechHandle | asyncio.TaskrA   rB   r!   )rC   s   "r*   rD   rE      s     	< 	<$? 	<D 	<r)   c                	   V P                   P                  4       '       d   R # V P                  P                  V4       \	        V\
        4      '       d   VP                  V P                  4       VP                  V P                  4       R # rG   )
rL   rg   rI   add
isinstancer   _add_item_added_callbackr   add_done_callback_mark_done_if_neededrR   r   s   &&r*   _watch_handleRunResult._watch_handle   s_    >>  &!fl++++D,<,<=  !:!:;r)   c                    V ^8  d   QhRRRR/# )r?   r   r   rA   rl   r!   )rC   s   "r*   rD   rE      s     	 	&A 	d 	r)   c                	    WP                   9  d   R # V P                   P                  V4       VP                  V P                  4       \	        V\
        4      '       d   VP                  V P                  4       R# )FT)rI   discardremove_done_callbackr   r   r   _remove_item_added_callbackr   r   s   &&r*   _unwatch_handleRunResult._unwatch_handle   sY    &f%##D$=$=>fl++..t/?/?@r)   c                    V ^8  d   QhRRRR/# )r?   r   z"SpeechHandle | asyncio.Task | NonerA   rB   r!   )rC   s   "r*   rD   rE      s      +M RV r)   c                	    \        V\        4      '       d   Wn        \        ;QJ d&    R  V P                   4       F  '       d   K   RM	  RM! R  V P                   4       4      '       d   V P                  4        R# R# )c              3  @   "   T F  qP                  4       x  K  	  R # 5irG   )rg   ).0r   s   & r*   	<genexpr>1RunResult._mark_done_if_needed.<locals>.<genexpr>   s     9={{}}=s   FTN)r   r   rQ   allrI   
_mark_doner   s   &&r*   r   RunResult._mark_done_if_needed   sM    fl++(.%394==933394==999OO :r)   c                   V ^8  d   QhRR/# r?   rA   rB   r!   )rC   s   "r*   rD   rE      s     ; ;D ;r)   c                	   \         P                  ! \        P                  4      ;_uu_ 4        V P                  f'   V P
                  P                  R 4        R R R 4       R # V P                  P                  p\        V\        4      '       g   V P                  '       dn   \        WP                  4      '       gS   V P
                  P                  \        RV P                  P                   R\        V4      P                   24      4       M=Wn        V P
                  P                  R 4       MV P
                  P                  V4       R R R 4       R #   + '       g   i     R # ; i)NzExpected output of type , got )
contextlibsuppressrJ   InvalidStateErrorrQ   rL   
set_result_maybe_run_final_outputr   BaseExceptionrN   set_exceptionrh   r#   r    rP   )rR   ri   s   & r*   r   RunResult._mark_done   s     !:!:;;((0))$/ <;
  44LLLlM::$$$ZFWFW-X-XNN00$6t7H7H7Q7Q6R S##'#5#>#>"?A *6&NN--d3,,\:% <;;;s   +E"=E B*EE%	c                    V ^8  d   QhRRRR/# )r?   r|   floatrA   intr!   )rC   s   "r*   rD   rE      s      5 S r)   c                   \        \        \        V P                  4      4      4       F:  pV P                  V,          P                  P
                  V8:  g   K1  V^,           u # 	  ^ # )z
Returns the index to insert an item by creation time.

Iterates in reverse, assuming items are sorted by `created_at`.
Finds the position after the last item with `created_at <=` the given timestamp.
)reversedrangelenrO   r   r|   )rR   r|   is   &$ r*   r}   RunResult._find_insertion_index   sP     %D$8$8 9:;A##A&++66*D1u < r)   )__last_speech_handlerL   rP   rI   rN   rO   rM   )r#   r$   r%   r&   rS   propertyrY   	functoolscached_propertyrc   ri   rg   rw   r   r   r   r   r   r   r}   r(   r!   r)   r*   r<   r<   D   s    	>4 	> $ $  & " "$%)26 	<	;* r)   r<   c                     ] tR t^tR R lt]R R l4       t]R R l4       tR R ltR	 R
 ltR8R R llt]RR/R R ll4       t	]R R l4       t	]R R l4       t	]R R l4       t	]R R l4       t	RR/R R llt	]R]
/R R ll4       t]R]
R]
/R  R! ll4       t]R"]
R#]
/R$ R% ll4       t]R&]
/R' R( ll4       tR]
R]
R]
R"]
R#]
R&]
/R) R* lltR9R+ R, lltR- R. ltR]
R]
/R/ R0 lltR]
/R1 R2 lltR"]
R#]
/R3 R4 lltR&]
/R5 R6 lltR7tR# ):r\   c                   V ^8  d   QhRR/# )r?   
run_resultr<   r!   )rC   s   "r*   rD   RunAssert.__annotate__   s        9  r)   c                	6    VP                   V n        ^ V n        R# )r   N)rY   _events_list_current_index)rR   r   s   &&r*   rS   RunAssert.__init__   s    &--r)   c                    V ^8  d   QhRRRR/# )r?   r   r   rA   EventAssertr!   )rC   s   "r*   rD   r      s    9999r)   c                	    R # rG   r!   )rR   r   s   &&r*   __getitem__RunAssert.__getitem__   s    69r)   c                    V ^8  d   QhRRRR/# )r?   sslicerA   EventRangeAssertr!   )rC   s   "r*   rD   r      s    <<U<'7<r)   c                	    R # rG   r!   )rR   r   s   &&r*   r   r      s    9<r)   c                    V ^8  d   QhRRRR/# )r?   keyz[int, slice]rA   zEventAssert | EventRangeAssertr!   )rC   s   "r*   rD   r      s     *
 *
| *
0N *
r)   c                &   \        V\        4      '       d    V P                  V,          p\        W V4      # \        V\        4      '       d   V^ 8  d   V\        V P                  4      ,          p^ Tu;8:  d   \        V P                  4      8  g0   M V P                  RV R\        V P                  4       R2VR7       \        V P                  V,          W4      # \        \        V 4      P                   R\        V4      P                   24      h)a  
Access a specific event or range for assertions.

Args:
    key (int | slice): Index or slice of events.

Returns:
    EventAssert: Assertion for a single event when key is int.
    EventRangeAssert: Assertion for a span of events when key is slice.

Raises:
    TypeError: If key is not an int or slice.
    AssertionError: If index is out of range.

Examples:
    # Single event access
    >>> result.expect[0].is_message(role="user")
    >>> result.expect[-1].is_message(role="assistant")

    # Full range access
    >>> result.expect[:].contains_function_call(name="foo")

    # Partial range access
    >>> result.expect[0:2].contains_message(role="assistant")
znth(z) out of range (total events: )r   z# indices must be int or slice, not )r   r   r   r   r   r   _raise_with_debug_infor   	TypeErrorr    r#   )rR   r   rY   s   && r*   r   r      s    4 c5!!&&s+F#F#66c3Qws4,,--5s4#4#455++3%=c$BSBS>T=UUVW ,  t005tAADz""##FtCyGYGYFZ[
 	
r)   c                   V ^8  d   QhRR/# )r?   rA   r   r!   )rC   s   "r*   rD   r   !  s       r)   c                	    R pV P                   \        V P                  4      8  d   V P                  R4       W P                   ,          pV# )Tz&Expected another event, but none left.)r   r   r   r   rR   __tracebackhide__r   s   &  r*   _current_eventRunAssert._current_event!  sC     #d&7&7"88''(PQ(()r)   Nc               $    V ^8  d   QhRRRRRR/# )r?   r   strr   
int | NonerA   rB   r!   )rC   s   "r*   rD   r   *  s'     S Sc S* SPT Sr)   c                	    R pVf   V P                   MTpRP                  \        V P                  VR7      4      p\	        V R2V,           4      h)T
)selected_indexz
Context around failure:
)r   r_   r`   r   AssertionError)rR   r   r   r   marker_indexrb   s   &&&   r*   r    RunAssert._raise_with_debug_info*  sM     .3mt**YY~d.?.?P\]^
y(CDzQRRr)   r    c                    V ^8  d   QhRRRR/# )r?   r    rB   rA   r   r!   )rC   s   "r*   rD   r   2  s    BB$B+Br)   c               	    R # rG   r!   rR   r    s   &$r*   
next_eventRunAssert.next_event1  s    ?Br)   c                    V ^8  d   QhRRRR/# )r?   r    r   rA   ChatMessageAssertr!   )rC   s   "r*   rD   r   5  s    OO"4O9JOr)   c               	    R # rG   r!   r   s   &$r*   r   r   4  s    LOr)   c                    V ^8  d   QhRRRR/# )r?   r    r.   rA   FunctionCallAssertr!   )rC   s   "r*   rD   r   8      VV":V?QVr)   c               	    R # rG   r!   r   s   &$r*   r   r   7      SVr)   c                    V ^8  d   QhRRRR/# )r?   r    r2   rA   FunctionCallOutputAssertr!   )rC   s   "r*   rD   r   ;  s    cc"AcF^cr)   c               	    R # rG   r!   r   s   &$r*   r   r   :  s    `cr)   c                    V ^8  d   QhRRRR/# )r?   r    r:   rA   AgentHandoffAssertr!   )rC   s   "r*   rD   r   >  r   r)   c               	    R # rG   r!   r   s   &$r*   r   r   =  r   r)   c                    V ^8  d   QhRRRR/# )r?   r    zSLiteral['message', 'function_call', 'function_call_output', 'agent_handoff'] | NonerA   zdEventAssert | ChatMessageAssert | FunctionCallAssert | FunctionCallOutputAssert | AgentHandoffAssertr!   )rC   s   "r*   rD   r   @  s      * **	*r)   c               b   Rp V P                  4       pV ;P                  ^,          un        Ve"   VP                  4       P                  V8X  g   KO   TR8X  d   TP	                  4       # TR8X  d   TP                  4       # TR8X  d   TP                  4       # TR8X  d   TP                  4       # T# )a  
Advance to the next event, optionally filtering by type.

Args:
    type (str, optional): Event type to match.

Returns:
    EventAssert or subclass: Assertion object for the matched event.

Example:
    >>> result.expect.next_event(type="function_call").is_function_call(name="foo")
Tr   r-   r1   r9   )r   r   r   r    
is_messageis_function_callis_function_call_outputis_agent_handoff)rR   r    r   	ev_asserts   &$  r*   r   r   @  s    0 !++-I1$|y055=9''))_$--//++4466_$--//r)   rolec               $    V ^8  d   QhRRRRRR/# )r?   r    r   r   NotGivenOr[llm.ChatRole]rA   zChatMessageAssert | Noner!   )rC   s   "r*   rD   r   m  s$     ' ')'1I'	!'r)   c               	    R # rG   r!   )rR   r    r   s   &$$r*   skip_next_event_ifRunAssert.skip_next_event_ifl  s     $'r)   name	argumentsc               (    V ^8  d   QhRRRRRRRR/# )	r?   r    r.   r  NotGivenOr[str]r  NotGivenOr[dict[str, Any]]rA   zFunctionCallAssert | Noner!   )rC   s   "r*   rD   r   r  s4     ( ( '( 	(
 .( 
#(r)   c               	    R # rG   r!   )rR   r    r  r  s   &$$$r*   r  r  q  s     %(r)   outputis_errorc               (    V ^8  d   QhRRRRRRRR/# )	r?   r    r2   r
  r  r  NotGivenOr[bool]rA   zFunctionCallOutputAssert | Noner!   )rC   s   "r*   rD   r   {  s4     . . ..  	.
 #. 
).r)   c               	    R # rG   r!   )rR   r    r
  r  s   &$$$r*   r  r  z  s     +.r)   new_agent_typec               $    V ^8  d   QhRRRRRR/# )r?   r    r:   r  NotGivenOr[type[Agent]]rA   zAgentHandoffAssert | Noner!   )rC   s   "r*   rD   r     s$     ( (/(AX(	"(r)   c               	    R # rG   r!   )rR   r    r  s   &$$r*   r  r    s     %(r)   c               8    V ^8  d   QhRRRRRRRRR	RR
RRRRR/# )r?   r    zLLiteral['message', 'function_call', 'function_call_output', 'agent_handoff']r   r   r  r  r  r  r
  r  r  r  r  rA   z]ChatMessageAssert | AgentHandoffAssert | FunctionCallAssert | FunctionCallOutputAssert | Noner!   )rC   s   "r*   rD   r     s]     :1 :1 [:1 '	:1
 :1 .:1  :1 #:1 0:1	:1r)   c                  Rp Rp	VR8X  d"   V P                  4       P                  VR7      p	MwVR8X  d"   V P                  4       P                  W4R7      p	MOVR8X  d"   V P                  4       P                  WVR7      p	M'VR	8X  d!   V P                  4       P	                  VR
7      p	V ;P
                  ^,          un        V	#   \         d     R# i ; i)a  
Conditionally skip the next event if it matches criteria.

Args:
    type (str): Type of event to check.
    role (ChatRole, optional): Required role for message events.
    name (str, optional): Required function name for calls.
    arguments (dict, optional): Required args for function calls.
    output (str, optional): Required output for function call outputs.
    is_error (bool, optional): Required error flag for call outputs.
    new_agent_type (type, optional): Required agent class for handoffs.

Returns:
    EventAssert or None: The skipped event assertion if matched.

Example:
    >>> skipped = result.expect.skip_next_event_if(type="message", role="assistant")
TNr   r   r-   r  r  r1   r
  r  r9   r  )r   r   r   r   r   r   r   rh   )
rR   r    r   r  r  r
  r  r  r   evs
   &$$$$$$$  r*   r  r    s    F !	   y ((*5545@(((*;;;[//((*BB&Bd(((*;;>;Z1$I 		s   B;C   CCc                    V ^8  d   QhRRRR/# )r?   countr   rA   r\   r!   )rC   s   "r*   rD   r     s      s 9 r)   c                    Rp\        V4       FX  pV P                  \        V P                  4      8  d   V P	                  RV RV R24       V ;P                  ^,          un        KZ  	  V # )z
Skip a specified number of upcoming events without assertions.

Args:
    count (int): Number of events to skip.

Returns:
    RunAssert: Self for chaining.

Example:
    >>> result.expect.skip_next(2)
TzTried to skip z event(s), but only z were available.)r   r   r   r   r   )rR   r  r   r   s   &&  r*   	skip_nextRunAssert.skip_next  sm     !uA""c$*;*;&<<++$UG+?sBRS 1$  r)   c                   V ^8  d   QhRR/# r   r!   )rC   s   "r*   rD   r     s       r)   c                    RpV P                   \        V P                  4      8  dG   V P                  V P                   ,          pV P                  R\	        V4      P
                   24       R# R# )z
Assert that there are no further events.

Raises:
    AssertionError: If unexpected events remain.

Example:
    >>> result.expect.no_more_events()
Tz$Expected no more events, but found: N)r   r   r   r   r    r#   r   s   &  r*   no_more_eventsRunAssert.no_more_events  sa     !T%6%6!77%%d&9&9:E''6tE{7K7K6LM 8r)   c               $    V ^8  d   QhRRRRRR/# r?   r  r  r  r  rA   r   r!   )rC   s   "r*   rD   r     s/     N N N .	N
 
Nr)   c               8    RpV R,          P                  WR7      # )a1  
Assert existence of a function call event matching criteria.

Args:
    name (str, optional): Function name to match.
    arguments (dict, optional): Arguments to match.

Returns:
    FunctionCallAssert: Assertion for the matching call.

Example:
    >>> result.expect.contains_function_call(name="foo")
TNNNr  )contains_function_call)rR   r  r  r   s   &$$ r*   r'   RunAssert.contains_function_call  s"    & !Aw--4-MMr)   c                    V ^8  d   QhRRRR/# r?   r   r   rA   r   r!   )rC   s   "r*   rD   r     s      3 3 '3 
	3r)   c               8    RpV R,          P                  VR7      # )z
Assert existence of a message event matching criteria.

Args:
    role (ChatRole, optional): Role to match.

Returns:
    ChatMessageAssert: Assertion for the matching message.

Example:
    >>> result.expect.contains_message(role="user")
Tr&  r  )contains_messagerR   r   r   s   &$ r*   r,  RunAssert.contains_message  s"    " !Aw''T'22r)   c               $    V ^8  d   QhRRRRRR/# r?   r
  r  r  r  rA   r   r!   )rC   s   "r*   rD   r     s/     W W  W #	W
 
"Wr)   c               8    RpV R,          P                  WR7      # )aL  
Assert existence of a function call output event matching criteria.

Args:
    output (str, optional): Output string to match.
    is_error (bool, optional): Error flag to match.

Returns:
    FunctionCallOutputAssert: Assertion for the matching output.

Example:
    >>> result.expect.contains_function_call_output(is_error=True)
Tr&  r  )contains_function_call_outputrR   r
  r  r   s   &$$ r*   r2  'RunAssert.contains_function_call_output  s"    & !Aw44F4VVr)   c                    V ^8  d   QhRRRR/# r?   r  r  rA   r   r!   )rC   s   "r*   rD   r   .  s      M M!8M	Mr)   c               8    RpV R,          P                  VR7      # )a  
Assert existence of an agent handoff event matching criteria.

Args:
    new_agent_type (type, optional): Expected new agent class.

Returns:
    AgentHandoffAssert: Assertion for the matching handoff.

Example:
    >>> result.expect.contains_agent_handoff(new_agent_type=MyAgent)
Tr&  r  )contains_agent_handoffrR   r  r   s   &$ r*   r8   RunAssert.contains_agent_handoff.  s"     !Aw--^-LLr)   )r   r   rG   )   )r#   r$   r%   r&   rS   r   r   r   r   r   r   r  r  r!  r'  r,  r2  r8  r(   r!   r)   r*   r\   r\      s     9 9< <*
XS BB BO OV Vc cV V* 	*X 'LU' ' ( !*	(
 1:( ( . #,	.
 &/. . ([d( (:1 *3	:1
 !*:1 1::1 #,:1 &/:1 3<:1x0$N !*N 1:	N,3 *33(W #,W &/	W,M;DM Mr)   r\   c                      ] tR tRtRR R lltR R ltR R ltR]R	]/R
 R lltR]R]/R R llt	R]/R R llt
R]/R R lltRtR# )r   iA  c               $    V ^8  d   QhRRRRRR/# )r?   r   RunEventparentr\   r   r   r!   )rC   s   "r*   rD   EventAssert.__annotate__B  s!      h 	 # r)   c                	*    Wn         W n        W0n        R # rG   _event_parent_indexrR   r   r?  r   s   &&&&r*   rS   EventAssert.__init__B      r)   c                    V ^8  d   QhRRRR/# r?   r   r   rA   rB   r!   )rC   s   "r*   rD   r@  G       H Hc Hd Hr)   c                	V    R pV P                   P                  WP                  R7       R# Tr   NrD  r   rE  rR   r   r   s   && r*   _raiseEventAssert._raiseG  !     ++G;;+Gr)   c                   V ^8  d   QhRR/# )r?   rA   r>  r!   )rC   s   "r*   rD   r@  K  s      x r)   c                	    V P                   # rG   rC  rX   s   &r*   r   EventAssert.eventK      {{r)   r  r  c               $    V ^8  d   QhRRRRRR/# r$  r!   )rC   s   "r*   rD   r@  N  s/     %J %J %J .	%J
 
%Jr)   c                  Rp\        V P                  \        4      '       g   V P                  R4       \        V P                  \        4      '       g   Q h\	        V4      '       d\   V P                  P
                  P                  V8w  d7   V P                  RV RV P                  P
                  P                   R24       \	        V4      '       d   \        P                  ! V P                  P
                  P                  4      pVP                  4        FC  w  rVWT9  g   WE,          V8w  g   K  V P                  RV RV RVP                  V4       24       KE  	  \        V P                  V P                  V P                  4      # )	a  
Verify this event is a function call with matching details.

Args:
    name (str, optional): Expected function name.
    arguments (dict, optional): Expected call arguments.

Returns:
    FunctionCallAssert: Assertion for the function call.

Raises:
    AssertionError: If the event is not a function call or details mismatch.

Example:
    >>> ev_assert.is_function_call(name="foo", arguments={"x": 1})
TzExpected FunctionCallEventzExpected call name '', got ''z	For key 'z', expected r   )r   rC  r,   rP  r   r   r  jsonloadsr  itemsgetr   rD  rE  )rR   r  r  r   actualr   values   &$$    r*   r   EventAssert.is_function_callN  s    , !$++'899KK45$++'89999D>>dkk..33t;KK.tfHT[[=M=M=R=R<SSTUVIZZ 0 0 : :;F'oo/
$u(<KK)C5UG6&**UX/IZ [\ 0 "$++t||T[[IIr)   r
  r  c               $    V ^8  d   QhRRRRRR/# r0  r!   )rC   s   "r*   rD   r@  u  s)     P P(P@PP	!Pr)   c                  Rp\        V P                  \        4      '       g   V P                  R4       \        V P                  \        4      '       g   Q h\	        V4      '       d\   V P                  P
                  P                  V8w  d7   V P                  RV RV P                  P
                  P                   R24       \	        V4      '       d[   V P                  P
                  P                  V8w  d6   V P                  RV RV P                  P
                  P                   24       \        V P                  V P                  V P                  4      # )a  
Verify this event is a function call output with matching details.

Args:
    output (str, optional): Expected output text.
    is_error (bool, optional): Expected error flag.

Returns:
    FunctionCallOutputAssert: Assertion for the output.

Raises:
    AssertionError: If the event is not function output or details mismatch.

Example:
    >>> ev_assert.is_function_call_output(output="OK", is_error=False)
Tz Expected FunctionCallOutputEventzExpected output 'rZ  r[  zExpected is_error=r   )r   rC  r0   rP  r   r   r
  r  r   rD  rE  r3  s   &$$ r*   r   #EventAssert.is_function_call_outputu  s    & !$++'>??KK:;$++'>????F 0 0 7 76 AKK+F88DKK<L<L<S<S;TTUVWH$++"2"2";";x"GKK,XJfT[[=M=M=V=V<WXY'T\\4;;OOr)   r   c                    V ^8  d   QhRRRR/# r*  r!   )rC   s   "r*   rD   r@    s      I I": IK\ Ir)   c                  Rp\        V P                  \        4      '       g   V P                  R4       \        V P                  \        4      '       g   Q h\	        V4      '       d\   V P                  P
                  P                  V8w  d7   V P                  RV RV P                  P
                  P                   R24       \        V P                  V P                  V P                  4      # )a3  
Verify this event is a message from the given role.

Args:
    role (ChatRole, optional): Expected sender role.

Returns:
    ChatMessageAssert: Assertion for the message.

Raises:
    AssertionError: If the event is not a message or role mismatch.

Example:
    >>> ev_assert.is_message(role="assistant")
TzExpected ChatMessageEventzExpected role 'rZ  r[  )
r   rC  r   rP  r   r   r   r   rD  rE  r-  s   &$ r*   r   EventAssert.is_message  s      !$++'788KK34$++'78888D>>dkk..33t;KK/$x8H8H8M8M7NaPQ dllDKKHHr)   r  c                    V ^8  d   QhRRRR/# r6  r!   )rC   s   "r*   rD   r@    s      J J!8J	Jr)   c                  Rp\        V P                  \        4      '       g   V P                  R4       \        V P                  \        4      '       g   Q h\	        V4      '       dp   \        V P                  P
                  V4      '       gJ   V P                  RVP                   R\        V P                  P
                  4      P                   R24       \        V P                  V P                  V P                  4      # )aD  
Verify this event is an agent handoff.

Args:
    new_agent_type (type, optional): Expected new agent class.

Returns:
    AgentHandoffAssert: Assertion for the handoff.

Raises:
    AssertionError: If the event is not an agent handoff or type mismatch.

Example:
    >>> ev_assert.is_agent_handoff(new_agent_type=MyAgent)
TzExpected AgentHandoffEventzExpected new_agent 'rZ  r[  )r   rC  r4   rP  r   r8   r#   r    r   rD  rE  r9  s   &$ r*   r   EventAssert.is_agent_handoff  s    $ !$++'899KK45$++'89999N##Jt{{7L7Ln,],]KK&~'>'>&?xT[[MbMbHcHlHlGmmno "$++t||T[[IIr)   rC  rE  rD  N))r#   r$   r%   r&   rS   rP  r   r   r   r   r   r   r(   r!   r)   r*   r   r   A  sk    
H%J !*%J 1:	%JNP+4PS\P@IY I6J;DJ Jr)   r   c                  z    ] tR tRtR R ltR]R]/R R lltR]/R	 R
 lltR]R]/R R lltR]/R R llt	Rt
R# )r   i  c               $    V ^8  d   QhRRRRRR/# )r?   rY   rV   r?  r\   rngr   r!   )rC   s   "r*   rD   EventRangeAssert.__annotate__  s!      ~ y u r)   c                	*    Wn         W n        W0n        R # rG   _eventsrD  _rng)rR   rY   r?  rp  s   &&&&r*   rS   EventRangeAssert.__init__  s    	r)   r  r  c               $    V ^8  d   QhRRRRRR/# r$  r!   )rC   s   "r*   rD   rq    s*      *  *  * .	 *
 
 *r)   c                  Rp\        V P                  4       F  w  rE\        YPP                  V P                  P
                  ;'       g    ^ V,           4      p\        P                  ! \        4      ;_uu_ 4        VP                  WR7      uuRRR4       u # 	  V P                  P                  RV P                  : 24       \        R4      h  + '       g   i     K  ; i)a  
Assert that a function call matching criteria exists in the event range.

Args:
    name (str, optional): Expected function name.
    arguments (dict, optional): Expected call arguments.

Returns:
    FunctionCallAssert: Assertion for the matched function call.

Raises:
    AssertionError: If no matching function call is found in range.

Example:
    >>> result.expect[0:3].contains_function_call(name="foo")
Tr  Nz8No FunctionCallEvent satisfying criteria found in range unreachable)	enumeratert  r   rD  ru  startr   r   r   r   r   rh   )rR   r  r  r   idxr  	candidates   &$$    r*   r'  'EventRangeAssert.contains_function_call  s    , ! .GC#Btyy7K7K!s6RSI$$^44 11t1Q 54 /
 	++FtyymT	
 =)) 544   :CC r   c                    V ^8  d   QhRRRR/# r*  r!   )rC   s   "r*   rD   rq    s      * * '* 
	*r)   c                  Rp\        V P                  4       F  w  r4\        Y@P                  V P                  P
                  ;'       g    ^ V,           4      p\        P                  ! \        4      ;_uu_ 4        VP                  VR7      uuRRR4       u # 	  V P                  P                  RV P                  : 24       \        R4      h  + '       g   i     K  ; i)aR  
Assert that a message matching criteria exists in the event range.

Args:
    role (ChatRole, optional): Expected sender role.

Returns:
    ChatMessageAssert: Assertion for the matched message.

Raises:
    AssertionError: If no matching message is found in range.

Example:
    >>> result.expect[:2].contains_message(role="assistant")
Tr  Nz5No ChatMessageEvent matching criteria found in range ry  )rz  rt  r   rD  ru  r{  r   r   r   r   r   rh   )rR   r   r   r|  r  r}  s   &$    r*   r,  !EventRangeAssert.contains_message  s    ( ! .GC#Btyy7K7K!s6RSI$$^44 +++6 54 /
 	++CDII=Q	
 =)) 544r  r
  r  c               $    V ^8  d   QhRRRRRR/# r0  r!   )rC   s   "r*   rD   rq    s*      *  *   * #	 *
 
" *r)   c                  Rp\        V P                  4       F  w  rE\        YPP                  V P                  P
                  ;'       g    ^ V,           4      p\        P                  ! \        4      ;_uu_ 4        VP                  WR7      uuRRR4       u # 	  V P                  P                  RV P                  : 24       \        R4      h  + '       g   i     K  ; i)a  
Assert that a function call output matching criteria exists in the event range.

Args:
    output (str, optional): Expected output text.
    is_error (bool, optional): Expected error flag.

Returns:
    FunctionCallOutputAssert: Assertion for the matched output.

Raises:
    AssertionError: If no matching output is found in range.

Example:
    >>> result.expect[1:4].contains_function_call_output(is_error=True)
Tr  Nz<No FunctionCallOutputEvent matching criteria found in range ry  )rz  rt  r   rD  ru  r{  r   r   r   r   r   rh   )rR   r
  r  r   r|  r  r}  s   &$$    r*   r2  .EventRangeAssert.contains_function_call_output  s    , ! .GC#Btyy7K7K!s6RSI$$^44 888Z 54 /
 	++J499-X	
 =)) 544r  r  c                    V ^8  d   QhRRRR/# r6  r!   )rC   s   "r*   rD   rq  :  s     * *!8*	*r)   c                  Rp\        V P                  4       F  w  r4\        Y@P                  V P                  P
                  ;'       g    ^ V,           4      p\        P                  ! \        4      ;_uu_ 4        VP                  VR7      uuRRR4       u # 	  V P                  P                  RV P                  : 24       \        R4      h  + '       g   i     K  ; i)aq  
Assert that an agent handoff matching criteria exists in the event range.

Args:
    new_agent_type (type, optional): Expected new agent class.

Returns:
    AgentHandoffAssert: Assertion for the matched handoff.

Raises:
    AssertionError: If no matching handoff is found in range.

Example:
    >>> result.expect[0:3].contains_agent_handoff(new_agent_type=MyAgent)
Tr  Nz6No AgentHandoffEvent matching criteria found in range ry  )rz  rt  r   rD  ru  r{  r   r   r   r   r   rh   )rR   r  r   r|  r  r}  s   &$    r*   r8  'EventRangeAssert.contains_agent_handoff:  s    $ ! .GC#Btyy7K7K!s6RSI$$^44 111P 54 /
 	++DTYYMR	
 =)) 544r  rs  N)r#   r$   r%   r&   rS   r   r'  r,  r2  r8  r(   r!   r)   r*   r   r     s]    
 * !* * 1:	 *D* *3*@ * #, * &/	 *D*;D* *r)   r   c                  p    ] tR tRtR R ltR R ltR R lt]P                  ! R4      R	 R
 l4       t	Rt
R# )r   iY  c               $    V ^8  d   QhRRRRRR/# )r?   r   r   r?  r\   r   r   r!   )rC   s   "r*   rD   ChatMessageAssert.__annotate__Z  s"      . 	 # r)   c                	*    Wn         W n        W0n        R # rG   rB  rF  s   &&&&r*   rS   ChatMessageAssert.__init__Z  rH  r)   c                    V ^8  d   QhRRRR/# rJ  r!   )rC   s   "r*   rD   r  _  rK  r)   c                	V    R pV P                   P                  WP                  R7       R# rM  rN  rO  s   && r*   rP  ChatMessageAssert._raise_  rR  r)   c                   V ^8  d   QhRR/# )r?   rA   r   r!   )rC   s   "r*   rD   r  c  s      ' r)   c                	    V P                   # rG   rU  rX   s   &r*   r   ChatMessageAssert.eventc  rW  r)   judge_evaluationc               $    V ^8  d   QhRRRRRR/# )r?   llm_vzllm.LLMintentr   rA   r   r!   )rC   s   "r*   rD   r  g  s'     | | |S |=N |r)   c                 a"   Rp\         P                  ! 4       pV P                  P                  P                  pVP                  \        P                  R4       VP                  \        P                  SP                  4       VP                  \        P                  R4       VP                  \        P                  \        P                  ! RVRV/4      4       V'       g   V P                  R4       \        R4      hV'       g   V P                  R4       \        R4      h\         R	 R
 l4       p\"        P$                  ! 4       pVP'                  RRR7       VP'                  RRV RV 2R7       RpRp	/ p
R.p\(        ;QJ d    V3R lV 4       F  '       g   K   RM	  RM! V3R lV 4       4      '       g   RV
R&   SP+                  VV.RRRRR//V
R7        Rj  xL
  pVP,                  e   VP,                  p	VP.                  '       g   K8  VP.                  P0                  '       g   KV  VP.                  P0                  ^ ,          pVP2                  pK   L|D}T'       g   T P                  R4       \5        T\6        4      '       g   Q h\8        P:                  ! YhR7      w  rT! T/ TB G Rj  xL 
 w  ppTP                  \        P<                  T'       * 4       TP                  \        P>                  T4       T	'       d   TPA                  \        PB                  T	PD                  \        PF                  T	PH                  \        PJ                  T	PD                  \        PL                  T	PH                  \        PN                  T	PP                  /4       T'       g   T P                  RT 24       T # \R        '       d4   ^ RI*H+p T! TPY                  R R!4      ^R"R#7      p\[        R$T R%T R&24       T # 5i)'a9  
Evaluate whether the message fulfills the given intent.

Args:
    llm_v (llm.LLM): LLM instance for judgment.
    intent (str): Description of the expected intent.

Returns:
    ChatMessageAssert: Self for chaining further assertions.

Example:
    >>> await msg_assert.judge(llm, intent="should ask for size")
Tjudger  r  r   zThe chat message is empty.ry  z(Intent is required to judge the message.c               $    V ^8  d   QhRRRRRR/# )r?   successrl   reasonr   rA   ztuple[bool, str]r!   )rC   s   "r*   rD   -ChatMessageAssert.judge.<locals>.__annotate__  s"     	# 	# 	#c 	#>N 	#r)   c                   "   W3# 5i)z
Determines whether the message correctly fulfills the given intent.

Args:
    success: Whether the message satisfies the intent.
    reason: A concise explanation justifying the result.
r!   )r  r  s   &&r*   check_intent-ChatMessageAssert.judge.<locals>.check_intent  s      ?"s   systeman  You are a test evaluator for conversational agents.
You will be shown a message and a target intent. Determine whether the message accomplishes the intent.
Only respond by calling the `check_intent(success: bool, reason: str)` function with your final judgment.
Be strict: if the message does not clearly fulfill the intent, return `success = False` and explain why.)r   contentuserzCCheck if the following message fulfills the given intent.

Intent:
z

Message:
Nzgpt-5c              3  @   <"   T F  qSP                   9   x  K  	  R # 5irG   )model)r   excluded_modelr  s   & r*   r   *ChatMessageAssert.judge.<locals>.<genexpr>  s     cGb^U[[0Gbs   Fg        temperaturer    functionr  r  )chat_ctxtoolstool_choiceextra_kwargsz0LLM did not return any arguments for evaluation.)fncjson_argumentszJudgement failed: )shortenr   z\nz...)widthplaceholderz- Judgment succeeded for `z`: ``).r   get_current_spanrC  r   text_contentset_attributer   ATTR_GEN_AI_OPERATION_NAMEATTR_GEN_AI_REQUEST_MODELr  ATTR_FUNCTION_TOOL_NAMEATTR_FUNCTION_TOOL_ARGSr\  dumpsrP  rh   r   r   ChatContextadd_messageanychatusagedelta
tool_callsr  r   r   	llm_utilsprepare_function_argumentsATTR_FUNCTION_TOOL_IS_ERRORATTR_FUNCTION_TOOL_OUTPUTset_attributesATTR_GEN_AI_USAGE_INPUT_TOKENSprompt_tokensATTR_GEN_AI_USAGE_OUTPUT_TOKENScompletion_tokens#ATTR_GEN_AI_USAGE_INPUT_TEXT_TOKENS$ATTR_GEN_AI_USAGE_OUTPUT_TEXT_TOKENS%ATTR_GEN_AI_USAGE_INPUT_CACHED_TOKENSprompt_cached_tokensr^   textwrapr  replacera   )rR   r  r  r   current_spanmsg_contentr  r  r  r  r  excluded_models_temperaturechunktoolfnc_args
fnc_kwargsr  r  r  	print_msgs   &f$                 r*   r  ChatMessageAssert.judgef  sv     !--/kk&&33"";#I#I7S"";#H#H%++V"";#F#FHZ[""//JJ&)[AB	

 KK45}--KKBC}--		# 
	# ??${ 	 	
 	"8 $(M+ 	 	
 !%	,0'.i#scGbcssscGbccc*-L' !::.Z&.9QR%	 & 
 	+ 	+% {{&;;;{{%%%{{--a0 NN		+ 
  KKJK)S))))(CC 
 !-h E* EEE"";#J#JPWKX"";#H#H&Q''>>@S@S??AXAXCCUEXEXDDeF]F]EEuGaGa KK,VH56  ( 3 3D% @X]^I.ykfXQGHsv   DP 	A?P 	P  P >!P I"#I $I"'-P P 5+P  I""P +AP 8J;9AP BP )!P 5P rl  N)r#   r$   r%   r&   rS   rP  r   r   start_as_current_spanr  r(   r!   r)   r*   r   r   Y  s4    
H !!"45| 6|r)   r   c                  .    ] tR tRtR R ltR R ltRtR# )r   i  c               $    V ^8  d   QhRRRRRR/# )r?   r   r,   r?  r\   r   r   r!   )rC   s   "r*   rD   FunctionCallAssert.__annotate__  "      /  3 r)   c                	*    Wn         W n        W0n        R # rG   rB  rF  s   &&&&r*   rS   FunctionCallAssert.__init__  rH  r)   c                   V ^8  d   QhRR/# )r?   rA   r,   r!   )rC   s   "r*   rD   r          ( r)   c                	    V P                   # rG   rU  rX   s   &r*   r   FunctionCallAssert.event  rW  r)   rl  Nr#   r$   r%   r&   rS   r   r(   r!   r)   r*   r   r         
 r)   r   c                  .    ] tR tRtR R ltR R ltRtR# )r   i  c               $    V ^8  d   QhRRRRRR/# )r?   r   r0   r?  r\   r   r   r!   )rC   s   "r*   rD   %FunctionCallOutputAssert.__annotate__  s#      5 y QT r)   c                	*    Wn         W n        W0n        R # rG   rB  rF  s   &&&&r*   rS   !FunctionCallOutputAssert.__init__  rH  r)   c                   V ^8  d   QhRR/# )r?   rA   r0   r!   )rC   s   "r*   rD   r    s      . r)   c                	    V P                   # rG   rU  rX   s   &r*   r   FunctionCallOutputAssert.event  rW  r)   rl  Nr  r!   r)   r*   r   r     r  r)   r   c                  .    ] tR tRtR R ltR R ltRtR# )r   i  c               $    V ^8  d   QhRRRRRR/# )r?   r   r4   r?  r\   r   r   r!   )rC   s   "r*   rD   AgentHandoffAssert.__annotate__  r  r)   c                	*    Wn         W n        W0n        R # rG   rB  rF  s   &&&&r*   rS   AgentHandoffAssert.__init__  rH  r)   c                   V ^8  d   QhRR/# )r?   rA   r4   r!   )rC   s   "r*   rD   r     r  r)   c                	    V P                   # rG   rU  rX   s   &r*   r   AgentHandoffAssert.event   rW  r)   rl  Nr  r!   r)   r*   r   r     r  r)   r   	MockToolsagents_mock_toolsc               $    V ^8  d   QhRRRRRR/# )r?   agentztype[Agent]mockszdict[str, Callable]rA   zGenerator[None, None, None]r!   )rC   s   "r*   rD   rD     s#     * *k **= *B] *r)   c              #     "   \         P                  / 4      p/ VCW/Cp\         P                  V4      p Rx  \         P                  V4       R#   \         P                  T4       i ; i5i)z
Temporarily assign a set of mock tool callables to a specific Agent type within the current context.

Usage:
    with mock_tools(MyAgentClass, {"tool_name": mock_fn}):
        # inside this block, MyAgentClass will see the given mocks
N)_MockToolsContextVarr_  rH   reset)r  r  currentupdatedtokens   &&   r*   
mock_toolsr  
  s[      #&&r*G''%'G $$W-E*""5)""5)s   2A*A A*A''A*r   c               $    V ^8  d   QhRRRRRR/# )r?   rY   rV   r   r   rA   z	list[str]r!   )rC   s   "r*   rD   rD     s"      > j T] r)   c          	        . p\        V 4       F  w  r4R pVe   W18X  d   RMRp\        V\        \        \        34      '       dD   VP
                  P                  RR0 RmR7      pV RV RVP                  P                   RV R2pMC\        V\        4      '       d$   V RV R	VP                   R
VP                   R2pM
V RV RV 2pVP                  V4       K  	  V# ) z>>>z   T)exclude_noneexclude_defaultsexcludez [z] z(item=r   z] AgentHandoffEvent(old_agent=z, new_agent=>   idr    call_idr|   )rz  r   r   r,   r0   r   
model_dump	__class__r#   r4   r7   r8   append)rY   r   linesr   r   prefix	item_reprlines   &$      r*   r`   r`     s    Ef%%1UuFe.0ACZ[\\

--!!%? . I
 XRs"U__%=%=$>fYKqQD011("QC  "__-\%//9J!M 
 XRs"UG,DT) &, Lr)   )@
__future__r   rJ   r   contextvarsr   r\  oscollections.abcr   r   r   dataclassesr   typingr   r	   r
   r   r   r   opentelemetryr   r  r   r   r   r  	telemetryr   r   typesr   r   r   speech_handler   r  r   r   getenvr^   r   r   r,   r0   r4   r>  r<   r\   r   r   r   r   r   r   dictr    r   r  
ContextVarr  r  r`   r!   r)   r*   <module>r      s   "      	 / % !     3 + )  ' ryy!8!<=  ) ) )
 5 5 5
 C C C
 5 5 5 //2IIL]]d dNSM SMl
LJ LJ^F* F*RJ JZ    T%[$sH}"556I"--k:;NO  * *"4  r)   