
    Cj                       S SK Jr  S SKrS SKJr  S SKJrJrJrJ	r	  S SK
Jr  S SKJr  SSKJrJr  SS	KJr  SS
KJrJr  SSKJr  SSKJr  SSKJrJr  SSKJr  SSKJ r   \(       a  SSK!J"r"  \" S\S9r#\\\   \#/\4   r$\\\   /\4   r%\	SSSS.         SS jj5       r&\	SSSS.             SS jj5       r&\	SSSS.           SS jj5       r&     S             SS jjr&g)     )annotationsN)Callable)TYPE_CHECKINGAnycastoverload)TypeAdapter)TypeVar   )ModelBehaviorError	UserError)Handoff)RunContextWrapperTContext)ensure_strict_json_schema)	SpanError)_error_tracing_json)MaybeAwaitable   )RealtimeAgent)	AgentBaseTHandoffInput)defaultT)tool_name_overridetool_description_override
is_enabledc                   g N )agentr   r   r   s       j/home/rurouni/.local/share/pipx/venvs/strix-agent/lib/python3.13/site-packages/agents/realtime/handoffs.pyrealtime_handoffr#      s     25    )r   r   r   c                   g r   r    )r!   
on_handoff
input_typer   r   r   s         r"   r#   r#   )   s     25r$   c                   g r   r    )r!   r&   r   r   r   s        r"   r#   r#   6   s     25r$   c                  ^ ^^^^ T(       a  T(       d  T(       a  T(       a   S5       eTbm  [        T5      (       d   S5       e[        R                  " T5      n[        UR                  5      S:w  a  [        S5      e[        T5      mTR                  5       nOASm0 nTb:  [        R                  " T5      n[        UR                  5      S:w  a  [        S5      e S     SU UUU4S jjjnU=(       d    [        R                  " T 5      n	U=(       d    [        R                  " T 5      n
[        U5      nSU4S	 jjn[        U	U
UUST R                  [        T5      (       a  US
9$ TS
9$ )aJ  Create a handoff from a RealtimeAgent.

Args:
    agent: The RealtimeAgent to handoff to.
    tool_name_override: Optional override for the name of the tool that represents the handoff.
    tool_description_override: Optional override for the description of the tool that
        represents the handoff.
    on_handoff: A function that runs when the handoff is invoked.
    input_type: the type of the input to the handoff. If provided, the input will be validated
        against this type. Only relevant if you pass a function that takes an input.
    is_enabled: Whether the handoff is enabled. Can be a bool or a callable that takes the run
        context and agent and returns whether the handoff is enabled. Disabled handoffs are
        hidden from the LLM at runtime.

Note: input_filter is not supported for RealtimeAgent handoffs.
zBYou must provide either both on_handoff and input_type, or neitherNzon_handoff must be callabler   z5on_handoff must take two arguments: context and inputr   z*on_handoff must take one argument: contextc                  >#    Tb  Tb  Uc+  [         R                  " [        SSS0S95        [        S5      e[        R
                  " UTSS9n[        [        [           T5      n[        R                  " U5      (       a  U" X5      I S h  vN   T$ U" X5         T$ TbE  [        [        T5      n[        R                  " U5      (       a  U" U 5      I S h  vN   T$ U" U 5        T$  N[ N7f)Nz6Handoff function expected non-null input, but got Nonedetailszinput_json is None)messagedataF)json_strtype_adapterpartial)r   attach_error_to_current_spanr   r   r   validate_jsonr   OnHandoffWithInputr   inspectiscoroutinefunctionOnHandoffWithoutInput)	ctx
input_jsonvalidated_input
input_funcno_input_funcr!   r'   r&   r/   s	        r"   _invoke_handoff)realtime_handoff.<locals>._invoke_handoffo   s     !l&>!;; X')=> ))abb#11#)O
 0?LJ**:66 666  30  # !6
CM**=99#C(((  c" 7 )s%   BC+C'A
C+C)C+)C+c                   >#    [        T5      (       d   S5       e[        U[        5      (       d   S5       eT" X5      n[        R                  " U5      (       a
  UI S h  vN $ U$  N7f)Nz is_enabled must be non-null herez$Can't handoff to a non-RealtimeAgent)callable
isinstancer   r4   isawaitable)r7   
agent_baseresultr   s      r"   _is_enabled%realtime_handoff.<locals>._is_enabled   sc     
##G%GG#*m44\6\\4C,v&&<  s   AA(A& A()	tool_nametool_descriptioninput_json_schemaon_invoke_handoffinput_filter
agent_namer   r   )r7   RunContextWrapper[Any]r8   
str | NonereturnRealtimeAgent[TContext])r7   rL   rB   zAgentBase[Any]rN   bool)r?   r4   	signaturelen
parametersr   r	   json_schemar   default_tool_namedefault_tool_descriptionr   name)r!   r   r   r&   r'   r   sigrH   r<   rF   rG   rD   r/   s   `  ```      @r"   r#   r#   B   sm   2 :zj LI 
##B%BB#
+s~~!#STT":.(446!##J/C3>>"a' LMM ?C#1;	  @ #Fg&?&?&FI0[G4T4TUZ4[ 22CD )+)::"*:"6"6;  =G r$   )
r!   rO   r   rM   r   rM   r   Sbool | Callable[[RunContextWrapper[Any], RealtimeAgent[Any]], MaybeAwaitable[bool]]rN   *Handoff[TContext, RealtimeAgent[TContext]])r!   rO   r&   z!OnHandoffWithInput[THandoffInput]r'   ztype[THandoffInput]r   rM   r   rM   r   rY   rN   rZ   )r!   rO   r&   r6   r   rM   r   rM   r   rY   rN   rZ   )NNNNT)r!   rO   r   rM   r   rM   r&   z@OnHandoffWithInput[THandoffInput] | OnHandoffWithoutInput | Noner'   ztype[THandoffInput] | Noner   rY   rN   rZ   )'
__future__r   r4   collections.abcr   typingr   r   r   r   pydanticr	   typing_extensionsr
   
exceptionsr   r   handoffsr   run_contextr   r   strict_schemar   tracing.spansr   utilr   r   util._typesr    r   r!   r   r   r3   r6   r#   r    r$   r"   <module>rh      s   "  $ 5 5   % 6  5 5 % ( ( ! 505}EsJK  "3C"8!93!>?  
 &*,0UY5"5 #5  *	5
S5 05 
5 
 -1%)UY	5"	5 2	5 $		5
  *	5 #	5S	5 0	5 
	5 

 -1%)UY5"5 &5  *	5
 #5S5 05 
5 &*,0SW-1UYd"d"d  *d Q	d
 +dSd 0dr$   