+
    ~jA                    P   ^ RI Ht ^ RIt^ RIHt ^ RIHt ^ RIHtH	t	H
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 ^ R	IHt ^ R
IHtHtHtHt ^ RIHt ^RIH t  ^RI!H"t" Rt#R R lt$] ! R R4      4       t% ! R R]PL                  4      t& ! R R]PN                  4      t'R# )    )annotationsN)	Awaitable)	dataclass)AnyLiteralcast)APIConnectionErrorAPIStatusErrorAPITimeoutErrorllm)
ToolChoice)ChatContext)Tool)DEFAULT_API_CONNECT_OPTIONS	NOT_GIVENAPIConnectOptions
NotGivenOr)is_given)
ChatModels)CACHE_CONTROL_EPHEMERALc                    V ^8  d   QhRRRR/# )   modelstrreturnbool )formats   "r/Users/mitch_tango/dev/rabbit-r1-livekit/agent/.venv/lib/python3.14/site-packages/livekit/plugins/anthropic/llm.py__annotate__r    ,   s     B B3 B4 B    c                   a  \         ;QJ d#    V 3R l\         4       F  '       g   K   R# 	  R# ! V 3R l\         4       4      # )zGReturn True if the model does not support assistant message prefilling.c              3  F   <"   T F  pSP                  V4      x  K  	  R # 5iN)
startswith).0pr   s   & r   	<genexpr>*_model_disables_prefill.<locals>.<genexpr>.   s!     A,@qu"",@s   !TF)any_NO_PREFILL_PATTERNS)r   s   fr   _model_disables_prefillr,   ,   s.    3A,@A33A3A3A,@AAAr!   c                  r    ] tR t^1t$ R]R&   R]R&   R]R&   R]R&   R	]R
&   R]R&   R]R&   R]R&   R]R&   RtR# )_LLMOptionsstr | ChatModelsr   NotGivenOr[str]userNotGivenOr[float]temperatureNotGivenOr[bool]parallel_tool_callsNotGivenOr[ToolChoice]tool_choice NotGivenOr[Literal['ephemeral']]cachingNotGivenOr[int]top_k
max_tokensr   strict_tool_schemar   N)__name__
__module____qualname____firstlineno____annotations____static_attributes__r   r!   r   r.   r.   1   s;    
""))''--[r!   r.   c                     a  ] tR t^?tR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4       t]R R l4       tRRR]	R]R]R]/R R llt
RtV ;t# )LLMr   claude-sonnet-4-6api_keybase_urlr1   clientNr;   r<   r3   r5   r7   r9   timeout_strict_tool_schemaTc               P    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/   rG   r0   rH   r1   rI   zanthropic.AsyncClient | Noner;   r:   r<   r3   r2   r5   r4   r7   r6   r9   r8   rJ   zNotGivenOr[httpx.Timeout]rK   r   r   Noner   )r   s   "r   r    LLM.__annotate__@   s     H
 H
  H
 !	H

 "H
 H
 -H
 H
 $H
 'H
 .H
 ,H
 2H
 +H
 "H
  
!H
r!   c                 < \         SV `  4        \        VVVV	V
VVVVR7	      V n        \	        V4      '       d   TM\
        P                  P                  R4      pV'       g   \        R4      hT;'       g{    \        P                  ! T\	        V4      '       d   TMR\        P                  ! T;'       g    \        P                  ! RRR7      R\        P                  ! R	^d^xR
7      R7      R7      V n        R# )u  
Create a new instance of Anthropic LLM.

``api_key`` must be set to your Anthropic API key, either using the argument or by setting
the ``ANTHROPIC_API_KEY`` environmental variable.

model (str | ChatModels): The model to use. Defaults to "claude-sonnet-4-6".
api_key (str, optional): The Anthropic API key. Defaults to the ANTHROPIC_API_KEY environment variable.
base_url (str, optional): The base URL for the Anthropic API. Defaults to None.
user (str, optional): The user for the Anthropic API. Defaults to None.
client (anthropic.AsyncClient | None): The Anthropic client to use. Defaults to None.
timeout (httpx.Timeout | None): HTTP timeout configuration for the underlying httpx client.
    Defaults to ``httpx.Timeout(5.0, read=30.0)``, which keeps a tight connect timeout
    while allowing up to 30 s between streamed chunks — long enough for Claude's
    adaptive-thinking phases without masking genuine network stalls.
    Pass a custom ``httpx.Timeout`` to override (e.g. ``httpx.Timeout(5.0, read=60.0)``
    for very large contexts or extended thinking budgets).
temperature (float, optional): The temperature for the Anthropic API. Defaults to None.
parallel_tool_calls (bool, optional): Whether to parallelize tool calls. Defaults to None.
tool_choice (ToolChoice, optional): The tool choice for the Anthropic API. Defaults to "auto".
caching (Literal["ephemeral"], optional): If set to "ephemeral", caching will be enabled for the system prompt, tools, and chat history.
)	r   r1   r3   r5   r7   r9   r;   r<   r=   ANTHROPIC_API_KEYz_Anthropic API key is required, either as argument or set ANTHROPIC_API_KEY environment variableNg      @g      >@)readTi  )max_connectionsmax_keepalive_connectionskeepalive_expiry)rJ   follow_redirectslimits)rG   rH   http_client)super__init__r.   _optsr   osenvironget
ValueError	anthropicAsyncClienthttpxTimeoutLimits_client)selfr   rG   rH   r1   rI   r;   r<   r3   r5   r7   r9   rJ   rK   anthropic_api_key	__class__s   &$$$$$$$$$$$$$ r   rY   LLM.__init__@   s    P 	 # 3#!2


 (0'8'8GbjjnnM`>a : 
  
 
