+
    ~jc                    4   ^ RI Ht ^ RIt^ RIt^ RIt^ RIHtHtHtH	t	 ^ RI
Ht ^ RIHtHtHtHtHt ^ RIHt ^RIHtHtHtHtHtHtHt ^RIHtHtHtHt ^R	I H!t!H"t" ^R
I#H$t$ ^RI%H&t&H't'H(t( ^RIH)t)H*t* ^RI+H,t, ^RI-H.t. ^RI/H0t0H1t1 ]'       d)   ^RIH2t2H3t3H4t4 ^RIH5t5 ^RI6H7t7 ^RI8H9t9 ^RI:H;t; ^RI/H<t< ] ! R R4      4       t= ! R R4      t>]! R4      t? ! R R]>]]?,          4      t@] ! R R4      4       tAR]&R ]&R!]&/R" R# lltBR$ R% ltCR& R' ltDR# )(    )annotationsN)AsyncGeneratorAsyncIterable	Coroutine	Generator)	dataclass)TYPE_CHECKINGAnyGenericLiteralTypeVar)rtc)	inferencellmstttokenizettsutilsvad)ChatContextRealtimeModel	ToolErrorfind_function_tools)Instructions_ReadOnlyChatContextlogger)	NOT_GIVENFlushSentinel
NotGivenOr)is_givenmisc)UserTurnExceededEvent)SpeechHandle)TurnHandlingOptions_migrate_turn_handling)	LLMModels	STTModels	TTSModels)mcp)AgentActivity)AgentSession)TimedString)TurnDetectionModec                  &    ] tR t^t$ ]tR]R&   RtR# )ModelSettingszNotGivenOr[llm.ToolChoice]tool_choice N)__name__
__module____qualname____firstlineno__r   r1   __annotations____static_attributes__r2       o/Users/mitch_tango/dev/rabbit-r1-livekit/agent/.venv/lib/python3.14/site-packages/livekit/agents/voice/agent.pyr0   r0      s    .7K+76r9   r0   c                     ] tR t^%tRRR]RRR]R]R]R]R	]R
]R]R]R]R]R]R]/R R llt]R R 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 l4       tR R  ltR! R" ltR#R$/R% R& lltR' R( ltR) R* ltR+ R, ltR- R. ltR/ R0 ltR1 R2 ltR3 R4 ltR5 R6 ltR7 R8 ltR9 R: lt ! R; R<4      t]R= R> l4       t]R? R@ l4       t]P:                  RA RB l4       t]RC RD l4       t]RE RF l4       t]RG RH l4       t ]RI RJ l4       t!]RK RL l4       t"]RM RN l4       t#]RO RP l4       t$]RQ RR l4       t%]RS RT l4       t&]RU RV l4       t']RW RX l4       t(RYt)R# )ZAgentidNchat_ctxtoolsr   r   turn_handlingr   r   min_consecutive_speech_delayuse_tts_aligned_transcriptturn_detectionmin_endpointing_delaymax_endpointing_delayallow_interruptionsmcp_serversc          "     \    V ^8  d   QhRRRRRRRRR	R
RRRRRRRRRRRRRRRRRRRRRRRR/# )    instructionsstr | Instructionsr=   z
str | Noner>   z"NotGivenOr[llm.ChatContext | None]r?   #list[llm.Tool | llm.Toolset] | Noner   z,NotGivenOr[stt.STT | STTModels | str | None]r   NotGivenOr[vad.VAD | None]r@   NotGivenOr[TurnHandlingOptions]r   z@NotGivenOr[llm.LLM | llm.RealtimeModel | LLMModels | str | None]r   z,NotGivenOr[tts.TTS | TTSModels | str | None]rA   NotGivenOr[float]rB   NotGivenOr[bool]rC   $NotGivenOr[TurnDetectionMode | None]rD   rE   rF   rG   &NotGivenOr[list[mcp.MCPServer] | None]returnNoner2   )formats   "r:   __annotate__Agent.__annotate__&   s     P4 P4 )P4 	P4
 5P4 3P4 :P4 (P4 7P4 NP4 :P4 '8P4 %5P4 =P4   1!P4"  1#P4$ .%P4& <'P4( 
)P4r9   c               	   T;'       g    . p\        V 4      \        J d	   R V n        M8T;'       g*    \        P                  ! \        V 4      P
                  4      V n        \        V4      '       g   \        VVVVR7      MTpWn        . VO\        V 4      OV n
        V'       d   VP                  V P                  R7      M\        P                  ! 4       V n        VP                  R\         4      V n        \%        V\&        4      '       d    \(        P*                  P-                  V4      p\%        V\&        4      '       d    \(        P.                  P-                  V4      p\%        V	\&        4      '       d    \(        P0                  P-                  V	4      p	WPn        Wn        Wn        W`n        \         V n        \         V n        \        VP                  R\         4      ;p4      '       d+   RV9   d   VR,          V n        RV9   d   VR,          V n        VP                  R/ 4      pWn        Wn         VP                  R\         4      V n!        VP                  R	\         4      V n"        Wpn#        \%        V\H        4      '       d   \K        V4      ^ 8X  d   R
pVV n&        V PL                  '       d   \N        PP                  ! R4       R
V n)        R
# )default_agent)rD   rE   rC   rF   r?   rC   interruptionenabledmodeendpointing	min_delay	max_delayNz}passing MCP servers to AgentSession or Agent is deprecated and will be removed in a future version. Use `MCPToolset` instead.)*typer<   _idr"   camel_to_snake_caser3   r!   r&   _instructionsr   _toolscopyr   empty	_chat_ctxgetr   _turn_detection
isinstancestrr   STTfrom_model_stringLLMTTS_stt_llm_tts_vad_allow_interruptions_interruption_detection_min_consecutive_speech_delay_use_tts_aligned_transcript_min_endpointing_delay_max_endpointing_delay_turn_handlinglistlen_mcp_serversr   warning	_activity)selfrJ   r=   r>   r?   r   r   r@   r   r   rA   rB   rC   rD   rE   rF   rG   raw_interruptionr^   s   &$$$$$$$$$$$$$$$$  r:   __init__Agent.__init__&   s3   * :&DHJJT55d4j6I6IJDH M** #&;&;-$7	  	 *:: 3D 9:=ET[[9;K\K\K^,001A9Mc3--11#6Cc3--11#6Cc3--11#6C				6?!OX$(9(9.)(TT$UU,,,<Y,G)))/?/G,#''r:-I*+E(&1ook9&M#&1ook9&M#+k4((S-=-BK'NNU 04r9   c                   V ^8  d   QhRR/# rI   rS   rl   r2   )rU   s   "r:   rV   rW   y   s      C r9   c                	    V P                   # N)rb   r   s   &r:   r=   Agent.idx   s    xxr9   c                   V ^8  d   QhRR/# r   r2   )rU   s   "r:   rV   rW   }   s      s r9   c                	    V P                   # r   )r=   r   s   &r:   labelAgent.label|   s    wwr9   c                   V ^8  d   QhRR/# )rI   rS   rK   r2   )rU   s   "r:   rV   rW      s     " "0 "r9   c                    V P                   # )zJ
Returns:
    str: The core instructions that guide the agent's behavior.
)rd   r   s   &r:   rJ   Agent.instructions   s     !!!r9   c                   V ^8  d   QhRR/# )rI   rS   list[llm.Tool | llm.Toolset]r2   )rU   s   "r:   rV   rW      s     " "3 "r9   c                6    V P                   P                  4       # )ze
Returns:
    list[llm.Tool | llm.ToolSet]:
        A list of function tools available to the agent.
)re   rf   r   s   &r:   r?   Agent.tools   s     {{!!r9   c                   V ^8  d   QhRR/# )rI   rS   llm.ChatContextr2   )rU   s   "r:   rV   rW      s     
: 
:/ 
:r9   c                @    \        V P                  P                  4      # )z
Provides a read-only view of the agent's current chat context.

Returns:
    llm.ChatContext: A read-only version of the agent's conversation history.

See Also:
    update_chat_ctx: Method to update the internal chat context.
)r   rh   itemsr   s   &r:   r>   Agent.chat_ctx   s     $DNN$8$899r9   c                   V ^8  d   QhRR/# )rI   rS   z&NotGivenOr[Literal['adaptive', 'vad']]r2   )rU   s   "r:   rV   rW      s     , ,(N ,r9   c                	    V P                   # r   )rv   r   s   &r:   interruption_detectionAgent.interruption_detection   s    +++r9   c                    V ^8  d   QhRRRR/# )rI   rJ   rl   rS   rT   r2   )rU   s   "r:   rV   rW      s     ? ?c ?d ?r9   c                   "   V P                   f	   Wn        R# V P                   P                  V4      G Rj  xL
  R#  L5i)aA  
Updates the agent's instructions.

If the agent is running in realtime mode, this method also updates
the instructions for the ongoing realtime session.

Args:
    instructions (str):
        The new instructions to set for the agent.

Raises:
    llm.RealtimeError: If updating the realtime session instructions fails.
N)r   rd   update_instructions)r   rJ   s   &&r:   r   Agent.update_instructions   s2      >>!!-nn00>>>s   5A >A c                    V ^8  d   QhRRRR/# )rI   r?   r   rS   rT   r2   )rU   s   "r:   rV   rW      s     1 1(D 1 1r9   c                  "   . pV F  p\        V\        P                  \        P                  34      '       d   VP	                  V4       KF  \        P
                  P                  V4      ;p'       d   VP	                  V4       K  \        R\        V4       R24      h	  TpV P                  ff   \        V Uu/ uF  q3P                  VbK  	  upP                  4       4      V n        V P                  P                  V P                  R7      V n        R# V P                  P!                  V4      G Rj  xL
  R# u upi  L5i)a]  
Updates the agent's available function tools.

If the agent is running in realtime mode, this method also updates
the tools for the ongoing realtime session.

Args:
    tools (list[llm.Tool | llm.ToolSet]):
        The new list of function tools available to the agent.

Raises:
    llm.RealtimeError: If updating the realtime session tools fails.
zInvalid tool type: z. Expected Tool or ToolSet.NrZ   )rk   r   ToolToolsetappendtool_context_resolve_wrapped_tool	TypeErrorra   r   r|   r=   valuesre   rh   rf   update_tools)r   r?   valid_toolstoolresolved_tools   &&   r:   r   Agent.update_tools   s      57D$3;; 788""4("%"2"2"H"H"NNN""=1"5d4j\A\ ]^^  >>!%@%$%@GGIJDK!^^00t{{0CDNnn))%000	  A 	1s&   A1E4AE:D;A%E4E 5Eexclude_invalid_function_callsTc               $    V ^8  d   QhRRRRRR/# )rI   r>   r   r   boolrS   rT   r2   )rU   s   "r:   rV   rW      s$     
 
'
LP
	
r9   c                  "   V P                   f2   TP                  V'       d   V P                  M\        R7      V n        R# V P                   P                  WR7      G Rj  xL
  R#  L5i)a  
Updates the agent's chat context.

If the agent is running in realtime mode, this method also updates
the chat context for the ongoing realtime session.

Args:
    chat_ctx (llm.ChatContext):
        The new or updated chat context for the agent.
    exclude_invalid_function_calls (bool): Whether to exclude function calls
        and outputs not from the agent's tools.

Raises:
    llm.RealtimeError: If updating the realtime session chat context fails.
NrZ   )r   )r   rf   re   r   rh   update_chat_ctx)r   r>   r   s   &&$r:   r   Agent.update_chat_ctx   sZ     $ >>!%]]%Cdkk + DN nn,, - 
 	
 	
s   !A*=A*!A("A*c                   V ^8  d   QhRR/# rI   rS   rT   r2   )rU   s   "r:   rV   rW      s       r9   c                   "   R# 5i)zCalled when the task is enteredNr2   r   s   &r:   on_enterAgent.on_enter           c                   V ^8  d   QhRR/# r   r2   )rU   s   "r:   rV   rW      s      t r9   c                   "   R# 5i)zCalled when the task is exitedNr2   r   s   &r:   on_exitAgent.on_exit   r   r   c               $    V ^8  d   QhRRRRRR/# )rI   turn_ctxr   new_messagezllm.ChatMessagerS   rT   r2   )rU   s   "r:   rV   rW      s$      '6E	r9   c                   "   R# 5i)zCalled when the user has finished speaking, and the LLM is about to respond

This is a good opportunity to update the chat context or edit the new message before it is
sent to the LLM.
Nr2   )r   r   r   s   &&&r:   on_user_turn_completedAgent.on_user_turn_completed   s
      	r   c                    V ^8  d   QhRRRR/# )rI   evr#   rS   rT   r2   )rU   s   "r:   rV   rW     s     
 
.C 
 
r9   c                t   "   V P                   P                  VP                  RRRR7      G Rj  xL
  R#  L5i)ap  Called when the user turn has exceeded the configured limit.

The user has been speaking for too long without the agent successfully
responding. By default, generates a reply using the current turn's
transcript (previous turns are already in the chat context).

Override to customize (e.g., use session.say() with a canned message,
or skip the interruption entirely).
zThe user has been speaking too long without giving a chance to reply. Politely cut in with a short reply or notice. Keep it short since the user cannot interrupt it.Fnone)
user_inputrJ   rF   r1   N)sessiongenerate_reply
transcript)r   r   s   &&r:   on_user_turn_exceededAgent.on_user_turn_exceeded  s=      ll))}}r !& * 
 	
 	
s   -868c               $    V ^8  d   QhRRRRRR/# )rI   audioAsyncIterable[rtc.AudioFrame]model_settingsr0   rS   z|AsyncIterable[stt.SpeechEvent | str] | Coroutine[Any, Any, AsyncIterable[stt.SpeechEvent | str]] | Coroutine[Any, Any, None]r2   )rU   s   "r:   rV   rW     s+     C C2CDQC	$Cr9   c                B    \         P                  P                  WV4      # )a  
A node in the processing pipeline that transcribes audio frames into speech events.

By default, this node uses a Speech-To-Text (STT) capability from the current agent.
If the STT implementation does not support streaming natively, a VAD (Voice Activity
Detection) mechanism is required to wrap the STT.

You can override this node with your own implementation for more flexibility (e.g.,
custom pre-processing of audio, additional buffering, or alternative STT strategies).

Args:
    audio (AsyncIterable[rtc.AudioFrame]): An asynchronous stream of audio frames.
    model_settings (ModelSettings): Configuration and parameters for model execution.

Yields:
    stt.SpeechEvent: An event containing transcribed text or other STT-related data.
)r<   defaultstt_noder   r   r   s   &&&r:   r   Agent.stt_node  s    0 }}%%d>BBr9   c               (    V ^8  d   QhRRRRRRRR/# )	rI   r>   r   r?   list[llm.Tool]r   r0   rS   zAsyncIterable[llm.ChatChunk | str | FlushSentinel] | Coroutine[Any, Any, AsyncIterable[llm.ChatChunk | str | FlushSentinel]] | Coroutine[Any, Any, str] | Coroutine[Any, Any, llm.ChatChunk] | Coroutine[Any, Any, None]r2   )rU   s   "r:   rV   rW   5  s8      M  M! M  M &	 M	$ Mr9   c                B    \         P                  P                  WW#4      # )a  
A node in the processing pipeline that processes text generation with an LLM.

By default, this node uses the agent's LLM to process the provided context. It may yield
plain text (as `str`) for straightforward text generation, or `llm.ChatChunk` objects that
can include text and optional tool calls. `ChatChunk` is helpful for capturing more complex
outputs such as function calls, usage statistics, or other metadata.

You can override this node to customize how the LLM is used or how tool invocations
and responses are handled.

Args:
    chat_ctx (llm.ChatContext): The context for the LLM (the conversation history).
    tools (list[FunctionTool]): A list of callable tools that the LLM may invoke.
    model_settings (ModelSettings): Configuration and parameters for model execution.

Yields/Returns:
    str: Plain text output from the LLM.
    llm.ChatChunk: An object that can contain both text and optional tool calls.
)r<   r   llm_node)r   r>   r?   r   s   &&&&r:   r   Agent.llm_node5  s    @ }}%%deLLr9   c               $    V ^8  d   QhRRRRRR/# )rI   text AsyncIterable[str | TimedString]r   r0   rS   ztAsyncIterable[str | TimedString] | Coroutine[Any, Any, AsyncIterable[str | TimedString]] | Coroutine[Any, Any, None]r2   )rU   s   "r:   rV   rW   W  s+     L L4LFSL	$Lr9   c                B    \         P                  P                  WV4      # )a  
A node in the processing pipeline that finalizes transcriptions from text segments.

This node can be used to adjust or post-process text coming from an LLM (or any other
source) into a final transcribed form. For instance, you might clean up formatting, fix
punctuation, or perform any other text transformations here.

You can override this node to customize post-processing logic according to your needs.

Args:
    text (AsyncIterable[str | TimedString]): An asynchronous stream of text segments.
    model_settings (ModelSettings): Configuration and parameters for model execution.

Yields:
    str: Finalized or post-processed text segments.
)r<   r   transcription_noder   r   r   s   &&&r:   r   Agent.transcription_nodeW  s    . }}//NKKr9   c               $    V ^8  d   QhRRRRRR/# )rI   r   AsyncIterable[str]r   r0   rS   nAsyncIterable[rtc.AudioFrame] | Coroutine[Any, Any, AsyncIterable[rtc.AudioFrame]] | Coroutine[Any, Any, None]r2   )rU   s   "r:   rV   rW   p  s+     B B&B8EB	$Br9   c                B    \         P                  P                  WV4      # )a  
A node in the processing pipeline that synthesizes audio from text segments.

By default, this node converts incoming text into audio frames using the Text-To-Speech
from the agent.
If the TTS implementation does not support streaming natively, it uses a sentence tokenizer
to split text for incremental synthesis.

You can override this node to provide different text chunking behavior, a custom TTS engine,
or any other specialized processing.

Args:
    text (AsyncIterable[str]): An asynchronous stream of text segments to be synthesized.
    model_settings (ModelSettings): Configuration and parameters for model execution.

Yields:
    rtc.AudioFrame: Audio frames synthesized from the provided text.
)r<   r   tts_noder   s   &&&r:   r   Agent.tts_nodep  s    2 }}%%d.AAr9   c               $    V ^8  d   QhRRRRRR/# )rI   r   r   r   r0   rS   r   r2   )rU   s   "r:   rV   rW     s+     U U2UDQU	$Ur9   c                B    \         P                  P                  WV4      # )zRA node processing the audio from the realtime LLM session before it is played out.)r<   r   realtime_audio_output_noder   s   &&&r:   r    Agent.realtime_audio_output_node  s     }}77^TTr9   c                   V ^8  d   QhRR/# )rI   rS   r+   r2   )rU   s   "r:   rV   rW     s       r9   c                L    V P                   f   \        R4      hV P                   # )z9Get the current activity context for this task (internal)z3no activity context found, the agent is not running)r   RuntimeErrorr   s   &r:   _get_activity_or_raiseAgent._get_activity_or_raise  s"    >>!TUU~~r9   c                      ] tR tRt]R R l4       t]R R l4       t]R R l4       t]R R	 l4       t]R
 R l4       t	Rt
R# )Agent.defaulti  c               (    V ^8  d   QhRRRRRRRR/# )	rI   agentr<   r   r   r   r0   rS   z%AsyncGenerator[stt.SpeechEvent, None]r2   )rU   s   "r:   rV   Agent.default.__annotate__  s2     -	B -	B-	B!>-	BP]-	B2-	Br9   c                 aa
"   V P                  4       pVP                  f   Q R4       hVP                  pVP                  P                  P                  '       gW   VP                  '       g$   \        RVP                  P                   R24      h\        P                  ! WCP                  R7      pVP                  P                  P                  pVP                  VR7      ;_uu_4       GRj  xL
 o
VP                  e/   VP                  P                  e   VP                  P                  MVP                  P                  '       dG   VP                  P                  P                  '       d!   VP                  P                  P                  MFVP                  P                   '       d   VP                  P                   M\"        P"                  ! 4       p\"        P"                  ! 4       V,
          S
n        \&        P(                  ! \*        R7      R VV
3R	 ll4       p\,        P.                  ! V! 4       4      p S
  Rj  xL
  p	V	5x  K   ELb LD \&        P0                  P3                  T4      G Rj  xL 
  M-  \&        P0                  P3                  T4      G Rj  xL 
  i ; iRRR4      GRj  xL 
  R#   + GRj  xL 
 '       g   i     R# ; i5i)
z+Default implementation for `Agent.stt_node`Nz,stt_node called but no STT node is availablez	The STT (z) does not support streaming, add a VAD to the AgentTask/VoiceAgent to enable streamingOr manually wrap your STT in a stt.StreamAdapter)r   r   conn_optionsr   c                   V ^8  d   QhRR/# r   r2   )rU   s   "r:   rV   ,Agent.default.stt_node.<locals>.__annotate__  s     1 1d 1r9   c                 T   <"   S  R j  xL
  p SP                  V 4       K   LDR # 5ir   )
push_frame)framer   streams    r:   _forward_input.Agent.default.stt_node.<locals>._forward_input  s*     ', 1 1e))%01us   (%#%(%()r   r   capabilities	streamingr   r   r   StreamAdapterr   r   stt_conn_optionsr  _audio_recognition_input_started_at_recorder_iorecording_started_at_started_attimestart_time_offsetr   log_exceptionsr   asynciocreate_taskaiocancel_and_wait)r   r   r   activitywrapped_sttr   _audio_input_started_atr  forward_taskeventr  s   &f&       @r:   r   Agent.default.stt_node  s(    
 335H<<+[-[[+",,K<<,,666|||&#HLL$6$6#7 8K K 
 "//K\\R#++88IIL"))|)DDD  22> 33EEQ //AA
 $++888$,,99NNN !((55JJ $++777 &--99!YY[ ( ,099;9P+P(%%V41 1 51  '22>3CDB'- $ $e#1 E.$v  ))33LAAA%))33LAAA5 EDDDDDs   AKK.BK0I1K4AK%K3;K/BK?JII
I		JKIJ"K;I><K#J,%J(&J,,K/K:J=;KK	K	
K	K		Kc          
     ,    V ^8  d   QhRRRRRRRRR	R
/# )rI   r   r<   r>   r   r?   r   r   r0   rS   z9AsyncGenerator[llm.ChatChunk | str | FlushSentinel, None]r2   )rU   s   "r:   rV   r     s;     	  	 	 %	  "	  *		 
 G	 r9   c                 "   V P                  4       pVP                  f   Q R4       h\        VP                  \        P                  4      '       g   Q R4       hV'       d   VP                  M\
        pVP                  pVP                  P                  P                  pVP                  WWWR7      ;_uu_4       GRj  xL
 pV  Rj  xL
  p	V	5x  K   L LDRRR4      GRj  xL 
  R#   + GRj  xL 
 '       g   i     R# ; i5i)z+Default implementation for `Agent.llm_node`Nz,llm_node called but no LLM node is availablezJllm_node should only be used with LLM (non-multimodal/realtime APIs) nodes)r>   r?   r1   r   )
r   r   rk   ro   r1   r   r   r   llm_conn_optionschat)
r   r>   r?   r   r  r1   activity_llmr   r  chunks
   &&&&      r:   r   Agent.default.llm_node  s      335H<<+[-[[+hllCGG44 \4 9G.44IK#<<L#++88IIL#((!K )   #)    %K	 6     sy   AD!AD>C?DC.C	C

C	C.DCC.D&C)'D.D	4C75
D	 D		Dc               (    V ^8  d   QhRRRRRRRR/# )	rI   r   r<   r   r   r   r0   rS   $AsyncGenerator[rtc.AudioFrame, None]r2   )rU   s   "r:   rV   r     s2     !	B !	B!	B 2!	BDQ!	B1!	Br9   c               T  aa	"   V P                  4       pVP                  f   \        R4      hVP                  pVP                  P                  P                  '       g7   \        P
                  ! V\        P                  P                  RR7      R7      pVP                  P                  P                  pVP                  VR7      ;_uu_4       GRj  xL
 o	R V	V3R llp\        P                  ! V! 4       4      p S	  Rj  xL
  pVP                  5x  K   LG LD \         P"                  P%                  T4      G Rj  xL 
  M-  \         P"                  P%                  T4      G Rj  xL 
  i ; iRRR4      GRj  xL 
  R#   + GRj  xL 
 '       g   i     R# ; i5i)	z+Default implementation for `Agent.tts_node`Nz`tts_node` called but no TTS node is available. If audio output is not needed, disable it using `session.output.set_audio_enabled(False)`.T)retain_format)r   sentence_tokenizerr   c                   V ^8  d   QhRR/# r   r2   )rU   s   "r:   rV   ,Agent.default.tts_node.<locals>.__annotate__  s     ' 'd 'r9   c                 t   <"   S  R j  xL
  p SP                  V 4       K   LDSP                  4        R # 5ir   )	push_text	end_input)r!  r  r   s    r:   r  .Agent.default.tts_node.<locals>._forward_input  s8     '+ 0 0e((/0t $$&s   8%#%8%8)r   r   r   r  r  r  r   	blingfireSentenceTokenizerr   r   tts_conn_optionsr  r  r  r  r   r  r  )
r   r   r   r  wrapped_ttsr   r  r  r   r  s
   &f&      @r:   r   Agent.default.tts_node  sC    
 335H||#"A 
 #,,K<<,,666!//#'/'9'9'K'KZ^'K'_
 $++88IIL"))|)DDD' '  '22>3CDB$* ' 'b hh E'F  ))33LAAA%))33LAAA EDDDDDs   AF( A4F(DF(&F?ED D
D 	EF(D  E""FEF#E5.E1/E55F8F(FF(F%	F
F%	F%		F(c               (    V ^8  d   QhRRRRRRRR/# )	rI   r   r<   r   r   r   r0   rS   z'AsyncGenerator[str | TimedString, None]r2   )rU   s   "r:   rV   r   
  s,     	 		 @	R_	4	r9   c               :   "   V  Rj  xL
  pV5x  K   LDR# 5i)z5Default implementation for `Agent.transcription_node`Nr2   )r   r   r   deltas   &&& r:   r    Agent.default.transcription_node	  s"     
  $  ets   	c               (    V ^8  d   QhRRRRRRRR/# )	rI   r   r<   r   r   r   r0   rS   r$  r2   )rU   s   "r:   rV   r     s,     
	 
	
	!>
	P]
	1
	r9   c                  "   V P                  4       pVP                  f   Q R4       hV  Rj  xL
  pV5x  K   LDR# 5i)z=Default implementation for `Agent.realtime_audio_output_node`NzJrealtime_audio_output_node called but no realtime LLM session is available)r   realtime_llm_session)r   r   r   r  r  s   &&&  r:   r   (Agent.default.realtime_audio_output_node  sN     
 335H00< \<  %  eus   (A =;=	A =A r2   N)r3   r4   r5   r6   staticmethodr   r   r   r   r   r8   r2   r9   r:   r   r     sj    	-	B 
-	B^ 
	  
	 . 
!	B 
!	BF 
	 
	 

	 

	r9   r   c                   V ^8  d   QhRR/# )rI   rS   zllm.RealtimeSessionr2   )rU   s   "r:   rV   rW     s     
 
&9 
r9   c                X    V P                  4       P                  ;pf   \        R4      hV# )z
Retrieve the realtime LLM session associated with the current agent.

Raises:
    RuntimeError: If the agent is not running or the realtime LLM session is not available
zno realtime LLM session)r   r9  r   )r   
rt_sessions   & r:   r9  Agent.realtime_llm_session  s0     557LLLJU899r9   c                   V ^8  d   QhRR/# )rI   rS   rQ   r2   )rU   s   "r:   rV   rW   ,  s     
$ 
$ D 
$r9   c                    V P                   # )ad  
Retrieves the turn detection mode for identifying conversational turns.

If this property was not set at Agent creation, but an ``AgentSession`` provides a turn detection,
the session's turn detection mode will be used at runtime instead.

Returns:
    NotGivenOr[TurnDetectionMode | None]: An optional turn detection mode for managing conversation flow.
)rj   r   s   &r:   rC   Agent.turn_detection+  s     ###r9   c                    V ^8  d   QhRRRR/# )rI   valuezTurnDetectionMode | NonerS   rT   r2   )rU   s   "r:   rV   rW   9  s     @ @$< @ @r9   c                	j    Wn         V P                  e   V P                  P                  VR7       R # R # )N)rC   )rj   r   update_options)r   rD  s   &&r:   rC   rB  8  s,    $>>%NN)))? &r9   c                   V ^8  d   QhRR/# )rI   rS   NotGivenOr[stt.STT | None]r2   )rU   s   "r:   rV   rW   @       
 
/ 
r9   c                    V P                   # )a  
Retrieves the Speech-To-Text component for the agent.

If this property was not set at Agent creation, but an ``AgentSession`` provides an STT component,
the session's STT will be used at runtime instead.

Returns:
    NotGivenOr[stt.STT | None]: An optional STT component.
)rq   r   s   &r:   r   	Agent.stt?       yyr9   c                   V ^8  d   QhRR/# )rI   rS   .NotGivenOr[llm.LLM | llm.RealtimeModel | None]r2   )rU   s   "r:   rV   rW   M  s     
 
C 
r9   c                    V P                   # )aO  
Retrieves the Language Model or RealtimeModel used for text generation.

If this property was not set at Agent creation, but an ``AgentSession`` provides an LLM or RealtimeModel,
the session's model will be used at runtime instead.

Returns:
    NotGivenOr[llm.LLM | llm.RealtimeModel | None]: The language model for text generation.
)rr   r   s   &r:   r   	Agent.llmL  rL  r9   c                   V ^8  d   QhRR/# )rI   rS   NotGivenOr[tts.TTS | None]r2   )rU   s   "r:   rV   rW   Z  rI  r9   c                    V P                   # )a.  
Retrieves the Text-To-Speech component for the agent.

If this property was not set at Agent creation, but an ``AgentSession`` provides a TTS component,
the session's TTS will be used at runtime instead.

Returns:
    NotGivenOr[tts.TTS | None]: An optional TTS component for generating audio output.
)rs   r   s   &r:   r   	Agent.ttsY  rL  r9   c                   V ^8  d   QhRR/# )rI   rS   rR   r2   )rU   s   "r:   rV   rW   g  s     
! 
!C 
!r9   c                    V P                   # )a@  
Retrieves the list of Model Context Protocol (MCP) servers providing external tools.

If this property was not set at Agent creation, but an ``AgentSession`` provides MCP servers,
the session's MCP servers will be used at runtime instead.

Returns:
    NotGivenOr[list[mcp.MCPServer]]: An optional list of MCP servers.
)r~   r   s   &r:   rG   Agent.mcp_serversf  s        r9   c                   V ^8  d   QhRR/# )rI   rS   rM   r2   )rU   s   "r:   rV   rW   t  rI  r9   c                    V P                   # )a9  
Retrieves the Voice Activity Detection component for the agent.

If this property was not set at Agent creation, but an ``AgentSession`` provides a VAD component,
the session's VAD will be used at runtime instead.

Returns:
    NotGivenOr[vad.VAD | None]: An optional VAD component for detecting voice activity.
)rt   r   s   &r:   r   	Agent.vads  rL  r9   c                   V ^8  d   QhRR/# rI   rS   rP   r2   )rU   s   "r:   rV   rW     s     
) 
)%5 
)r9   c                    V P                   # )a<  
Indicates whether interruptions (e.g., stopping TTS playback) are allowed.

If this property was not set at Agent creation, but an ``AgentSession`` provides a value for
allowing interruptions, the session's value will be used at runtime instead.

Returns:
    NotGivenOr[bool]: Whether interruptions are permitted.
)ru   r   s   &r:   rF   Agent.allow_interruptions  s     (((r9   c                   V ^8  d   QhRR/# rI   rS   rO   r2   )rU   s   "r:   rV   rW     s     
+ 
+'8 
+r9   c                    V P                   # )u  
Minimum time-in-seconds since the last detected speech before the agent
declares the user’s turn complete. In VAD mode this effectively behaves
like max(VAD silence, min_endpointing_delay); in STT mode it is applied
after the STT end-of-speech signal, so it can be additive with the STT
provider’s endpointing delay.

If this property was set at Agent creation, it will be used at runtime instead of the session's value.
)ry   r   s   &r:   rD   Agent.min_endpointing_delay  s     ***r9   c                   V ^8  d   QhRR/# r`  r2   )rU   s   "r:   rV   rW     s     + +'8 +r9   c                    V P                   # )z
Maximum time-in-seconds the agent will wait before terminating the turn.

If this property was set at Agent creation, it will be used at runtime instead of the session's value.
)rz   r   s   &r:   rE   Agent.max_endpointing_delay  s     ***r9   c                   V ^8  d   QhRR/# r`  r2   )rU   s   "r:   rV   rW     s     
2 
2.? 
2r9   c                    V P                   # )a?  
Retrieves the minimum consecutive speech delay for the agent.

If this property was not set at Agent creation, but an ``AgentSession`` provides a value for
the minimum consecutive speech delay, the session's value will be used at runtime instead.

Returns:
    NotGivenOr[float]: The minimum consecutive speech delay.
)rw   r   s   &r:   rA   "Agent.min_consecutive_speech_delay  s     111r9   c                   V ^8  d   QhRR/# r\  r2   )rU   s   "r:   rV   rW     s     0 0,< 0r9   c                    V P                   # )aZ  
Indicates whether to use TTS-aligned transcript as the input of
the ``transcription_node``.

If this property was not set at Agent creation, but an ``AgentSession`` provides a value for
the use of TTS-aligned transcript, the session's value will be used at runtime instead.

Returns:
    NotGivenOr[bool]: Whether to use TTS-aligned transcript.
)rx   r   s   &r:   rB    Agent.use_tts_aligned_transcript  s     ///r9   c                   V ^8  d   QhRR/# )rI   rS   r,   r2   )rU   s   "r:   rV   rW     s     5 5 5r9   c                6    V P                  4       P                  # )zs
Retrieve the VoiceAgent associated with the current agent.

Raises:
    RuntimeError: If the agent is not running
)r   r   r   s   &r:   r   Agent.session  s     **,444r9   )r   ru   rh   rb   rd   rv   rr   rz   r~   rw   ry   rq   re   rs   rj   r{   rx   rt   )*r3   r4   r5   r6   r   r   propertyr=   r   rJ   r?   r>   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r9  rC   setterr   r   r   rG   r   rF   rD   rE   rA   rB   r   r8   r2   r9   r:   r<   r<   %   s   P4 	P4
 8AP4 6:P4 =FP4 +4P4 :CP4 QZP4 =FP4 ;DP4 8AP4 @IP4  4=!P4" 4=#P4$ 1:%P4& ?H'P4d     " " " " 