!6!6%!)(!3!3X))@@5==4#@!%||$(.1%("
r!   c                   V ^8  d   QhRR/# r   r   r   r   )r   s   "r   r    rN      s        s  r!   c                	.    V P                   P                  # r$   )rZ   r   re   s   &r   r   	LLM.model   s    zzr!   c                   V ^8  d   QhRR/# rj   r   )r   s   "r   r    rN      s     = =# =r!   c                	`    V P                   P                  P                  P                  R 4      # )zutf-8)rd   	_base_urlnetlocdecoderl   s   &r   providerLLM.provider   s#    ||%%,,33G<<r!   toolsconn_optionsextra_kwargsc               4    V ^8  d   QhRRRRRRRRR	R
RRRR/# )r   chat_ctxr   ru   zlist[Tool] | Nonerv   r   r5   r4   r7   r6   rw   zNotGivenOr[dict[str, Any]]r   	LLMStreamr   )r   s   "r   r    rN      s[     }
 }
 }
 !	}

 (}
 .}
 ,}
 1}
 
}
r!   c               	
   / p\        V4      '       d   VP                  V4       \        V P                  P                  4      '       d   V P                  P                  VR &   \        V P                  P                  4      '       d   V P                  P                  VR&   \        V P                  P
                  4      '       d   V P                  P
                  VR&   \        V P                  P                  4      '       d   V P                  P                  MRVR&   RpV'       Ed   ^RIHp	 \        P                  ! V4      p
V
P                  RV P                  P                  R7      pV
P                   FU  p\        W4      '       g   K  VP                  VP!                  4       4       VP"                  '       g   KI  VP"                  pKW  	  WR	&   \        V4      '       d   TMV P                  P$                  p\        V4      '       d   R
R/p\        V\&        4      '       d,   VP)                  R
4      R8X  d   R
RRVR,          R,          /pM0\        V\*        4      '       d   VR8X  d   R
R/pMVR8X  d   . VR	&   RpVeI   \        V4      '       d   TMV P                  P,                  p\        V4      '       d   V'       * VR&   WR&   \/        V P                  P0                  4      pVP3                  RVR7      w  pp\5        \6        \8        P:                  P<                  ,          V4      pVP>                  '       d?   VP>                   Uu. uF$  p\8        P:                  PA                  VRR7      NK&  	  upVR&   V P                  PB                  R8X  d   VP)                  R4      '       d   \D        VR,          R%,          R&   VP)                  R	4      '       d   \D        VR	,          R%,          R&   Rp\G        V4       F{  pVR,          R8X  d.   VR,          ;p'       d   V'       g   \D        VR%,          R&   RpK>  VR,          R 8X  g   KN  VR,          ;p'       g   Ka  V'       g   Kk  \D        VR%,          R&    M	  V'       d[   V PH                  PJ                  PL                  PN                  ! R&RV.R VR!V P                  P0                  R"RR#VPP                  /VB pMLV PH                  PL                  PN                  ! R&R VR!V P                  P0                  R"RR#VPP                  /VB p\S        T TTT;'       g    . VR$7      # u upi )'r1   r3   r;   i   r<   N)AnthropicToolr_   )strictru   typeautofunctiontoolnamerequiredr*   nonedisable_parallel_tool_user7   )r   inject_trailing_user_messagetext)r   r~   system	ephemeralcache_controlFrole	assistantcontentTbetasmessagesr   streamrJ   )anthropic_streamry   ru   rv   r   )*r   updaterZ   r1   r3   r;   r<   ru   r|   r   ToolContextparse_function_toolsr=   provider_tools
isinstanceappendto_dict	beta_flagr7   dictr]   r   r5   r,   r   to_provider_formatr   listr_   typesMessageParamsystem_messagesTextBlockParamr9   r   reversedrd   betar   createrJ   rz   )re   ry   ru   rv   r5   r7   rw   extrar   r|   tool_ctxtool_schemasr   anthropic_tool_choiceinject_trailinganthropic_ctx
extra_datar   r   seen_assistantmsgr   s   &$$$$$$               r   chatLLM.chat   s    L!!LL&DJJOO$$ JJOOE&MDJJ**++#'::#9#9E- DJJ$$%%!ZZ--E'N7?

@U@U7V7Vdjj33\`l $	5,u-H#88DJJ$A$A 9 L !//d22 ''7~~~$(NN		 0 *'N)1+)>)>+DJJDZDZK$$@F?O%k400[__V5LPZ5ZJ 7 ?-)  S11"j017-$.)+g04-(4 $$788 ,!ZZ;; (
   344QdMd-.IJ+@-( 2$**2B2BC$,$?$?_ %@ %
!z Y__99:MJ%%%  *999G ..G&.I9E(O ::,yy""7Nh#O4yy!!6Mgr"?3"N)K;.$'	N22*3JGBK0%)N[F*3y>0I0I0I~~3JGBK0 * \\&&//66  k! jj&& 	
 %,, F \\**11 !jj&&  %,,	
 F #++2%
 	
[s   *U)rd   rZ   )r>   r?   r@   rA   r   rY   propertyr   rs   r   r   rC   __classcell__rg   s   @r   rE   rE   ?   s   H
 #6H
 $-	H

 %.H
 !*H
 04H
 "+H
 '0H
 *3H
 1:H
 /8H
 5>H
 .7H
 %)H
 H
T     = =}
 $(	}

 +F}
 1:}
 /8}
 4=}
 }
r!   rE   c                  F   a  ] tR tRtR V 3R lltR R ltR R ltRtV ;t# )	rz   i  c               0    V ^8  d   QhRRRRRRRRR	R
RR/# )r   r   rE   r   zGAwaitable[anthropic.AsyncStream[anthropic.types.RawMessageStreamEvent]]ry   zllm.ChatContextru   z
list[Tool]rv   r   r   rM   r   )r   s   "r   r    LLMStream.__annotate__  sG          b	 
 "    (  
 r!   c               	   < \         SV `  WWER 7       W n        RV n        RV n        RV n        RV n        RV n        RV n        ^ V n	        ^ V n
        ^ V n        ^ V n        R# ))ry   ru   rv   N F)rX   rY   _awaitable_anthropic_stream_anthropic_stream_tool_call_id	_fnc_name_fnc_raw_arguments_request_id_ignoring_cot_input_tokens_cache_creation_tokens_cache_read_tokens_output_tokens)re   r   r   ry   ru   rv   rg   s   &&$$$$r   rY   LLMStream.__init__  ss     	uX+;(  	
 *.%).2 ""&'#"#r!   c                   V ^8  d   QhRR/# )r   r   rM   r   )r   s   "r   r    r   .  s     (A (AD (Ar!   c                	2  "   R p V P                   '       g   V P                  G Rj  xL
 V n         V P                   ;_uu_4       GRj  xL
 pV  Rj  xL
  pV P                  V4      pVf   K!  V P                  P	                  V4       RpK@   Lh LH L?D@T P
                  T P                  ,           T P                  ,           pT P                  P	                  \        P                  ! T P                  \        P                  ! T P                  TYPP                  ,           T P                  T P                  T P                  R7      R7      4       RRR4      GRj  xL 
  R#   + GRj  xL 
 '       g   i     R# ; i  \        P                   d   p\        TR7      ThRp?i\        P                   d>   p\        TP                   TP"                  TP$                  TP&                  R7      ThRp?i\(         d   p\+        TR7      ThRp?ii ; i5i)TNF)completion_tokensprompt_tokenstotal_tokensprompt_cached_tokenscache_creation_tokenscache_read_tokens)idusage)	retryable)status_code