: 
: , ,?(1>
SW
@
(C4 MDL2B6U@ @D 
 
 
$ 
$ @ @ 
 
 
 
 
 
 
! 
! 
 
 
) 
) 
+ 
+ + + 
2 
2 0 0 5 5r9   r<   TaskResult_Tc                     a  ] tR tRtR]RRR]R]R]R]R	]R
RR]R]R]R]R]/R V 3R ll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V ;t# ) 	AgentTaski  r>   r?   Nr   r   r@   r   r   preserve_function_call_historyFrC   rF   rD   rE   rG   c               T    V ^8  d   QhRRRRRRRRR	R
RRRRRRRRRRRRRRRRRRRR/# )rI   rJ   rK   r>   zNotGivenOr[llm.ChatContext]r?   rL   r   rH  r   rM   r@   rN   r   rN  r   rR  rt  r   rC   rQ   rF   rP   rD   rO   rE   rG   rR   rS   rT   r2   )rU   s   "r:   rV   AgentTask.__annotate__  s     0- 0- )0- .	0-
 30- (0- (0- 70- <0- (0- )-0- =0- .0-  10-   1!0-" <#0-$ 
%0-r9   c               	n  < T;'       g    . p\        V4      '       g   \        V
VVVR 7      MTp\        SV `  VVVVVVVVVR7	       RV n        \
        P                  \        ,          ! 4       V n        \
        P                  ! 4       V n
        V P                  P                  4        Wn        RV n        R# ))rC   rF   rD   rE   )	rJ   r>   r?   r   r   r   r   rG   r@   FN)r!   r&   superr   _AgentTask__startedr  Futurerq  _AgentTask__futEvent_AgentTask__inactive_evset_preserve_function_call_history
_old_agent)r   rJ   r>   r?   r   r   r@   r   r   rt  rC   rF   rD   rE   rG   	__class__s   &$$$$$$$$$$$$$$r:   r   AgentTask.__init__  s    &  M** #-$7&;&;	  	 	%#' 	 
	
 ^^L13
$]]_ /M,(,r9   c                   V ^8  d   QhRR/# )rI   rS   r   r2   )rU   s   "r:   rV   rv    s     ! !d !r9   c                	6    V P                   P                  4       # r   )r{  doner   s   &r:   r  AgentTask.done  s    zz  r9   c                   V ^8  d   QhRR/# r   r2   )rU   s   "r:   rV   rv    s     F F Fr9   c                	    V P                   '       d   V P                   P                  R R7       V P                  P                  4       '       d   R# V P	                  \        RV P                   R24      4       R# )T)forceNz
AgentTask z is cancelled)r   	interruptr{  r  completer   r=   r   s   &r:   cancelAgentTask.cancel  sR    >>>NN$$4$0::??i*TWWI] CDEr9   c                    V ^8  d   QhRRRR/# )rI   resultzTaskResult_T | ExceptionrS   rT   r2   )rU   s   "r:   rV   rv  	  s     ; ;7 ;D ;r9   c                	   V P                   P                  4       '       d#   \        V P                  P                   R 24      h\        V\        4      '       d   V P                   P                  V4       MV P                   P                  V4       T P                   P                  4        ^RI
Hp VP                  R4      pV'       d	   Wn        R# R# )z is already done)_SpeechHandleContextVarN)r{  r  r   r  r3   rk   	Exceptionset_exception
set_result	exceptionagent_activityr  ri   _maybe_run_final_output)r   r  r  speech_handles   &&  r:   r  AgentTask.complete	  s    ::??$.."9"9!::JKLLfi((JJ$$V,JJ!!&)

;/33D94:1 r9   c                   V ^8  d   QhRR/# )rI   rS   rq  r2   )rU   s   "r:   rV   rv    s     d% d%L d%r9   c           	     	:  a "   S P                   '       d#   \        S P                  P                   R 24      hRS n         \        P
                  ! 4       pVf#   \        S P                  P                   R24      h\        V4      pV'       d   VP                  '       g#   \        S P                  P                   R24      hR V 3R llpVP                  V4       ^RI	H
pHp VP                  R4      pVP                  4       pVP                  pVP                  p	VS n        Rp
V'       dH   VP                   '       d#   \        S P                  P                   R24      hVP"                  p
R	Vn        V.pVP$                  '       dK   VP$                  P'                  4       '       g+   WP$                  Jd   VP)                  VP$                  4       VP*                  '       du   \-        VP.                  \0        4      '       dU   VP.                  P2                  P4                  '       g/   \6        P8                  ! R
VP.                  P:                   R24       S P<                  P?                  4        . pRp V	PA                  S RVR	R7      G Rj  xL
  S PB                  '       g?   S P'                  4       '       g)   S PE                  \G        RS PH                   R24      4       V	PJ                  pS PB                  '       do   S PB                  P$                  ;p'       dQ   V'       d+   VP'                  4       '       g   VPM                  V4       TpM\        PN                  ! V4      G Rj  xL
  V'       d   VP'                  4       '       g}   V'       d)   VPQ                  V4      '       d   VP)                  V4       V F-  pVPQ                  V4      '       g   K  VP)                  V4       K/  	  V'       d   VPS                  R4        \        PN                  ! S PX                  4      G Rj  xL
 T'       d2   \Z        P\                  ! \        4      ;_uu_ 4        Yn        RRR4       T	PJ                  pT'       d1   TP'                  4       '       g   T F  pTPM                  T4       K  	  T'       d     \        PN                  ! T4      G Rj  xL
  T	Pb                  S 8w  dG   \6        Pd                  ! S P                  P                   R24       TPg                  4       G Rj  xL
  MvTPh                  Pk                  S Ph                  S Pl                  '       * RR7      pTPn                  TPp                  Pn                  R&   T	PA                  TRR	R7      G Rj  xL
  S P<                  PW                  4        #  EL/ ELV  \T         d    S P<                  PW                  4        h i ; i EL  + '       g   i     EL; i EL4  \^         d&    \6        P`                  ! RS PH                  4        ELai ; i EL L  T'       dF   \Z        P\                  ! \        4      ;_uu_ 4        Yn        RRR4       M  + '       g   i     M; iT	PJ                  pT'       d1   TP'                  4       '       g   T F  pTPM                  T4       K  	  T'       dT    \        PN                  ! T4      G Rj  xL 
  M2  \^         d%    \6        P`                  ! RS PH                  4        Mi ; iT	Pb                  S 8w  dH   \6        Pd                  ! S P                  P                   R24       TPg                  4       G Rj  xL 
  MwTPh                  Pk                  S Ph                  S Pl                  '       * RR7      pTPn                  TPp                  Pn                  R&   T	PA                  TRR	R7      G Rj  xL 
  S P<                  PW                  4        i ; i5i)z# is not re-entrant, await only onceTNz) must be executed inside an async contextzY should only be awaited inside tool_functions or the on_enter/on_exit methods of an Agentc                    V ^8  d   QhRRRR/# )rI   _asyncio.Task[Any]rS   rT   r2   )rU   s   "r:   rV   ,AgentTask.__await_impl.<locals>.__annotate__0  s     	 	!2 	t 	r9   c                  < SP                   P                  4       '       d   R # \        P                  ! RSP                  P
                   R24       SP                  \        RSP                  P
                   R24      4       R # )Nz!The asyncio.Task finished before z was completed.)r{  r  r   errorr  r3   r  r   )r  r   s   &r:   _handle_task_done1AgentTask.__await_impl.<locals>._handle_task_done0  sj    zz   LL3DNN4K4K3LO\ MM78O8O7PP_`r9   )_AgentActivityContextVarr  zE cannot be awaited inside a function tool that is already interruptedFzRealtime model 'z' does not support resuming function calls from chat context, using AgentTask inside a function tool may have unexpected behavior.pause)previous_activityblocked_taskswait_on_enterzactivity doesn't start for z, likely due to session closingz"error in on_enter task of agent %sz completed, but the agent has changed in the meantime. Ignoring handoff to the previous agent, likely due to `AgentSession.update_agent` being invoked.)exclude_function_callexclude_instructions:NNNresume)new_activityr  )9ry  r   r  r3   r  current_task_get_activity_task_infoinline_taskadd_done_callbackr  r  r  ri   r   r   r  interruptedrF   _on_enter_taskr  r   function_callrk   r   r   r  manual_function_callsr   r  r   r}  clear_update_activityr   r  r   r=   _global_run_state_watch_handleshield_unwatch_handle_mark_done_if_neededr  r~  r{  
contextlibsuppressBaseExceptionr  current_agentr   acloser>   merger  r   rh   )r   r  	task_infor  r  r  r  old_activity	old_agentr   old_allow_interruptionsr  suspended_handlespending_on_enter_task	run_stateon_enter_tasktaskhandlemerged_chat_ctxs   f                  r:   __await_implAgentTask.__await_impl  s    >>>$.."9"9!::]^__++->>**++TU  ,L9		 5 5 5>>**+  ,E  F 	 	  	&&'89U
 033D9/335 &&	&&#"&((("~~..//tu  '4&G&G#05M-%''' //4466$?$??  !<!<= ###<++];; $$11GGGLL"<#3#3#9#9": ;W W 	  "DF;?(	 **}\a +    >>>$))++5dggY>]^  11I~~~DNN4Q4Q#Q=#QY^^%5%5 ++M:,9) "..777
 !1!1 Y%>%>}%M%M%,,];)D 0066)006 * %2248
)	% 

33 ((668O5 7  11I !1!1/F++F3 0 %T!..)>??? $$,~~../ 0w w #))+++"+"4"4":":MM.2.R.R*R)- #; # 0?/D/D	##))!,..HE /    ""$_* 8  	""$	
 4 766 @$ T$$%I477ST ,E ((668O5 7666  11I !1!1/F++F3 0 %T!..)>???$ T$$%I477ST $$,~~../ 0w w #))+++"+"4"4":":MM.2.R.R*R)- #; # 0?/D/D	##))!,..HE /    ""$s  B`B`-`?A	`	`);`%A`+A`8W V?W 'W =AW W !W )W ?-W ,W-W 9W W W .*W W :W #Y /W/0Y 3*`W2$` `!`9X	XX	A`(X<)A6`X? `?W W 'W,,`/Y 2X=	`X		,X95`8X99`?`+`,Y<	3	`<Z`#`9!`[<5[86[<;`<,\+(`*\++A`?^ A7`7_:8 ``c                   V ^8  d   QhRR/# )rI   rS   z#Generator[None, None, TaskResult_T]r2   )rU   s   "r:   rV   rv    s     / /> /r9   c                	>    V P                  4       P                  4       # r   )_AgentTask__await_impl	__await__r   s   &r:   r  AgentTask.__await__  s      ",,..r9   c                   V ^8  d   QhRR/# r   r2   )rU   s   "r:   rV   rv    s     ( ($ (r9   c                	V   "   V P                   P                  4       G R j  xL
  R #  L5ir   )r}  waitr   s   &r:   _wait_for_inactiveAgentTask._wait_for_inactive  s       %%'''s   )'))__fut__inactive_ev	__startedr  r  )r3   r4   r5   r6   r   r   r  r  r  r  r  r  r8   __classcell__)r  s   @r:   rs  rs    s    0- 1:	0-
 6:0- +40- +40- :C0- ?H0- +40- 050- @I0- 1:0- 4=0-  4=!0-" ?H#0- 0-d!F;*d%L/( (r9   rs  c                  B    ] tR tRt$ RtR]R&   RtR]R&   RtR]R	&   R
tR# )_ActivityTaskInfoi  Nzllm.FunctionCall | Noner  zSpeechHandle | Noner  Fr   r  r2   )	r3   r4   r5   r6   r  r7   r  r  r8   r2   r9   r:   r  r    s"    -1M*1)-M&-Kr9   r  r  r  r  c          
     ,    V ^8  d   QhRRRRRRRRR	R
/# )rI   r  r  r  z#NotGivenOr[llm.FunctionCall | None]r  zNotGivenOr[SpeechHandle | None]r  rP   rS   rT   r2   )rU   s   "r:   rV   rV     s<     : :
: 7: 3	:
 ": 
:r9   c                   \        V 4      ;'       g    \        4       p\        V4      '       d   Wn        \        V4      '       d   W$n        \        V4      '       d   W4n        \        V R V4       R# __livekit_agents_activity_taskN)r  r  r!   r  r  r  setattr)r  r  r  r  infos   &$$$ r:   _set_activity_task_infor    sZ     #4(??,=,?D**&D2D9r9   c                    V ^8  d   QhRRRR/# )rI   r  r  rS   z_ActivityTaskInfo | Noner2   )rU   s   "r:   rV   rV     s      A A"3 A8P Ar9   c                    \        V R R4      # r  )getattr)r  s   &r:   r  r    s    494@@r9   c                    V ^8  d   QhRRRR/# )rI   r  r  rS   rT   r2   )rU   s   "r:   rV   rV     s     > >+< > >r9   c                    \         P                  ! 4       pV'       d%   \        V4      ;p'       d   \        V R V4       R# R# R# r  )r  r  r  r  )r  r  r  s   &  r:    _pass_through_activity_task_infor    s8    '')L!8!FFF6= G|r9   )E
__future__r   r  r  r  collections.abcr   r   r   r   dataclassesr   typingr	   r
   r   r   r   livekitr    r   r   r   r   r   r   r   r   r   r   r   llm.chat_contextr   r   logr   typesr   r   r    r!   r"   eventsr#   r  r$   turnr%   r&   r'   r(   r)   r*   r  r+   agent_sessionr,   ior-   r.   r0   r<   rq  rs  r  r  r  r  r2   r9   r:   <module>r     s    "    O O ! @ @  = = = L L A  8 8 " ) ' =;;-+' 7 7 7
a
5 a
5H ~&|(w|, |(~   : :C: 6?	:
 %.:*A>r9   