request_idbody)r   r   _parse_event	_event_chsend_nowaitr   r   r   r   	ChatChunkr   CompletionUsager   r_   r   r
   messager   r   r   	Exceptionr	   )re   r   r   event
chat_chunkprompt_tokenes   &      r   _runLLMStream._run.  s    	&	A)))/3/O/O)O&----#) * *%!%!2!25!9J!-22:>$)	 *P-*6 &&)D)DDtG^G^^  **MM++!11.2.A.A*6)58K8K)K151H1H262M2M.2.E.E
 .-----0 (( 	>!I6A='' 	 		MM<<VV	
   	A$y9q@	As   H!F B!F 	B
F E%BB
BE%1E%F F BB<E%F E F #H%E?	+E.,
E?	7E?	9F =H?F HF$$H;H<8G44HHHHHc                    V ^8  d   QhRRRR/# )r   r   z%anthropic.types.RawMessageStreamEventr   zllm.ChatChunk | Noner   )r   s   "r   r    r   X  s     = ="G =L` =r!   c                	   VP                   R 8X  d   VP                  P                  V n        VP                  P                  P
                  V n        VP                  P                  P                  V n        VP                  P                  P                  '       d&   VP                  P                  P                  V n
        VP                  P                  P                  '       d&   VP                  P                  P                  V n        R# VP                   R8X  d0   V ;P                  VP                  P                  ,          un        R# VP                   R8X  d[   VP                  P                   R8X  d>   VP                  P                  V n        VP                  P                  V n        RV n        R# VP                   R8X  Ed!   VP$                  pVP                   R8X  d   VP&                  pV P(                  eX   VP+                  R4      '       d	   R	V n        M8V P,                  '       d'   R
V9   d    VP/                  R
4      R,          pRV n        V P,                  '       d   R# \0        P2                  ! V P                  \0        P4                  ! VRR7      R7      # VP                   R8X  d4   V P"                  f   Q hV ;P"                  VP6                  ,          un        R# VP                   R8X  d   V P                  e   V P                   f   Q hV P"                  f   Q h\0        P2                  ! V P                  \0        P4                  ! R\0        P8                  ! V P"                  ;'       g    RV P                   ;'       g    RV P                  ;'       g    RR7      .R7      R7      pR;V n        ;V n        V n        V# R# )message_startmessage_deltacontent_block_starttool_user   content_block_delta
text_deltaNz
<thinking>Tz</thinking>Fr   )r   r   )r   deltainput_json_deltacontent_block_stop)	argumentsr   call_id)r   
tool_callsr   )r~   r   r   r   r   input_tokensr   output_tokensr   cache_creation_input_tokensr   cache_read_input_tokensr   content_blockr   r   r   r   r   r   _toolsr%   r   splitr   r   ChoiceDeltapartial_jsonFunctionToolCall)re   r   r   r   r   s   &&   r   r   LLMStream._parse_eventX  s   ::($}}//D!&!4!4!A!AD"'--"5"5"C"CD}}"">>>.3mm.A.A.].]+}}"":::*/--*=*=*U*U'j i ZZ?*5;;#<#<<f e ZZ00""'':5%*%8%8%;%;"!&!4!4!9!9*,'\ [ ZZ00KKEzz\)zz;;*|44-1*+++0E#zz-8<-2*%%%}}''//$[I  11..:::''5+=+=='. + ZZ//!!-~~111..::: ]]''//(00*.*A*A*G*GR%)^^%9%9r(,(:(:(@(@b$	
 QUT"TT%<t~!!r!   )r   r   r   r   r   r   r   r   r   r   r   )	r>   r?   r@   rA   rY   r   r   rC   r   r   s   @r   rz   rz     s       6(AT= =r!   rz   )rF   zclaude-opus-4-6)(
__future__r   r[   collections.abcr   dataclassesr   typingr   r   r   ra   r_   livekit.agentsr	   r
   r   r   livekit.agents.llmr   livekit.agents.llm.chat_contextr   livekit.agents.llm.tool_contextr   livekit.agents.typesr   r   r   r   livekit.agents.utilsr   modelsr   utilsr   r+   r,   r.   rE   rz   r   r!   r   <module>r     s    # 	 % ! % %   S S ) 7 0  *  * @ B
 
\ 
\ 
\P
#'' P
fC Cr!   