ó
    ±"³j÷© ã                  ó  • % S SK Jr  S SKrS SKrS SKrS SKrS SKrS SKrS SK	J
r
JrJrJrJrJrJr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  S SKJr  S S	KJrJrJrJ r J!r!J"r"J#r#J$r$  S S
K%J&r&  S SK'r'S SK(J)r)  S SK*J+r+  S SK,J-r-  S SK.J/r/J0r0J1r1  S SK2J3r3  S SK4J5r5  S SK6J7r7  SSK8J9r9J:r:J;r;J<r<J=r=J>r>J?r?J@rAJBrBJCrDJErEJFrG  SSK9JHrHJIrIJJrJJKrKJLrLJMrM  SSKNJOrOJPrPJQrQJRrR  SSKSJTrT  SSK<JUrU  SSK=JVrV  SSKWJXrXJYrY  SSKZJ[r[  SSK\J]r]  SSK^J_r_J`r`JaraJbrbJcrcJdrdJerf  SSKgJhrh  SSKiJjrj  SSKkJlrl  SS KmJnrnJoroJprpJqrqJrrr  SS!KsJtrt  SS"KuJvrvJwrwJxrx  SS#KyJzr{  SS$K|J}r}J~r~  SS%KJ€r€  SS&K�J‚r‚  SS'KƒJ„r„J…r…J†r†  SS(K‡Jˆrˆ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“J”r”J•r•J–r–J—r—J˜r˜J™r™JšršJ›r›JœrœJ�r�JžržJŸrŸJ r J¡r¡J¢r¢J£r£J¤r¤  SS-K¥J¦r¦J§r§  SS.K¨J©r©Jªrª  SS/K«J¬r¬  SS0K­J®r®  SS1K¯J°r°  SS2K±J²r²  SS3K³J´r´  SS4KµJ¶r¶  S5S6K·J¸r¸J¹r¹JºrºJ»r»J¼r¼J½r½J¾r¾J¿r¿JÀrÀJÁrÁJÂrÂ  S5S7KÃJÄrÄJÅrÅ  S5S8KÆJÇrÇ  \(       a,  S S9KÈJÉrÉ  S S:KÊJËrËJÌrÌ  SS;K8JÍrÎ  SS<KÏJÐrÐJÑrÑJÒrÒJÓrÓJÔrÔJÕrÕJÖrÖ  SS=K×JØrØ  S>rÙ\GR´                  " S?S@9 " SA SB5      5       rÛ\GR´                  " S?S@9 " SC SD5      5       rÜ\SSSSE.               SrSF jj5       rÝSsSG jrÞStSH jrßS5SI.SuSJ jjràSvSK jrá\1" SL5      râ\1" SM5      rã\1" SN5      rä\1" SO5      rå\æ" S5      rç\GR´                   " SP SQ5      5       rè\GR´                  " SRSS9 " ST SU\¸\“\„4   5      5       ré\GR´                   " SV SW5      5       rê\GR´                   " SX SY\ \ä\å4   5      5       rë      SwSZ jrìSxS[ jríS\rîS]\ïS^'    \f\l4rðS_\ïS`'    SySa jrñ " Sb Sc\"5      ròSzSd jróS{Se jrôS|Sf jrõS}Sg jrö\GR´                   " Sh Si\ \“   5      5       r÷SSj.       S~Sk jjrøSSl jrùS€Sm jrú      S�Sn jrû        S‚So jrü\GR´                  " SRSS9 " Sp Sq\´\“   5      5       rýg)ƒé    )ÚannotationsN)ÚAsyncGeneratorÚAsyncIterableÚAsyncIteratorÚ	AwaitableÚCallableÚ
CollectionÚ	GeneratorÚSequence)ÚAbstractAsyncContextManagerÚAsyncExitStackÚasynccontextmanagerÚcontextmanager)Ú
ContextVar)Úcopy)Úreplace)ÚPath)ÚTYPE_CHECKINGÚAnyÚClassVarÚGenericÚLiteralÚ
NamedTupleÚcastÚoverload)Úuuid4)Ú
NoOpTracer)Úto_snake)ÚGenerateJsonSchema)ÚSelfÚTypeIsÚTypeVar)ÚDEFAULT_INSTRUMENTATION_VERSION)Úload_from_registry)ÚDeferredCapabilityLoaderé   )Ú_agent_graphÚ_displayÚ_enqueueÚ_instructionsÚ_outputÚ_system_promptÚ_utilsÚconcurrencyÚ
exceptionsÚmessagesÚmodelsÚusage)ÚCallToolsNodeÚEndStrategyÚModelRequestNodeÚUserPromptNodeÚbuild_run_contextÚcapture_run_messages)ÚCancellationTokenÚ
RunBindingÚRunCancellationÚtake_run_binding)Ú registered_loaded_capability_ids)ÚAgentInstructions)ÚOutputToolset)Údispatch_event_streamÚset_current_run_context)Úvalidate_from_spec_args)ÚPydanticAIDeprecationWarning)ÚAbstractCapabilityÚAgentCapabilityÚ
AgentModelÚCombinedCapabilityÚModelSelectionÚModelSelectorÚ
ToolSearch)Úwrap_capability_funcs)Úhas_capability_type)ÚPendingMessageDrainCapability)Ú_combine_duplicate_capabilitiesÚ_declares_default_idÚ_reject_class_crossing_idÚ_repeated_id_messageÚleaf_capabilities)Úbind_capabilities_tier)ÚEventTÚHooksÚOnEventHookFunc)ÚInstrumentation)ÚInstrumentationSettingsÚInstrumentedModel)ÚAbstractNativeTool)ÚToolSearchTool)ÚOutputDataTÚ
OutputSpecÚStructuredDict)ÚAgentRunÚAgentRunResult)ÚModelSettingsÚmerge_model_settings)ÚTemplateStr)ÚParallelExecutionModeÚToolManager)Ú
AgentDepsTÚAgentNativeToolÚArgsValidatorFuncÚDeferredToolResultsÚDocstringFormatÚGenerateToolJsonSchemaÚNativeToolFuncÚ
RunContextÚSystemPromptFuncÚToolÚToolDefinitionÚ
ToolDeniedÚToolFuncContextÚToolFuncEitherÚToolFuncPlainÚ
ToolParamsÚToolPrepareFuncÚToolsPrepareFunc)ÚAbstractToolsetÚAgentToolset)ÚDynamicToolsetÚToolsetFunc)Úcollect_toolset_instructions)Úparse_discovered_tools©ÚAGENT_TOOLSET_ID)ÚCombinedToolset)ÚFunctionToolset)ÚPreparedToolseté   )ÚAbstractAgentÚAgentMetadataÚAgentModelSettingsÚAgentRealtimeÚAgentRetriesÚAgentRunEventsÚEventStreamHandlerÚEventStreamProcessorÚRunOutputDataTÚ_RealtimeSessionLifecycleÚ_RealtimeSessionResolution)Ú	AgentSpecÚget_capability_registry)ÚWrapperAgent)Ú	Starlette)ÚGraphÚGraphRunContext©Úresult)ÚAudioRetentionÚKnownRealtimeModelNameÚRealtimeEventÚRealtimeModelÚRealtimeModelSettingsÚRealtimeProviderSessionÚRealtimeSession)ÚModelsParam)r„   ÚAgentr†   r‡   rˆ   r_   r‰   r`   rl   r3   r4   rŠ   r‹   rX   r5   rd   r6   r‘   r8   rC   rw   rq   r™   T)Úfrozenc                  ó.   • \ rS rSr% SrS\S'   S\S'   Srg)Ú_ResolvedAgentRetrieséÀ   z-Fully resolved retry budgets used internally.ÚintÚtoolsÚoutput© N©Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__Ú__annotations__Ú__static_attributes__r§   ó    ÚW/home/mande/repo/quber/.venv/lib/python3.13/site-packages/pydantic_ai/agent/__init__.pyr¢   r¢   À   s   ‡ á7àƒJØ†Kr°   r¢   c                  ó    • \ rS rSr% S\S'   Srg)Ú_RunLifecycleéÈ   ÚboolÚshort_circuitedr§   N)r©   rª   r«   r¬   r®   r¯   r§   r°   r±   r³   r³   È   s   ‡ àÖr°   r³   )Úextract_errorÚresult_readyÚrestore_context_onc              óˆ
  ^ ^^^^^^^^^^^#   • [         R                  " 5       m[         R                  " 5       mSmSmSUUUUUUUUU U4
S jjn[        T 5       Vs0 s H  oˆR                  c  M  UR                  U_M      n	nTR                  =n
c  U	Tl        O!U
R                  5         U
R                  U	5        T R                  T5        [        R                  " 5       m[         R                  " T R                  TUS95      n[         R                  " TR                  5       5      n [         R                  " XË1[         R                  S9I Sh  v•N   [        R                  " U5      I Sh  v•N   / mT=(       d    S H.  nTR%                  US   US   R#                  US   5      45        M0     SU4S jjnUb  UR'                  U5        SUUU U4S	 jjnUR)                  5       =(       a    TR+                  5       (       + nU(       a  U" UR-                  5       5      I Sh  v•N     [/        US
97v •  U(       dˆ  TR#                  5         Tc(  Tb  T" 5       (       a  U" UI Sh  v•N 5      I Sh  v•N   OMTb   U" UI Sh  v•N 5      I Sh  v•N   O0UR)                  5       (       d  UR;                  5          UI Sh  v•N   Tb)   T R=                  TTS9I Sh  v•N nU" U5      I Sh  v•N   Tb  Te Uc  U" 5         ggs  snf  GNº GNŸ! [          a7  nUmTR#                  5         [        R                  " XË5      I Sh  v•N    e SnAff = f GN/! [          a4  nTb  T" U5      OUm[1        T[2        [4        45      (       a  e  SnAGNXSnAff = f GN0 GN' GN GN! [          a6  n[1        U[         R6                  5      (       d  UTLa  UTl         SnAGNSnAff = f GN%! [         R6                  [         4 a     GN@f = f! U(       dû  TR#                  5         Tc*  Tb  T" 5       (       a  U" UI Sh  v•N  5      I Sh  v•N    f Tbh   U" UI Sh  v•N  5      I Sh  v•N    f ! [          a?  n[1        U[         R6                  5      (       d  UTLa  UTl         SnAf  SnAf  SnAf SnAff = fUR)                  5       (       d=  UR;                  5          UI Sh  v•N    f ! [         R6                  [         4 a     f f = ff f = f GN4 GN'! [          a  nUm SnAGN7SnAff = f! Uc  U" 5         f f = f7f)uÎ  Dispatch run hooks around a caller-owned run body.

`restore_context_on` hands ownership of the propagated-ContextVar restore to the caller's exit
stack: registered before the caller pushes later entries (like its toolset), so restore happens
in LIFO order after those exit â€” resources entered inside the propagated context (e.g. the run
span set by `Instrumentation.wrap_run`) also *exit* inside it. Without it, this context manager
restores on its own exit.
Nc               “  ó  >
#   • [        T5         T
R                  T5      I S h  v•N   [        R                  " 5       n S S S 5        W  Vs/ s H  nUT;  d  TU   X   Ld  M  XU   4PM     snmTR	                  5         TR                  5       I S h  v•N   Tb  Tb  T" T5      eTeT	b7  T	" 5       (       d+  [        R                  [        [              " 5       I S h  v•N   T" 5       $  NÃ! , (       d  f       N²= fs  snf  Nm N%7f©N)
rA   Ú
before_runÚcontextvarsÚcopy_contextÚsetÚwaitÚasyncioÚFuturer`   r   )Úcurrent_ctxÚvarÚ	_run_doneÚ
_run_errorÚ
_run_readyÚ_wrap_contextÚbuild_resultr·   Úouter_contextr¸   Úrun_capabilityÚrun_ctxs     €€€€€€€€€€r±   Ú_do_runÚ%_run_lifecycle_hooks.<locals>._do_runð   sø   øé € ä$ WÕ-Ø ×+Ñ+¨GÓ4×4Ð4Ü%×2Ò2Ó4ˆK÷ .ñ #ó
â"�Ø˜-Ó'¨=¸Ñ+=À[ÑEUÐ+Uó $ˆS˜cÑ"Ó#Ù"ñ
ˆð
 	�‰ÔØ�n‰nÓ×ÐØÑ!Ø/<Ñ/H‘- 
Ó+ÐXÈjÐXØÑ#©L¯N©Nô
 —.‘.¤´Ñ!4Ò5Ó7×7Ð7Ù‹~Ðñ' 5÷ .Õ-üò

ñ 	ñ 8ùs\   ƒD�C*¤C(¥C*¾DÁ
C;Á"
C;Á,&DÂD ÂA	DÃDÃDÃ(C*Ã*
C8Ã4DÄD)Úhandler)Úreturn_whenr§   r   rƒ   c                 ó>   >• T H  u  pU R                  U5        M     g r¼   )Úreset)rÅ   ÚtokenÚcontext_tokenss     €r±   Ú_restore_context_varsÚ3_run_lifecycle_hooks.<locals>._restore_context_vars5  s   ø€ Û(‰JˆCØ�I‰I�eÖò )r°   c              “  ó”   >#   • TR                  TU S9I S h  v•N n [        R                  " 5         T" U 5      I S h  v•N   S mg  N, N	7f)Nr•   )Ú	after_runr-   Úraise_if_cancelling)r–   rÇ   ÚfinalizerÌ   rÍ   s    €€€€r±   Ú_finalize_resultÚ._run_lifecycle_hooks.<locals>._finalize_result<  sJ   øé € à%×/Ñ/°ÀÐ/ÐG×Gˆô
 	×"Ò"Ô$Ù�vÓ×ÐØ‰
ñ Hñ 	ùs   ƒA—A˜$A¼A½AÁA)r¶   )Úerror©ÚreturnúAgentRunResult[Any])rà   ÚNone©r–   rá   rà   râ   )rÂ   ÚEventrR   ÚidÚ_run_capabilities_by_idÚclearÚupdateÚ_prepare_run_contextr¾   r¿   Úcreate_taskÚwrap_runrÁ   ÚFIRST_COMPLETEDr-   Úcancel_and_drainÚBaseExceptionrÀ   ÚappendÚcallbackÚdoneÚis_setr–   r³   Ú
isinstanceÚGeneratorExitÚKeyboardInterruptÚCancelledErrorÚ__context__ÚcancelÚon_run_error)rÌ   rÍ   rÊ   rÛ   r·   r¸   r¹   rÎ   Ú
capabilityÚrun_capabilities_by_idÚexistingÚ
_wrap_taskÚ_ready_waiterÚexcÚcv_pairrÖ   rÜ   r¶   Úwrap_excr–   Úon_error_excrÆ   rÇ   rÈ   rÉ   rÕ   rË   s   ``````               @@@@@@r±   Ú_run_lifecycle_hooksr  Í   sË  ÿûé € ô< —’“€JÜ—’“€IØ'+€JØ>B€M÷÷ ð ô8 5FÀnÔ4UóÚ4U j×YfÑYfÓ!ˆ
�‰�zÒ!Ñ4Uð ð ð ×3Ñ3Ð3ˆÑ<Ø*@ˆÕ'à�‰ÔØ�‰Ð.Ô/Ø×'Ñ'¨Ô0ä×,Ò,Ó.€MÜ×$Ò$ ^×%<Ñ%<¸WÈgÐ%<Ð%VÓW€Jä×'Ò'¨
¯©Ó(9Ó:€Mð5Ü�lŠl˜MÐ6ÄG×D[ÑD[Ñ\×\Ð\ô ×%Ò% mÓ4×4Ð4ð LN€Nð !×& BÒ&ˆØ×Ñ˜w q™z¨7°1©:¯>©>¸'À!¹*Ó+EÐFÖGñ '÷ð Ñ%Ø×#Ñ#Ð$9Ô:÷	ò 	ð !—o‘oÓ'×C°
×0AÑ0AÓ0CÔ,C€OÞÙ˜z×0Ñ0Ó2Ó3×3Ð3ð5$ð#	Ü°Ñ@Ó@ö #Ø—‘”ØÑ%¨<Ñ+?Á<Ç>Á>Ù*°×+;Ó<×<Ñ<ØÑ+ð	>Ù.°Z×/?Ó@×@Ñ@ð $Ÿ™×*Ñ*Ø×%Ñ%Ô'ðØ(×(Ð(ð
 Ñ!ð/Ø-×:Ñ:¸7È*Ð:ÐU×U�ñ ' vÓ.×.Ð.ð Ñ!ØÐð "ð Ñ%Ù!Õ#ð &ùòiò$ 	]ò 	5øô ó ð ˆ
Ø�‰ŒÜ×%Ò% mÓ@×@Ñ@ØûðúòV 	4øô
 ó 	Ø/<Ñ/H™ sÔ+ÈcˆJô ˜*¤}Ô6GÐ&H×IÑIØõ Jûð		úò ,<Ò<ò
 0@Ò@øÜ(ó >ô
  *¨(´G×4JÑ4J×KÑKÐPXÐ`jÒPjà5=˜JÔ2ÿùð>úò )øÜ#×2Ñ2´MÐBó Úðûö/ #Ø—‘”ØÑ%¨<Ñ+?Á<Ç>Á>Ù*°×+;Ð+;Ó<×<Ò<ØÑ+ð	>Ù.°Z×/?Ð/?Ó@×@Ò@øÜ(ó >ô
  *¨(´G×4JÑ4J×KÑKÐPXÐ`jÒPjà5=˜J×2Ñ2ô QkÔKûð>úð $Ÿ™×*Ñ*Ø×%Ñ%Ô'ðØ(×(Ò(øÜ#×2Ñ2´MÐBó Ùðúð	 +ð' #úò: Vò /øô !ó *Ø)–
ûð*ûð Ñ%Ù!Õ#ð &üsB  ŽAUÁLÁ/LÂ B(UÄ)'L ÅL
ÅL ÅUÅ.LÅ/B6UÈ%MÈ&UÈ,M È80T2 É(NÉ)T2 É4NÉ5T2 É>N$ ÊNÊN$ ÊN!ÊN$ Ê&T2 Ê=O* ËO'ËO* ËT2 ËT ËTËT Ë#T2 Ë.TË/	T2 Ë9UÌ
L ÌUÌ
MÌ+MÍMÍMÍMÍUÍ
NÍ!)NÎ
P ÎNÎP ÎT2 ÎT2 ÎN$ Î!N$ Î$
O$Î.+OÏT2 ÏO$Ï$T2 Ï'O* Ï*PÐT2 ÐPÐT2 Ð1TÐ<P?Ð=TÑ	QÑ
	TÑQ/ÑQÑQ/Ñ(Q+Ñ)Q/Ñ.TÑ/
R8Ñ9+R3Ò$TÒ3R8Ò8(TÓ!S-Ó&S)Ó'S-Ó,TÓ-T
ÔTÔ	T
Ô
TÔT2 ÔT ÔT2 Ô
T/Ô"T*Ô$T2 Ô*T/Ô/T2 Ô2T?Ô?Uc                ó6   • [        U [        R                  5      $ )zONarrow a value to a concrete model without losing its client type to `Unknown`.)ró   r1   ÚModel)Úvalues    r±   Ú	_is_modelr  ƒ  s   € ä�eœVŸ\™\Ó*Ð*r°   c                óz   • [        U [        [        R                  45      (       a  [        R                  " 5       $ S$ )a=  The source to attribute one of the agent's configured instructions to.

Only the literal instructions the agent was built with are addressed by the agent's own key: an
instruction function becomes addressable when `@agent.instructions(name=...)` names it, so a bare
callable speaks for nobody and stays unidentified.
N)ró   ÚstrÚ	_messagesÚInstructionPartÚAgentInstructionSource)Úinstructions    r±   Ú_agent_instruction_sourcer  ˆ  s0   € ô 2<¸KÌ#Ìy×OhÑOhÐIi×1jÑ1jŒ9×+Ò+Ó-ÐtÐptÐtr°   ©Údefaultc               óV   • [        U R                  SU5      U R                  SU5      S9$ )z¸Resolve normalized retry overrides into concrete retry budgets.

Missing keys in an `AgentRetries` dict fall back to `default`, so internal code can work with a
single concrete shape.
r¥   r¦   ©r¥   r¦   )r¢   Úget)Úretriesr  s     r±   Ú_normalize_agent_retriesr  ’  s)   € ô ! w§{¡{°7¸GÓ'DÈWÏ[É[ÐYaÐcjÓMkÑlÐlr°   c                ó^   • U c  0 $ [        U [        5      (       a  X S.$ U R                  5       $ )uæ   Normalize retry input without filling missing keys.

Used while merging layered configuration. A bare `int` sets both the `tools` and `output`
budgets â€” the same shorthand at every call site (construction, run, override, spec).
r  )ró   r¤   r   )r  s    r±   Ú _normalize_agent_retry_overridesr  ›  s0   € ð �Øˆ	Ü�'œ3×ÑØ Ñ4Ð4Ø�<‰<‹>Ðr°   ÚTÚSÚ_PreparedDepsTÚ_PreparedOutputTc                  ój   • \ rS rSr% SrS\S'   S\S'   S\S'   S	\S
'   S\S'   S\S'   S\S'   S\S'   Srg)Ú_ResolvedSpeci¯  z>Result of resolving an AgentSpec for use at run/override time.zCombinedCapability[Any] | Nonerú   z)list[_instructions.AgentInstruction[Any]]Úinstructionsú
str | NoneÚmodelúModelSettings | NoneÚmodel_settingsúdict[str, Any] | NoneÚmetadataÚnameú
int | NoneÚoutput_retriesÚtool_retriesr§   Nr¨   r§   r°   r±   r  r  ¯  s5   ‡ áHà.Ó.Ø;Ó;ØÓØ(Ó(Ø#Ó#Ø
ÓØÓØÖr°   r  F)Úinitc                  ón  • \ rS rSr% SrS\S'   S\S'   S\S'   S	\S
'    S\S'    S\S'   S\S'    SrS\S'   \R                  " SS9r	S\S'   \R                  " SS9r
S\S'   \R                  " SS9rS\S'   \R                  " SS9rS\S'   \R                  " SS9rS\S'   \R                  " SS9rS\S '   \R                  " SS9rS!\S"'   \R                  " SS9rS#\S$'   \R                  " SS9rS%\S&'   \R                  " SS9rS'\S('   \R                  " SS9rS)\S*'   \R                  " SS9rS+\S,'   \R                  " SS9rS+\S-'   \R                  " SS9rS.\S/'   \R                  " SS9rS0\S1'   \R                  " SS9rS2\S3'   \R                  " SS9rS4\S5'   \R                  " SS9rS+\S6'   \R                  " SS9rS7\S8'   \R:                  S´S9 j5       r\ Sµ\ S:S;\!S:S:S:S:S:S;S:SS<S:S:S:S:S=.                                     S¶S> jjj5       r"\ Sµ\ S:S;\!S:S:S:S:S:S;S:SS<S:S:S:S:S=.                                     S¶S? jjj5       r" Sµ\ S:S;\!S:S:S:S:S:S;S:SS<S:S:S:S:S=.                                     S¶S@ jjjr"\\#S;S:\ S:S;S:S:S:S:S:S;S:SS:S:S:S:S:SA.                                       S·SB jj5       5       r$\\#S;S:\ S:S;S:S:S:S:S:S;S:SS:S:S:S:S:SA.                                         S¸SC jj5       5       r$\#\%" S:5      S;S:\ S:S;S:S:S:S:S:S;S:SS:S:S:S:S:SD.                                         S¹SE jj5       r$\\#S:S;S:\ S:S;S:S:S:S:S:S;S:SS:S:S:S:S:SF.                                         SºSG jj5       5       r&\\#S:S;S:\ S:S;S:S:S:S:S:S;S:SS:S:S:S:S:SF.                                           S»SH jj5       5       r&\#S:\%" S:5      S;S:\ S:S;S:S:S:S:S:S;S:SS:S:S:S:S:SI.                                           S¼SJ jj5       r&\'S½S¾SL jj5       r(\)S¿SM j5       r*\*RV                  SÀSN j5       r*\)SÁSO j5       r,\,RV                  SÂSP j5       r,\)SÃSQ j5       r-\-RV                  SÄSR j5       r-\)SÃSS j5       r.\.RV                  SÅST j5       r.SµSÆSU jjr/\)SÇSV j5       r0\)SÈSW j5       r1\)SÉSX j5       r2\)SÊSY j5       r3SÊSZ jr4SËS[ jr5\ SµS:S:S:S:S:S:S:S:S:S:S:S:S:S:SKS:S:S:S\.                                       SÌS] jjj5       r6\ SµS:S:S:S:S:S:S:S:S:S:S:S:S:SKS:S:S:S^.                                       SÍS_ jjj5       r6\7 SµS:S:S:S:S:S:S:S:S:S:S:S:S:S:SKS:S:S:S\.                                       SÎS` jjj5       r6 SµS:S:S:S:S:S:S:S:S:S:S:S:S:S:S:S:S:Sa.                                     SÏSb jjjr8 Sµ     SÐSc jjr9      SÑSd jr:      SÒSe jr; SÓ     SÔSf jjr<\=\>R~                  \>R~                  \>R~                  \>R~                  \>R~                  \>R~                  \>R~                  \>R~                  \>R~                  \>R~                  S:Sg.                       SÕSh jj5       r@\    SÖSi j5       rA\    S×Sj j5       rA\SØSk j5       rA\SÙSl j5       rA\S:Sm.   SÚSn jj5       rA SµS:Sm.     SÛSo jjjrAS:S:S:S:S:S:Sp.             SÜSq jjrB\    SÖSr j5       rC\    S×Ss j5       rC\SØSt j5       rC\SÙSu j5       rC\SSv.   SÝSw jj5       rC SµSSv.     SÞSx jjjrC\    SßSy j5       rD\    SàSz j5       rD\    SáS{ j5       rD\    SâS| j5       rD    SãS} jrD\    SäS~ j5       rE\S:S.     SåS€ jj5       rE SµS:S.       SæS� jjjrE\SçS‚ j5       rF\S:S:S:S:S:SƒS\GS:SSS:S:SS:S„.                               SèS… jj5       rF SµS:S:S:S:S:SƒS\GS:SSS:S:SS:S„.                                 SéS† jjjrF\SêS‡ j5       rH\S:S:S:S:S:SƒS\GS:SSS:S:SS:S„.                               SëSˆ jj5       rH SµS:S:S:S:S:SƒS\GS:SSS:S:SS:S„.                                 SìS‰ jjjrH\SíSŠ j5       rI\SKS:S‹.     SîSŒ jj5       rI SµSKS:S‹.       SïS� jjjrISðSŽ jrJ    SñS� jrKSòS� jrL Sµ     SóS‘ jjrMSµSôS’ jjrNSõS“ jrO    SöS” jrPS:S•.         S÷S– jjrQS:S•.         SøS— jjrR\'      SùS˜ j5       rSSµSúS™ jjrTSûSš jrUSüS› jrV              SýSœ jrW  Sþ     SÿS� jjrX\>R~                  S:S:S:S:4           GS Sž jjrY\)SòSŸ j5       rZ\)GSS  j5       r[\)GSS¡ j5       r\ SµSS¢.     GSS£ jjjr]\GSS¤ j5       r^\    GSS¥ j5       r^GSS¦ jr^\7S:S:S:S:S:S:S:S:S:S:S:SS§.                           GSS¨ jj5       r_\7S:S:S:S:S:S:S:S:S:S:S:S©SSªS«S:S¬.                                   GSS­ jj5       r`GSS® jraGS	S¯ jrbSµGS
S° jjrcS:S:S:S:S:S:S±.             GSS² jjrdS³reg:(  rŸ   i½  aG  Class for defining "agents" - a way to have a specific type of "conversation" with an LLM.

Agents are generic in the dependency type they take [`AgentDepsT`][pydantic_ai.tools.AgentDepsT]
and the output type they return, [`OutputDataT`][pydantic_ai.output.OutputDataT].

By default, if neither generic parameter is customised, agents have type `Agent[object, str]`.

Minimal usage example:

```python
from pydantic_ai import Agent

agent = Agent('openai:gpt-5.2')
result = agent.run_sync('What is the capital of France?')
print(result.output)
#> The capital of France is Paris.
```
ú1models.Model | models.KnownModelName | str | NoneÚ_modelr  Ú_nameú$TemplateStr[AgentDepsT] | str | NoneÚ_descriptionr4   Úend_strategyú%AgentModelSettings[AgentDepsT] | Noner"  úOutputSpec[OutputDataT]Ú_output_typeú%InstrumentationSettings | bool | NoneÚ_instrumentFz(ClassVar[InstrumentationSettings | bool]Ú_instrument_default©Úreprú AgentMetadata[AgentDepsT] | NoneÚ	_metadataútype[AgentDepsT]Ú
_deps_typeú!_output.OutputSchema[OutputDataT]Ú_output_schemaz6list[_output.OutputValidator[AgentDepsT, OutputDataT]]Ú_output_validatorsú2list[_instructions.SourcedInstruction[AgentDepsT]]r*   útuple[str, ...]Ú_system_promptsz3list[_system_prompt.SystemPromptRunner[AgentDepsT]]Ú_system_prompt_functionsz8dict[str, _system_prompt.SystemPromptRunner[AgentDepsT]]Ú _system_prompt_dynamic_functionszFunctionToolset[AgentDepsT]Ú_function_toolsetz OutputToolset[AgentDepsT] | NoneÚ_output_toolsetú!list[AbstractToolset[AgentDepsT]]Ú_user_toolsetsr¤   Ú_max_output_retriesÚ_max_tool_retriesúfloat | NoneÚ_tool_timeoutú-Any | Callable[[RunContext[AgentDepsT]], Any]Ú_validation_contextú%EventStreamHandler[AgentDepsT] | NoneÚ_event_stream_handlerú._concurrency.AbstractConcurrencyLimiter | NoneÚ_concurrency_limiterÚ_entered_countúAsyncExitStack | NoneÚ_exit_stackc                ó,   • [         R                  " 5       $ r¼   )ÚanyioÚLock©Úselfs    r±   Ú_enter_lockÚAgent._enter_lock  s   € ô
 �zŠz‹|Ðr°   Nr§   Úgraceful)Úoutput_typer  Úsystem_promptÚ	deps_typer%  Údescriptionr"  r  Úvalidation_contextr¥   ÚtoolsetsÚdefer_model_checkr0  r$  Útool_timeoutÚmax_concurrencyÚcapabilitiesc               ó   • g r¼   r§   ©rZ  r   r^  r  r_  r`  r%  ra  r"  r  rb  r¥   rc  rd  r0  r$  re  rf  rg  s                      r±   Ú__init__ÚAgent.__init__  ó   € ð, r°   c               ó   • g r¼   r§   ri  s                      r±   rj  rk  2  rl  r°   c          	     óŽ  • X`l         Xpl        Xàl        [        U5      n[	        U5        [        5       U l        [        U5      U l        [        U R                  R                  5        [        U R                  U/5      n[        U[        5      (       d   S5       eUU l        [        U R                  /5        Xl        X€l        X l        SU l        Xðl        XPl        [(        R*                  [,           R/                  U5      U l        / U l        [4        R6                  " U5       Vs/ s H#  n[4        R8                  " U[;        U5      5      PM%     snU l        [        U[<        5      (       a  U4O
[?        U5      U l         / U l!        0 U l"        [G        U	5      n[I        U5      nURJ                  U l&        URN                  U l(        UU l)        U RR                  b3  U RR                  S::  a#  [T        RV                  " SU RR                   35      eX l,        U R0                  RZ                  U l.        U R\                  (       a2  U R\                  R^                  c  U RP                  U R\                  l/        [a        USU RR                  U R0                  S9U l1        [e        U=(       d    / 5      nU Vs/ s H+  n[        U[f        5      (       a  M  [h        [j           " US9PM-     snU l6        [o        U Rl                  5      U l8        U Vs/ s H  n[        U[f        5      (       d  M  UPM     snU l9        SU l:        [v        Rx                  " U5      U l=        [}        SSS9U l?        [}        S	SS9U l@        [}        S
SS9U lA        [}        SSS9U lB        [}        SSS9U lC        [}        SSS9U lD        [}        SSS9U lE        [}        SSS9U lF        [}        SSS9U lG        [}        SSS9U lH        [}        SSS9U lI        [}        SSS9U lJ        SU lK        SU lL        [›        5       U lN        0 U lO        / U lP        / U lQ        / U lR        SU lS        [©        U R                  U SS9U l        U R                  R«                  5       nUb  U/U lP        [©        U R                  U SS9U l        Ub=  U(       d6  U R                  R¬                  (       d  [®        R°                  " U5      U l        / nU R                  R³                  UR´                  5        [        U5        [        U R                  /5        U R                  R·                  5       U lQ        [e        U R                  R¹                  5       5      U lR        [»        U R¤                  SS9  U R                  R½                  5       U lS        [¿        U RÀ                  5        gs  snf s  snf s  snf )a´  Create an agent.

Args:
    model: The default model to use for this agent, if not provided,
        you must provide the model when calling it. We allow `str` here since the actual list of allowed models changes frequently.
    output_type: The type of the output data, used to validate the data returned by the model,
        defaults to `str`.
    instructions: Instructions to use for this agent, you can also register instructions via a function with
        [`instructions`][pydantic_ai.agent.Agent.instructions] or pass additional, temporary, instructions when executing a run.
    system_prompt: Static system prompts to use for this agent, you can also register system
        prompts via a function with [`system_prompt`][pydantic_ai.agent.Agent.system_prompt].
    deps_type: The type used for dependency injection, this parameter exists solely to allow you to fully
        parameterize the agent, and therefore get the best out of static type checking.
        If you're not using deps, but want type checking to pass, you can set `deps=None` to satisfy Pyright
        or add a type hint `: Agent[object, <return type>]`.
    name: The name of the agent, used for logging. If `None`, we try to infer the agent name from the call frame
        when the agent is first run.
    description: A human-readable description of the agent, attached to the agent run span as
        `gen_ai.agent.description` when instrumentation is enabled.
    model_settings: Optional model request settings to use for this agent's runs, by default.
        Can be a static `ModelSettings` dict or a callable that takes a
        [`RunContext`][pydantic_ai.tools.RunContext] and returns `ModelSettings`.
        Callables are called before each model request, allowing dynamic per-step settings.
    retries: Per-category retry budgets for tools and output validation. Pass an `int` to set the same
        budget for both, or an [`AgentRetries`][pydantic_ai.AgentRetries] dict to set them
        individually (e.g. `retries={'tools': 3, 'output': 1}`). Defaults to 1 for both.
        On the text path, `output` is a global budget shared across all output-validation retries
        in a run; on the tool path it is the default per-tool `max_retries` for each output tool,
        overridable via [`ToolOutput(max_retries=...)`][pydantic_ai.output.ToolOutput.max_retries].
        Both budgets can be overridden per run via `agent.run(retries=...)` (and friends), passing
        an `AgentRetries` dict (e.g. `retries={'tools': 3}`) for per-category control.
        For model request retries, see the [transport retries](../retries.md#transport-retries) documentation.
    validation_context: Pydantic [validation context](https://docs.pydantic.dev/latest/concepts/validators/#validation-context) used to validate tool arguments and outputs.
    tools: Tools to register with the agent, you can also register tools via the decorators
        [`@agent.tool`][pydantic_ai.agent.Agent.tool] and [`@agent.tool_plain`][pydantic_ai.agent.Agent.tool_plain].
    toolsets: Toolsets to register with the agent, including MCP servers and functions which take a run context
        and return a toolset. See [`ToolsetFunc`][pydantic_ai.toolsets.ToolsetFunc] for more information.
    defer_model_check: by default, if you provide a [named][pydantic_ai.models.KnownModelName] model,
        it's evaluated to create a [`Model`][pydantic_ai.models.Model] instance immediately,
        which checks for the necessary environment variables. Set this to `True`
        to defer the evaluation until the first run. Useful if you want to
        [override the model][pydantic_ai.agent.Agent.override] for testing.
    end_strategy: Strategy for handling tool calls that are requested alongside a final result.
        See [`EndStrategy`][pydantic_ai.agent.EndStrategy] for more information.
    metadata: Optional metadata to store with each run.
        Provide a dictionary of primitives, or a callable returning one
        computed from the [`RunContext`][pydantic_ai.tools.RunContext] on each run.
        Metadata is resolved when a run starts and recomputed after a successful run finishes so it
        can reflect the final state.
        Resolved metadata can be read after the run completes via
        [`AgentRun.metadata`][pydantic_ai.agent.AgentRun],
        [`AgentRunResult.metadata`][pydantic_ai.agent.AgentRunResult], and
        [`StreamedRunResult.metadata`][pydantic_ai.result.StreamedRunResult],
        and is attached to the agent run span when instrumentation is enabled.
    tool_timeout: Default timeout in seconds for tool execution. If a tool takes longer than this,
        the tool is considered to have failed and a retry prompt is returned to the model (counting towards the retry limit).
        Individual tools can override this with their own timeout. Defaults to None (no timeout).
    max_concurrency: Optional limit on concurrent agent runs. Can be an integer for simple limiting,
        a [`ConcurrencyLimit`][pydantic_ai.ConcurrencyLimit] for advanced configuration with backpressure,
        a [`ConcurrencyLimiter`][pydantic_ai.ConcurrencyLimiter] for sharing limits across
        multiple agents, or None (default) for no limiting. When the limit is reached, additional calls
        to `run()` or `iter()` will wait until a slot becomes available.
    capabilities: Optional list of [capabilities](https://pydantic.dev/docs/ai/capabilities/overview/) to configure the agent with,
        including functions which take a run context and return a capability.
        See [`CapabilityFunc`][pydantic_ai.capabilities.CapabilityFunc] for more information.
        Custom capabilities can be created by subclassing
        [`AbstractCapability`][pydantic_ai.capabilities.AbstractCapability].
z1combining the agent capabilities kept a containerNr   ztool_timeout must be > 0, got ©Úmax_retriesÚtimeoutÚoutput_schema)Útoolset_funcÚ_override_namer  Ú_override_depsÚ_override_modelÚ_override_toolsetsÚ_override_toolsÚ_override_native_toolsÚ_override_instructionsÚ_override_metadataÚ_override_model_settingsÚ_override_output_retriesÚ_override_tool_retriesÚ_override_root_capabilityF)Ú	innermostTúagent capabilities©Úsource)ar-  r/  r0  rK   Ú_inject_auto_capabilitiesrU   Ú_event_hooksrG   Ú_root_capabilityÚ_validate_capability_idsrg  rN   ró   Ú _validate_instruction_source_idsr,  r"  r3  r5  r:  r<  r+   ÚOutputSchemar\   Úbuildr>  r?  r*   Únormalize_instructionsÚsourced_instructionr  r	  ÚtuplerB  rC  rD  r  r  r¥   rJ  r¦   rI  rL  r/   Ú	UserErrorrN  ÚtoolsetrF  rp  Ú_AgentFunctionToolsetrE  Úlistrx   rz   rf   Ú_dynamic_toolsetsÚlenÚ"_constructor_dynamic_toolset_countrH  rP  Ú_concurrencyÚnormalize_to_limiterrR  r   rt  ru  rv  rw  rx  ry  rz  r{  r|  r}  r~  r  rS  rU  rÀ   Ú_entered_model_idsÚ_entered_models_by_selectionÚ_cap_toolsetsÚ_cap_instructionsÚ_cap_native_toolsÚ_cap_model_settingsrS   Úget_toolsetÚhas_resolve_model_idr1   Úinfer_modelÚapplyrï   Ú_collect_instructionsÚget_native_toolsÚ_validate_native_tool_idsÚget_model_settingsr€   rc  )rZ  r   r^  r  r_  r`  r%  ra  r"  r  rb  r¥   rc  rd  r0  r$  re  rf  rg  Úcombinedr  Úretry_overridesÚresolved_retriesÚagent_toolsetsr�  Úcap_toolsetÚstatic_capabilitiess                              r±   rj  rk  J  sW  € ðt Œ
Ø'ÔØ(Ôä,¨\Ó:ˆä! ,Ô/ô 05«wˆÔä 2°<Ó @ˆÔÜ  ×!6Ñ!6×!CÑ!CÔDô 3°4×3HÑ3HÈ<È.ÓYˆô ˜(Ô$6×7Ñ7ÐlÐ9lÓlÐ7Ø (ˆÔÜ(¨$×*?Ñ*?Ð)@ÔAð Œà,Ôà'ÔØˆÔØ!ŒØ#Œä%×2Ñ2´;Ñ?×EÑEÀkÓRˆÔØ"$ˆÔô  -×CÒCÀLÔQó
âQ�ô ×-Ò-¨kÔ;TÐU`Ó;aÖbÙQñ
ˆÔô
 4>¸mÌS×3QÑ3Q Ñ/ÔW\Ð]jÓWkˆÔØ(*ˆÔ%Ø02ˆÔ-ä:¸7ÓCˆÜ3°OÓDÐØ!1×!7Ñ!7ˆÔØ#3×#:Ñ#:ˆÔ Ø)ˆÔØ×ÑÑ)¨d×.@Ñ.@ÀAÓ.EÜ×&Ò&Ð)GÈ×HZÑHZÐG[Ð'\Ó]Ð]à#5Ô à#×2Ñ2×:Ñ:ˆÔØ×× D×$8Ñ$8×$DÑ$DÑ$LØ/3×/GÑ/GˆD× Ñ Ô,ô "7ØØØ×&Ñ&Ø×-Ñ-ñ	"
ˆÔô ˜hŸn¨"Ó-ˆñ *ó"
â)�Ü˜g¤×7ó =ŒNœ:Ò&°GÔ<Ù)ñ"
ˆÔô
 36°d×6LÑ6LÓ2MˆÔ/Ù6DÓm²n¨7Ì
ÐSZÔ\k×HlŸw±nÑmˆÔð &*ˆÔ"ä$0×$EÒ$EÀoÓ$VˆÔ!ä>HÐIYÐcgÑ>hˆÔÜEOÐP`ÐjnÑEoˆÔÜfpØ tñg
ˆÔô eoØ ¨$ñe
ˆÔô
 Ð(°$Ñ7ð 	Ôô isØ$¨dñi
ˆÔ#ô Ð/¸Ñ>ð 	Ô#ô YcØ ¨$ñY
ˆÔô dnØ&°ñd
ˆÔ%ô ISØ&°ñI
ˆÔ%ô GQÐQiÐswÑFxˆÔ#ÜdnØ'°ñe
ˆÔ&ð  ˆÔØˆÔÜ,/«EˆÔØQSˆÔ)ð >@ˆÔØUWˆÔØDFˆÔØJNˆÔ ô !7°t×7LÑ7LÈdÐ^cÑ dˆÔØ×+Ñ+×7Ñ7Ó9ˆØÑ"Ø"- ˆDÔÜ 6°t×7LÑ7LÈdÐ^bÑ cˆÔàÑÖ%6¸t×?TÑ?T×?i×?iÜ ×,Ò,¨UÓ3ˆDŒKð EGÐØ×Ñ×#Ñ#Ð$7×$>Ñ$>Ô?Ü Ð!4Ô5Ü(¨$×*?Ñ*?Ð)@ÔAð "&×!6Ñ!6×!LÑ!LÓ!NˆÔÜ!% d×&;Ñ&;×&LÑ&LÓ&NÓ!OˆÔÜ! $×"8Ñ"8ÐAUÒVØ#'×#8Ñ#8×#KÑ#KÓ#MˆÔ ô 	˜Ÿ™Õ&ùòu
ùòH"
ùò ns   Ä&*V8Ê.V=ËV=ÌWÌ#W)Úcustom_capability_typesr   r^  r  r_  r%  ra  r"  r  rb  r¥   rc  rd  r0  r$  re  rf  rg  c               ó   • g r¼   r§   )ÚclsÚspecr«  r   r^  r  r_  r%  ra  r"  r  rb  r¥   rc  rd  r0  r$  re  rf  rg  s                       r±   Ú	from_specÚAgent.from_specQ  s   € ð0 !r°   c               ó   • g r¼   r§   )r­  r®  r`  r«  r   r^  r  r_  r%  ra  r"  r  rb  r¥   rc  rd  r0  r$  re  rf  rg  s                        r±   r¯  r°  k  s   € ð2 r°   ©r`  r«  r   r^  r  r_  r%  ra  r"  r  rb  r¥   rc  rd  r0  r$  re  rf  rg  c               óP  • [        X5      u  nnU[        La  UnO)UR                  b  [        UR                  5      nO[        n[        R
                  " UR                  5      nUR                  [        R
                  " U5      5        [        [        UUU5      5      nU(       a  UR                  U5        U=(       d    UR                  n[        S0 SU_SU_SU=(       d    S_SU_SU_SU=(       d    UR                  _SU	=(       d    UR                  _S	[        UR                  (       a  [!        ["        UR                  5      OSU
5      _S
[%        UU5      _SU_SU_SU_SU_SUb  UOUR&                  _SUb  UOUR(                  _SUb  UOUR*                  _SU_SU_6nU$ )aî  Construct an Agent from a spec dict or `AgentSpec`.

This allows defining agents declaratively in YAML/JSON/dict form.
Keyword arguments supplement the spec: scalar spec fields (like `name`,
`retries`) are used as defaults that explicit arguments override, while
`capabilities` from both sources are merged.

Args:
    spec: The agent specification, either a dict or an `AgentSpec` instance.
    deps_type: The type of the dependencies for the agent. When provided,
        template strings in capabilities (e.g. `"Hello {{name}}"`) are
        compiled and validated against this type.
    custom_capability_types: Additional capability classes to make available
        beyond the built-in defaults.
    model: Override the model from the spec.
    output_type: The type of the output data, defaults to `str`.
    instructions: Instructions for the agent.
    system_prompt: Static system prompts.
    name: The agent name, overrides spec `name` if provided.
    description: The agent description, overrides spec `description` if provided.
    model_settings: Model request settings.
    retries: Retry budgets for tools and output validation. Pass an `int` to set the same budget
        for both, or an [`AgentRetries`][pydantic_ai.AgentRetries] dict to set them individually.
        Overrides spec `retries` if provided.
    validation_context: Pydantic validation context for tool arguments and outputs.
    tools: Tools to register with the agent.
    toolsets: Toolsets to register with the agent.
    defer_model_check: Defer model evaluation until first run.
    end_strategy: Strategy for tool calls alongside a final result, overrides spec `end_strategy` if provided.
    metadata: Metadata to store with each run, overrides spec `metadata` if provided.
    tool_timeout: Default timeout for tool execution, overrides spec `tool_timeout` if provided.

    max_concurrency: Limit on concurrent agent runs.
    capabilities: Additional capabilities merged with those from the spec.

Returns:
    A new Agent instance.
Nr   r^  r  r_  r`  r%  ra  r"  r  rb  r¥   rc  rd  r0  r$  re  rf  rg  r§   )Ú_validate_specr	  rr  r^   r*   r‹  r  Úextendr‘  Ú_capabilities_from_specr   rŸ   r%  ra  rb   r"  r   ra   Ú_merge_retries_with_specr0  r$  re  )r­  r®  r`  r«  r   r^  r  r_  r%  ra  r"  r  rb  r¥   rc  rd  r0  r$  re  rf  rg  Úvalidated_specÚtemplate_contextÚeffective_output_typeÚmerged_instructionsÚall_capabilitiesÚeffective_modelÚagents                               r±   r¯  r°  †  sé  € ô~ ,:¸$Ó+JÑ(ˆÐ(ð œcÒ!Ø$/Ñ!Ø×)Ñ)Ñ5Ü$2°>×3OÑ3OÓ$PÑ!ä$'Ð!ô ,×BÒBÀ>×C^ÑC^Ó_ÐØ×"Ñ"¤=×#GÒ#GÈÓ#UÔVä7;Ü# NÐ4KÐM]Ó^ó8
Ðö Ø×#Ñ# LÔ1à×7 >×#7Ñ#7ˆäò 
Ù!ð
á-ð
ð -×4°øð
ñ (ð	
ñ
  ð
ð ×,˜×,Ñ,øð
ð $×A ~×'AÑ'Aøð
ô 0ØFT×Fc×Fc””] N×$AÑ$AÔBÐimØôð
ô -¨W°nÔEð
ñ  2ð
ñ ð
ñ ð
ñ  0ð!
ð" *6Ñ)A™À~×GbÑGbøð#
ð$ "*Ñ!5‘X¸>×;RÑ;Røð%
ð& *6Ñ)A™À~×GbÑGbøð'
ñ( ,ð)
ñ* *ð+
ˆð. ˆr°   )Úfmtr«  r   r^  r  r_  r%  ra  r"  r  rb  r¥   rc  rd  r0  r$  re  rf  rg  c               ó   • g r¼   r§   )r­  Úpathr¿  r«  r   r^  r  r_  r%  ra  r"  r  rb  r¥   rc  rd  r0  r$  re  rf  rg  s                        r±   Ú	from_fileÚAgent.from_fileô  s   € ð2 !r°   c               ó   • g r¼   r§   )r­  rÁ  r¿  r`  r«  r   r^  r  r_  r%  ra  r"  r  rb  r¥   rc  rd  r0  r$  re  rf  rg  s                         r±   rÂ  rÃ    s   € ð4 r°   )r¿  r`  r«  r   r^  r  r_  r%  ra  r"  r  rb  r¥   rc  rd  r0  r$  re  rf  rg  c               ór   • [         R                  " XS9nU R                  UUUUUUUU	U
UUUUUUUUUUUS9nU$ )a`  Construct an Agent from a YAML or JSON spec file.

This is a convenience method equivalent to
`Agent.from_spec(AgentSpec.from_file(path), ...)`.

The file format is inferred from the extension (`.yaml`/`.yml` or `.json`)
unless overridden with the `fmt` argument.

All other arguments are forwarded to [`from_spec`][pydantic_ai.agent.Agent.from_spec].
)r¿  r²  )r�   rÂ  r¯  )r­  rÁ  r¿  r`  r«  r   r^  r  r_  r%  ra  r"  r  rb  r¥   rc  rd  r0  r$  re  rf  rg  r®  r¾  s                           r±   rÂ  rÃ  +  sk   € ôH ×"Ò" 4Ñ1ˆØ—‘ØØØ$;ØØ#Ø%Ø'ØØ#Ø)ØØ1ØØØ/Ø%ØØ%Ø+Ø%ð) ð 
ˆð, ˆr°   Tc                ó   • U [         l        g)ziSet the instrumentation options for all agents that don't explicitly add an `Instrumentation` capability.N)rŸ   r6  )Ú
instruments    r±   Úinstrument_allÚAgent.instrument_allh  s   € ð %/ŒÕ!r°   c                ó   • U R                   $ )z/Instrumentation settings applied to this agent.©r5  rY  s    r±   rÇ  ÚAgent.instrumentm  s   € ð ×ÑÐr°   c                ó   • Xl         g r¼   rË  ©rZ  r  s     r±   rÇ  rÌ  r  s   € à Õr°   c                ó   • U R                   $ )z,The default model configured for this agent.©r,  rY  s    r±   r   ÚAgent.modelv  s   € ð �{‰{Ðr°   c                ó   • Xl         g)z‚Set the default model configured for this agent.

We allow `str` here since the actual list of allowed models changes frequently.
NrÐ  rÎ  s     r±   r   rÑ  {  s	   € ð �r°   c                ót   • U R                   R                  5       nU(       a  UR                  $ U R                  $ )z…The name of the agent, used for logging.

If `None`, we try to infer the agent name from the call frame when the agent is first run.
)rt  r  r  r-  )rZ  Úname_s     r±   r%  Ú
Agent.nameƒ  s-   € ð ×#Ñ#×'Ñ'Ó)ˆÞ#ˆu�{‰{Ð3¨¯©Ð3r°   c                ó   • Xl         g)z,Set the name of the agent, used for logging.N)r-  rÎ  s     r±   r%  rÕ  Œ  s	   € ð �
r°   c                óH   • U R                   c  g[        U R                   5      $ )z½A human-readable description of the agent.

If the description is a TemplateStr, returns the raw template source.
The rendered description is available at runtime via OTel span attributes.
N)r/  r	  rY  s    r±   ra  ÚAgent.description‘  s$   € ð ×ÑÑ$ØÜ�4×$Ñ$Ó%Ð%r°   c                ó   • Xl         g)z!Set the description of the agent.N)r/  rÎ  s     r±   ra  rØ  œ  s
   € ð "Õr°   c                óª   • U R                   c  g[        U R                   [        5      (       a  U R                   R                  U5      $ U R                   $ )zLReturn the agent description, rendering any TemplateStr with the given deps.N)r/  ró   rc   Úrender)rZ  Údepss     r±   Úrender_descriptionÚAgent.render_description¡  sG   € à×ÑÑ$ØÜ�d×'Ñ'¬×5Ñ5Ø×$Ñ$×+Ñ+¨DÓ1Ð1Ø× Ñ Ð r°   c                ó   • U R                   $ )z+The type of dependencies used by the agent.)r<  rY  s    r±   r`  ÚAgent.deps_type©  s   € ð �‰Ðr°   c                ó   • U R                   $ )zjThe type of data output by agent runs, used to validate the data returned by the model, defaults to `str`.)r3  rY  s    r±   r^  ÚAgent.output_type®  s   € ð × Ñ Ð r°   c                ó   • U R                   $ )zcOptional handler for events from the model's streaming response and the agent's execution of tools.)rP  rY  s    r±   Úevent_stream_handlerÚAgent.event_stream_handler³  s   € ð ×)Ñ)Ð)r°   c                ó   • U R                   $ )a  The Pydantic validation context used to validate tool arguments and outputs.

Set this when validators need values from [`ValidationInfo.context`][pydantic.ValidationInfo.context].
A callable can build the context from the current [`RunContext`][pydantic_ai.tools.RunContext].
©rN  rY  s    r±   rb  ÚAgent.validation_context¸  s   € ð ×'Ñ'Ð'r°   c                ó   • U R                   $ r¼   rç  rY  s    r±   Ú_get_validation_contextÚAgent._get_validation_contextÁ  s   € Ø×'Ñ'Ð'r°   c                ó¾   • [        U 5      R                   SU R                  < SU R                  < SU R                  < SU R
                  < SU R                  < S3$ )Nz(model=z, name=z, end_strategy=z, model_settings=z, output_type=Ú))Útyper©   r   r%  r0  r"  r^  rY  s    r±   Ú__repr__ÚAgent.__repr__Ä  s�   € Ü�t“*×%Ñ%Ð& g¨d¯j©j©^¸7À4Ç9Á9Á-ÈÐ_c×_pÑ_pÑ^sð  tEð  FJ÷  FYñ  FYñ  E\ð  \jð  ko÷  k{ñ  k{ñ  j~ð  ~ð  @ð  	@r°   )r^  Úmessage_historyÚdeferred_tool_resultsÚconversation_idÚrun_idr   r  rÜ  r"  Úusage_limitsÚcancellation_tokenr2   r$  r  Ú
infer_namerc  rg  r®  c               ó   • g r¼   r§   ©rZ  Úuser_promptr^  rñ  rò  ró  rô  r   r  rÜ  r"  rõ  rö  r2   r$  r  r÷  rc  rg  r®  s                       r±   ÚiterÚ
Agent.iterÇ  s	   € ð. JMr°   )rñ  rò  ró  rô  r   r  rÜ  r"  rõ  rö  r2   r$  r  r÷  rc  rg  r®  c               ó   • g r¼   r§   rù  s                       r±   rû  rü  à  s	   € ð. MPr°   c              óh  #   • U(       a1  U R                   c$  U R                  [        R                  " 5       5        U R	                  UUUUUUUUU	U
UUUUUUUUS9I Sh  v•N nUR                  5        ISh  v•N nU7v •  SSS5      ISh  v•N   g N3 N N	! , ISh  v•N  (       d  f       g= f7f)a€  A contextmanager which can be used to iterate over the agent graph's nodes as they are executed.

This method builds an internal agent graph (using system prompts, tools and output schemas) and then returns an
`AgentRun` object. The `AgentRun` can be used to async-iterate over the nodes of the graph as they are
executed. This is the API to use if you want to consume the outputs coming from each LLM model response, or the
stream of events coming from the execution of tools.

The `AgentRun` also provides methods to access the full message history, new messages, and usage statistics,
and the final result of the run once it has completed.

For more details, see the documentation of `AgentRun`.

Example:
```python
from pydantic_ai import Agent

agent = Agent('openai:gpt-5.2')

async def main():
    nodes = []
    async with agent.iter('What is the capital of France?') as agent_run:
        async for node in agent_run:
            nodes.append(node)
    print(nodes)
    '''
    [
        UserPromptNode(
            user_prompt='What is the capital of France?',
            instructions_functions=[],
            system_prompts=(),
            system_prompt_functions=[],
            system_prompt_dynamic_functions={},
        ),
        ModelRequestNode(
            request=ModelRequest(
                parts=[
                    UserPromptPart(
                        content='What is the capital of France?',
                        timestamp=datetime.datetime(...),
                    )
                ],
                timestamp=datetime.datetime(...),
                run_id='...',
                conversation_id='...',
            )
        ),
        CallToolsNode(
            model_response=ModelResponse(
                parts=[TextPart(content='The capital of France is Paris.')],
                usage=RequestUsage(
                    cost=Decimal('0.000196'), input_tokens=56, output_tokens=7
                ),
                model_name='gpt-5.2',
                timestamp=datetime.datetime(...),
                run_id='...',
                conversation_id='...',
            )
        ),
        End(data=FinalResult(output='The capital of France is Paris.')),
    ]
    '''
    print(agent_run.result.output)
    #> The capital of France is Paris.
```

Args:
    user_prompt: User input to start/continue the conversation.
    output_type: Custom output type to use for this run, `output_type` may only be used if the agent has no
        output validators since output validators would expect an argument that matches the agent's output type.
    message_history: History of the conversation so far.
    deferred_tool_results: Optional results for deferred tool calls in the message history.
    conversation_id: ID of the conversation this run belongs to. Pass `'new'` to start a fresh conversation, ignoring any `conversation_id` already on `message_history`. If omitted, falls back to the most recent `conversation_id` on `message_history` or a freshly generated UUID7.
    run_id: Optional ID for this agent run. Unlike `conversation_id`, never inherited from `message_history`. Passing an empty string, or a value that already appears on `message_history`, raises `UserError` because both break `new_messages()`; use `conversation_id` to correlate across turns or deferred-tool resume. If omitted, a fresh UUID7 is generated.
    model: Optional model to use for this run, required if `model` was not set when creating the agent.
    instructions: Optional additional instructions to use for this run.
    deps: Optional dependencies to use for this run.
    model_settings: Optional settings to use for this model's request, or a callable
        that receives [`RunContext`][pydantic_ai.tools.RunContext] and returns settings.
        Callables are called before each model request, allowing dynamic per-step settings.
    usage_limits: Optional limits on model request count or token usage.
    cancellation_token: Token used to cancel this run from another task or thread. Single-use:
        mint a fresh token per run, as a reused (already-cancelled) token prevents the run from starting.
    usage: Optional usage to start with, useful for resuming a conversation or agents used in tools.
    metadata: Optional metadata to attach to this run. Accepts a dictionary or a callable taking
        [`RunContext`][pydantic_ai.tools.RunContext]; merged with the agent's configured metadata.
    retries: Override the agent-level retry budgets for this run. Pass an `int` to override both
        the tool-retry and output budgets, or an [`AgentRetries`][pydantic_ai.AgentRetries] dict to
        override just one (e.g. `retries={'tools': 3}`). See
        [`Agent.__init__`][pydantic_ai.agent.Agent.__init__] for semantics of the two enforcement paths.
    infer_name: Whether to try to infer the agent name from the call frame if it's not set.
    toolsets: Optional additional toolsets for this run.
    capabilities: Optional additional [capabilities](https://pydantic.dev/docs/ai/capabilities/overview/) for this run, merged with the agent's configured capabilities.
    spec: Optional agent spec to apply for this run. At run time, spec values are additive.

Returns:
    The result of the run.
N©r^  rñ  rò  ró  rô  r   r  rÜ  r"  rõ  rö  r2   r$  r  rc  rg  r®  )r%  Ú_infer_nameÚinspectÚcurrentframeÚ_prepare_runÚopen)rZ  rú  r^  rñ  rò  ró  rô  r   r  rÜ  r"  rõ  rö  r2   r$  r  r÷  rc  rg  r®  ÚpreparedÚ	agent_runs                         r±   rû  rü  ù  s¨   é € ör ˜$Ÿ)™)Ñ+Ø×ÑœW×1Ò1Ó3Ô4à×*Ñ*ØØ#Ø+Ø"7Ø+ØØØ%ØØ)Ø%Ø1ØØØØØ%Øð% +ð 
÷ 
ˆð( —=‘=—?”? iØ‹O÷ #—?�?ñ)
÷( #—?—?’?üsZ   ‚AB2ÁBÁB2Á7BÁ8B2Á;BÂB2ÂBÂB2ÂB2ÂB2ÂB/ÂB!ÂB/Â+B2rÿ  c             ƒ  ó  ^ ^O^P^Q^R^S^T^U^V^W^X^Y^Z#   • [        5       nUb  UR                  O	[        5       n[        U5      nT R	                  5       u  nnT R                  U5      nUR                  S5      nUR                  S5      nUGb-  Uc  UR                  b  UR                  nUc  UR                  b  UR                  nUc  UR                  b  UR                  nUR                  (       a;  UR                  nUb*  [        R                  " U5      nUR                  U5        UnOUnUR                  b)  U
b  [        U
5      (       d  [!        UR                  U
5      n
UR"                  bJ  Ub;  [        U5      (       a  UR"                  mPUmOSLUOUP4S jjnUnO0 UR"                  EUEnOUR"                  nT R$                  R                  5       nUb  UR&                  nT R)                  U5      nT R+                  U	5      n	U=(       d    [,        R.                  " 5       n/ n Ub(  UR0                  b  U R3                  UR0                  5        U R                  [5        U5      5        T R7                  U 5      n U/U Qn![9        U!5      S:”  a  [;        U!5      mROU!S   mR0 mWUS L=(       d    T R<                  R                  5       S Ln"U"(       a  S OTRR?                  5       n#T RA                  U#U5        T RC                  U5      n$S n%S n&S n'U$(       aF  T RE                  U5      n([G        U([H        5      (       a  U(OS n%U%n&T RK                  U(TRU	TWS9I S h  v•N n'U#bI  [L        RN                  " T U	U'SU(       a  [Q        U5      O/ US9n)T RS                  U#TRU)TWS9I S h  v•N u  n*n%OU'b  U'n*O[T        RV                  " S	5      eAT RY                  U5      n+U=(       d    T RZ                  mUT R\                  n,Ub  UOT R^                  n-T R`                  n.U+T Rb                  :w  d  U,(       aO  U+Rd                  n.U.(       a;  U.T R`                  L a  Ub  [g        U.5      n.U.Rh                  b  Ub  U-U.l4        U,U.l5        OU.b  Ub  [g        U.5      n.U-U.l4        [l        Rn                  " T Rp                  T Rr                  TU5      n/[l        Rt                  " U(       a  [Q        U5      O/ USS[l        Rv                  " Xc5      [l        Rx                  " XS5      S
9n0T Rz                  R                  5       n1U1b  U1R&                  OT R                  mQU1c  U
OS mYU*R|                  n2[        TQ5      (       d  [!        U2TQ5      n2[        TY5      (       d  [!        U2TY5      n2U2(       aG  U2R                  S5      n3U3S:X  d  [G        U3[P        5      (       a  [T        RV                  " SU3< S35      eU=(       d    [,        R~                  " 5       n[G        U*[€        5      (       a  U*R‚                  n4U*R„                  n*OT R‡                  5       n4U4b  U4Rˆ                  n5[‹        U4S9n6O[�        5       n5S n60 n70 n8[Ž        [�           " SM0 SU	_ST _SU7_SU8_SU*_SU%_SU_SU_SU_SU0R’                  _SU5_SU4S L=(       a    U4R”                  _SU4(       a  U4R–                  O[˜        _SS_SU0Rš                  _SU0Rœ                  _S U0Rž                  _S!U_6n9T R¡                  U9U5      U0l        U0R"                  U9l        T R£                  U9UU U6S"US#9I S h  v•N n:U:R¤                  mXU:R¦                  n;U:R                  n<U:R¨                  n=U:R                  mSU:Rª                  n>U:R¬                  mV[9        TV5      [9        U!5      -
  mT[¯        UTUV4S$ j[±        U!5       5       5      n?SNUQUSUY4S% jjn@T R³                  U.UU>TXU-S&9nAUARµ                  U95      I S h  v•N nA[¶        [�           " UATXUS'9nBT R¹                  UU<S(9mZ    SOUZ4S) jjnCU(       a  [»        UU;R½                  5       5      O[¾        [H           " 5       nDU(       a  [Á        U5      O[¾        [H           " 5       nEU"(       a  S OTXR?                  5       nFT RA                  UFU5        U?(       a0  [        U#5      (       a  [Ã        U#5      (       d  U#OS nGUGb  SOS nHU#S LnIOˆ[        WF5      (       a  [Ã        WF5      (       d  WFnGS nHS"nIOaWFb:  T RK                  WFTXU	TWS9I S h  v•N n*[G        WF[H        5      (       a  WFOS n%S nGS nHS"nIO$U'b  U'n*U&n%S nGS nHS*nIO[T        RV                  " S+5      e      SPUWUXU 4S, jjnJSQURUUU 4S- jjnK[Å        T RÆ                  Rg                  5       5      nL[l        RÈ                  [�        [Ê        4   " SM0 S.U	_ST _SU_S/U(       a  [9        U5      OS_S0S _S1S _SU*_S2U%_S3WG_S4WH_S5WJ_S6WLRÌ                  _S7W@_SU_S8U-_S9T RÎ                  _S:U+_S;U,_S<T RÐ                  _S=TX_S>U;_S?WD_S@WE_SAU7_SBU8_SCU=_SDWB_SEWK_SU5_SFWC_SGU4_SHU_6nM[l        RÒ                  [�           " UUS / T RÔ                  T RÖ                  T RØ                  SI9nN[Ú        [�        [Ü        4   " U/U0UMUNT Rp                  =(       d    SUUU*WIWLTXWAUT RÞ                  [à        Râ                  " T Rä                  USJ9SK9$  GN¨ GNc GNÇ GN
 GNá7f)RNr¦   r¥   c                ó.   >• 0 T=(       d    0 ET" U 5      E$ r¼   r§   )ÚctxÚ_orig_metadataÚ
_spec_metas    €€r±   Ú_merged_metaÚ(Agent._prepare_run.<locals>._merged_metaÙ  s   ø€ Ø#P z×'7°RÐ#P¹NÈ3Ó<OÐ#PÐPr°   rƒ   r   ©rú   rÜ  Úresolved_models©r¾  rÜ  r   Úrun_stepr0   r2   ©rú   r	  r  úD`model` must either be set on the agent or included when calling it.)rñ  r2   Úoutput_retries_usedr  rô  ró  Útool_choiceÚrequiredz`tool_choice=aI  ` prevents the agent from producing a final response because output tools are excluded. Use `ToolOrOutput` to combine specific function tools with output capability, return a callable from a capability's `get_model_settings()` to vary `tool_choice` per step, or use `pydantic_ai.direct.model_request` for single-shot model calls.©ÚsettingsrÜ  r¾  Ú_durable_operationsræ   r   Ú	_model_idr2   rõ  Úpromptr0   ÚtracerÚtrace_include_contentÚinstrumentation_versionr  Úpending_messagesrô  ró  Ú_cancellationT©Úbase_capabilityÚextra_capabilitiesÚinstrumentation_capÚinject_deferred_loaderÚbase_is_overridec              3  ó<   >#   • U  H  u  pTTU-      UL v •  M     g 7fr¼   r§   )Ú.0ÚindexÚlayerÚmodel_layer_startÚresolved_layerss      €€r±   Ú	<genexpr>Ú%Agent._prepare_run.<locals>.<genexpr>Î  s'   øé € ð %
ÚTkÁLÀEˆOÐ-°Ñ5Ñ6¸%Õ?ÒTkùs   ƒc                ó’   >• U R                   n[        U TTT4[        U[        R                  5      (       a  UR
                  S9$ S S9$ )N©Úbase)r   Ú_layer_model_settingsró   r1   r  r  )Úrun_contextÚ
step_modelÚagent_model_settingsÚcap_model_settingsÚrun_model_settingss     €€€r±   r¤  Ú.Agent._prepare_run.<locals>.get_model_settingsÕ  sV   ø€ ð %×*Ñ*ˆJÜ(ØØ%Ð'9Ð;MÐNÜ,6°zÄ6Ç<Á<×,PÑ,P�Z×(Ñ(ñð ð W[ñð r°   )Úoutput_toolsetÚadditional_toolsetsÚcap_toolsetsrÌ   Úmax_output_retries©Úroot_capabilityÚdefault_max_retries©Úadditional_instructionsÚcap_instructionsc              “  ó`   >#   • [         R                  " TU 5      I S h  v•N =(       d    S $  N7fr¼   )r*   Úresolve_sourced_instructions)r3  Úsourced_instructionss    €r±   Úget_instructionsÚ,Agent._prepare_run.<locals>.get_instructionsõ  s)   øé € ô '×CÒCÐDXÐZeÓf×f×nÐjnÐnÑfùs   ƒ.ž,Ÿ.Fz[A capability removed the bootstrap model in `for_run()` but the agent has no default model.c              “  óD   >#   • TR                  U TUTS9I S h  v•N $  N7f)Nr  )Ú_evaluate_model_contribution)ÚselectorÚselection_ctxÚresolved_models_by_selectionrÌ   rZ  s     €€€r±   Úevaluate_model_selectorÚ3Agent._prepare_run.<locals>.evaluate_model_selector.  s6   øé € ð ×:Ñ:ØØ)Ø!Ø <ð	 ;ð ÷ ð ñ ùs   ƒ ™š c           	     ó\   >• [         R                  " TR                  U TU[        T5      S9  g )N)r%  r   r^  r¥   rg  )r(   Údisplay_agent_bannerr%  Ú_registered_capability_count)r   r¥   Úbootstrap_capabilityÚoutput_type_rZ  s     €€€r±   Údisplay_bannerÚ*Agent._prepare_run.<locals>.display_banner8  s,   ø€ ô ×)Ò)Ø—Y‘YØà(ØÜ9Ð:NÓOór°   Ú	user_depsÚnew_message_indexÚresumed_requestÚresumed_request_indexÚmodel_idÚmodel_selectorÚmodel_selected_for_steprM  Úenter_modelr¤  r<  r0  rr  Úoutput_validatorsrb  r>  rg  Úloaded_capability_idsÚdiscovered_tool_namesÚdurable_operationsrû   Únative_toolsÚtool_managerrT  rF  Úinstrumentation_settingsÚcancellation)rú  rò  r  Úinstructions_functionsÚsystem_promptsÚsystem_prompt_functionsÚsystem_prompt_dynamic_functions)r$  )ÚgraphÚstateÚ
graph_depsÚuser_prompt_nodeÚ
agent_nameÚbindingrö  r   Úcapability_owns_current_modelÚmodel_resourcesrÌ   r�  rõ  Úconcurrency_limiterÚresolve_metadata)r	  úRunContext[AgentDepsT]rà   údict[str, Any]r§   )r3  rt  rà   r!  )r3  rt  rà   z&list[_messages.InstructionPart] | None)rJ  zModelSelector[AgentDepsT]rK  ú(models.ModelSelectionContext[AgentDepsT]rà   útuple[models.Model, str | None])r   r	  r¥   r¤   rà   râ   )sr<   re  r;   r  Ú_base_run_capabilityÚ_resolve_specr  r   r'  r(  r  r*   r‹  rµ  r"  Úcallablerb   r$  r}  r  Ú_resolve_tool_retriesÚ	_get_depsÚ_usageÚRunUsagerú   rï   rK   Ú_bind_run_capabilitiesr“  rG   rv  Ú	get_modelÚ_check_dynamic_model_resumeÚ
_has_modelÚ_pick_raw_modelró   r	  Ú_resolve_model_selectionr1   ÚModelSelectionContextr‘  rI  r/   rŽ  Ú_prepare_output_schemar^  r?  rI  rF  r>  r�  r   rp  r^  r'   Úbuild_agent_graphr%  r<  ÚGraphAgentStateÚresolve_run_idÚresolve_conversation_idr|  r  ÚUsageLimitsrY   rd  ÚwrappedÚ!_resolve_instrumentation_settingsr  ÚInstrumentationCapr   rm   rf   rñ  Úinclude_contentÚversionr#   r  rô  ró  Ú_get_metadataÚ_resolve_run_capabilitiesrÌ   rg  rb  rc  r,  ÚallÚ	enumerateÚ_get_toolsetÚfor_runre   Ú_get_instructionsr=   ÚkeysrÀ   r}   r  Ú_RunModelResourcesr—  ÚGraphAgentDepsr\   r]  r0  rN  r6   rB  rC  rD  Ú_PreparedAgentRunr   rR  Ú	functoolsÚpartialÚ_resolve_and_store_metadata)[rZ  rú  r^  rñ  rò  ró  rô  r   r  rÜ  r"  rõ  rö  r2   r$  r  rc  rg  r®  ro  re  r¦  r"  r&  ÚresolvedÚeffective_output_retriesÚeffective_tool_retriesÚextrarü   r  Úoverride_output_retriesÚeffective_tool_retries_resolvedr#  Úmodel_layersÚmodel_is_explicitÚmodel_contributionÚhas_default_modelrZ  Údefault_model_idÚdefault_modelÚ	raw_modelrK  Ú
model_usedrr  r^  Ú$effective_output_toolset_max_retriesr9  rj  rk  Úmodel_settings_overrideÚbaseline_settingsr  rd  r  r$  ra  rû   Úinitial_ctxÚresolved_capsÚcapabilities_dictrB  Úcap_native_toolsr;  Úmodel_layers_unchangedr¤  r�  rc  rF  r_  r`  Úrun_model_contributionr[  r\  rp  rM  rT  rq  rl  rm  r
  r  r5  rR  r6  r+  rS  r,  rL  rÌ   r7  rE  s[   `                                                                              @@@@@@@@@@@@r±   r  ÚAgent._prepare_runŒ  s¦  ÿüé € ô2 #Ó$ˆð 07Ñ/B�w×+Ò+ÌÓHYˆô ;¸7ÓCˆð -1×,EÑ,EÓ,GÑ)ˆÐ)ð ×%Ñ% dÓ+ˆà#2×#6Ñ#6°xÓ#@Ð Ø!0×!4Ñ!4°WÓ!=ÐØÒà‰} §¡Ñ!;Ø Ÿ™�à'Ñ/°H×4KÑ4KÑ4WØ+3×+BÑ+BÐ(à%Ñ-°(×2GÑ2GÑ2SØ)1×)>Ñ)>Ð&à×$×$Ø ×-Ñ-�ØÑ+Ü,×CÒCÀLÓQ�HØ—O‘O EÔ*Ø#+‘Là#(�Là×&Ñ&Ñ2Ø!Ñ)´¸.×1IÑ1IÜ%9¸(×:QÑ:QÐSaÓ%b�Nð × Ñ Ñ,ØÑ'Ü ×)Ñ)Ø%-×%6Ñ%6˜
Ø)1˜÷Qð Qð $0™à#D h×&7Ñ&7Ð#D¸8Ð#D™à'×0Ñ0�Hð #'×"?Ñ"?×"CÑ"CÓ"EÐØ"Ñ.Ø'>×'DÑ'DÐ$Ø*.×*DÑ*DÐE[Ó*\Ð'à�~‰~˜dÓ#ˆØ×*œŸšÓ*ˆð
 DFÐØÑ H×$7Ñ$7Ñ$CØ×%Ñ% h×&9Ñ&9Ô:Ø×!Ñ!Ô"7¸Ó"EÔFØ!×8Ñ8Ð9KÓLÐØ>MÐ=cÐPbÐ=cˆäˆ|Ó˜qÓ Ü#5°lÓ#CÑ à#/°¡?Ð ØLNÐ$ð
 "¨Ð-×W°×1EÑ1E×1IÑ1IÓ1KÐSWÐ1WÐÞ%6™TÐ<P×<ZÑ<ZÓ<\ÐØ×(Ñ(Ð);¸_ÔMà ŸO™O¨EÓ2Ðð  $ˆØ'+ÐØ-1ˆÞØ×,Ñ,¨UÓ3ˆIÜ$.¨y¼#×$>Ñ$>‘yÀDˆHØ'ÐØ"&×"?Ñ"?ØØ/ØØ <ð	 #@ð #÷ ˆMð Ñ)Ü"×8Ò8ØØØ#ØÞ2Aœ˜oÔ.ÀrØñˆMð *.×)JÑ)JØ"Ø/Ø!Ø <ð	 *Kð *÷ $Ñ ˆJ™ð Ñ&Ø&‰Jä×&Ò&Ð'mÓnÐnØØ×3Ñ3°KÓ@ˆà"×6 d×&6Ñ&6ˆð
 !×3Ñ3Ðð )AÑ(LÑ$ÐRV×RjÑRjð 	-ð ×-Ñ-ˆØ˜D×/Ñ/Ó/Ö3DØ*×2Ñ2ˆNÞð " T×%9Ñ%9Ò9Ð>VÑ>bÜ%)¨.Ó%9�NØ!×-Ñ-Ñ5Ð9QÑ9]Ø1U�NÔ.Ø3D�Ô0øØÑ'Ð,DÑ,Pô " .Ó1ˆNØ)MˆNÔ&ô ×.Ò.¨t¯y©y¸$¿/¹/È<ÓXˆô ×,Ò,Þ5DœD Ô1È"ØØ !ØÜ×.Ò.¨vÓGÜ(×@Ò@ÀÓbñ
ˆð #'×"?Ñ"?×"CÑ"CÓ"EÐà-DÑ-PÐ#×)Ò)ÐVZ×ViÑVið 	ð 0GÑ/N™^ÐTXÐð 3=×2EÑ2EÐÜÐ,×-Ñ-Ü 4Ð5FÐH\Ó ]ÐÜÐ*×+Ñ+Ü 4Ð5FÐHZÓ [ÐÞØ+×/Ñ/°Ó>ˆKØ˜jÓ(¬J°{ÄD×,IÑ,IÜ ×*Ò*Ø# K¡?ð 3Vð Wóð ð $×;¤v×'9Ò'9Ó';ˆô �jÔ"3×4Ñ4ØGQ×GjÑGjÐ$Ø#×+Ñ+‰Jà'+×'MÑ'MÓ'OÐ$à#Ñ/Ø-×4Ñ4ˆFÜ=OÐYqÑ=rÑä“\ˆFØ"&Ðð TVÐØLNÐô
 !¤Ò,ò 
Ùð
áð
ñ !3ð
ñ %;ð	
ñ
 ð
ñ ð
ñ ð
ñ &ð
ñ ð
ð ×*Ò*ð
ñ ð
ð #;À$Ð"F×"sÐKc×KsÑKsøð
ö (ð %=×$DÒ$Dä0øð
ñ  ð!
ð" #×3Ò3ð#
ð$ —<’<ð%
ð& "×1Ò1ð'
ñ( 'ð)
ˆð< ×+Ñ+¨K¸ÓBˆŒØ$Ÿ~™~ˆÔð #×<Ñ<ØØ+Ø1Ø 3Ø#'Ø-ð =ð 
÷ 
ˆð '×5Ñ5ˆØ)×6Ñ6ÐØ(×5Ñ5ÐØ(×5Ñ5ÐØ*×9Ñ9ÐØ$×-Ñ-ˆð
 (×7Ñ7ˆÜ Ó0´3°|Ó3DÑDÐÜ!$õ %
ÜT]Ð^jÔTkó%
ó "
Ð÷	ñ 	ð ×#Ñ#Ø)Ø (Ø%Ø)ØCð $ð 
ˆð  Ÿ™¨Ó4×4ˆÜ"¤:Ò.Ø ^ÐIhñ
ˆð
  $×5Ñ5Ø$0Ø-ð  6ð  
Ðð
	oØ/ð	oà3÷	oö ô -¨_Ð>O×>TÑ>TÓ>VÔWä”S’“ð 	ö
 L[Ô 6°Ô GÔ`cÔdgÒ`hÓ`jÐæ):¡À×@XÑ@XÓ@ZÐØ×(Ñ(Ð)?ÀÔQö "ä&.Ð/A×&BÑ&BÌ9ÐUg×KhÑKhÑ"Ðnrð ð ,:Ñ+E¡aÈ4Ð#Ø,>ÀdÐ,JÑ)ÜÐ,×-Ñ-´iÐ@V×6WÑ6Wð 4ˆNØ&*Ð#Ø,0Ñ)Ø#Ñ/Ø#×<Ñ<Ø&Ø)ØØ <ð	  =ð  ÷ ˆJô 2<Ð<RÔTW×1XÑ1XÑ-Ð^bˆHØ!ˆNØ&*Ð#Ø,0Ñ)ØÑ&Ø&ˆJà'ˆHØ!ˆNØ&*Ð#Ø,1Ñ)ä×&Ò&Ømóð ð	Ø/ð	Ø@hð	à,÷	ñ 	÷	ñ 	ô -¨T×-DÑ-D×-IÑ-IÓ-KÓLˆÜ!×0Ñ0´¼[Ð1HÒIò !
Ùð!
áð!
ñ ð!
ö 7Fœc /Ô2È1øð	!
ñ
 !ð!
ñ #'ð!
ñ ð!
ñ ð!
ñ *ð!
ñ %<ð!
ñ %<ð!
ð (×3Ò3ð!
ñ  2ð!
ñ &ð!
ñ  Dð!
ð  ×*Ò*ð!!
ñ" (ð#!
ñ$ 0ð%!
ð&  $×7Ò7ð'!
ñ( +ð)!
ñ* +ð+!
ñ, #8ð-!
ñ. #8ð/!
ñ0  2ð1!
ñ2 $:ð3!
ñ4 *ð5!
ñ6 &ð7!
ñ8 *ð9!
ñ: ð;!
ñ< .ð=!
ñ> &>ð?!
ñ@ &ðA!
ˆ
ôF (×6Ñ6´zÒBØ#Ø"7ØØ#%Ø×/Ñ/Ø$(×$AÑ$AØ,0×,QÑ,Qñ
Ðô !¤¬S Ò1ØØØ!Ø-Ø—y‘y×+ GØØ1ØØ*GØ+Ø)ØØ%Ø $× 9Ñ 9Ü&×.Ò.¨t×/OÑ/OÐZbÑcñ
ð 	
òCò$òr
ò` 5ò\ùs_   �L?lÍk6ÍAlÎk9ÎNlÜ5k<Ü6B?lß5k?ß6D+lä!lä"Glë9lë<lë?lìlc                ó  • U R                   R                  5       nUb  U R                  UR                  U5      $ U R                  U R                  U5      nU R                  X!5      nU(       a  U(       a  0 UEUE$ U=(       d    U$ r¼   )r{  r  Ú_resolve_metadata_configr  r:  )rZ  r	  Úadditional_metadataÚmetadata_overrideÚbase_metadataÚrun_metadatas         r±   r‘  ÚAgent._get_metadata…  s€   € ð
 !×3Ñ3×7Ñ7Ó9ÐØÑ(Ø×0Ñ0Ð1B×1HÑ1HÈ#ÓNÐNà×5Ñ5°d·n±nÀcÓJˆØ×4Ñ4Ð5HÓNˆæž\Ø4�mÐ4 |Ð4Ð4Ø×,˜}Ð,r°   c                óF   • Uc  g [        U5      (       a
  U" U5      nU$ UnU$ r¼   )rz  )rZ  Úconfigr	  r$  s       r±   r¸  ÚAgent._resolve_metadata_config•  s0   € ð
 ‰>ØÜ"*¨6×"2Ñ"2‘6˜#“;ˆØˆð 9?ˆØˆr°   c                ó^   • [        U5      nU R                  X25      nXAR                  l        U$ r¼   )r7   r‘  rk  r$  )rZ  Úgraph_run_ctxr$  r3  Úresolved_metadatas        r±   rž  Ú!Agent._resolve_and_store_metadataŸ  s1   € ô
 (¨Ó6ˆØ ×.Ñ.¨{ÓEÐØ'8×ÑÔ$Ø Ð r°   c                ó¶  • Uc  g[        XR                  5      u  p4[        [        X2U5      5      nU(       a  [	        U5      OSn[        U5      n[         HY  n[        U5      R                  U   n	UR                  U   U	R                  :w  d  M:  [        R                  " SU< S3[        SS9  M[     [        UUR                  (       a   [         R"                  " UR                  5      O/ UR$                  UR&                  (       a  [)        [*        UR&                  5      OSUR,                  UR.                  UR1                  S5      UR1                  S5      S9$ )	zkValidate and instantiate capabilities from a spec, returning contributions.

Returns None if spec is None.
NzAgentSpec field z: is not supported at run/override time and will be ignoredé   )Ú
stacklevelr¦   r¥   )rú   r  r   r"  r$  r%  r'  r(  )r´  r<  r‘  r¶  rG   Ú_retry_overrides_from_specÚ_UNSUPPORTED_SPEC_FIELDSrî  Úmodel_fieldsÚ__dict__r  ÚwarningsÚwarnÚUserWarningr  r  r*   r‹  r   r"  r   ra   r$  r%  r  )
rZ  r®  r«  r¸  r¹  rg  r¥  r¦  Ú
field_nameÚ
field_infos
             r±   ry  ÚAgent._resolve_spec©  s+  € ð ‰<Øä+9¸$ÇÁÓ+PÑ(ˆäÔ3°NÐ]mÓnÓoˆÞ7CÔ% lÔ3Èˆä4°^ÓDˆ÷ 3ˆJÜ˜nÓ-×:Ñ:¸:ÑFˆJØ×&Ñ& zÑ2°j×6HÑ6HÕHÜ—’Ø& z¡nÐ4nÐoÜØ ôñ 3ô Øà×*×*ô '×=Ò=¸n×>YÑ>YÔZàØ ×&Ñ&à×,×,ô  ¤¨~×/LÑ/LÔMàØ#×,Ñ,Ø×$Ñ$Ø*×.Ñ.¨xÓ8Ø(×,Ñ,¨WÓ5ñ
ð 	
r°   )r%  rÜ  r   rc  r¥   rb  r  r$  r"  r  r®  c             #  ól  #   • [         R                  " U
5      (       aL  [        U
5      nUR                  S[         R                  5      nUR                  S[         R                  5      nO [         R                  n[         R                  nU R                  U5      nUbR  UR                  bE  [        UR                  R                  5      n[        U5        [        U5      R                  U 5      nOSnUGbp  [         R                  " U5      (       d  UR                  b  UR                  n[         R                  " U5      (       d  UR                  b  UR                  n[         R                  " U5      (       d  UR                  (       a  UR                  n[         R                  " U	5      (       d  UR                  b  UR                  n	[         R                  " U5      (       d  UR                   b  UR                   n[         R                  " U5      (       d  UR"                  b  UR"                  n[         R                  " U5      (       d  UR$                  b  UR$                  n[         R                  " U5      (       a0  U R&                  R)                  [         R*                  " U5      5      nOSn[         R                  " U5      (       a0  U R,                  R)                  [         R*                  " U5      5      nOSn[         R                  " U5      (       a‡  U=(       d    U R/                  5       n[1        U[2        5      (       a  UR4                  (       a  UO[6        R8                  " U5      nU R:                  R)                  [         R*                  " U5      5      nOSn[         R                  " U5      (       a0  U R<                  R)                  [         R*                  " U5      5      nOSn[         R                  " U5      (       a0  U R>                  R)                  [         R*                  " U5      5      nOSn[         R                  " U5      (       a0  U R@                  R)                  [         R*                  " U5      5      nOSn[         R                  " U5      (       aF  [B        RD                  " U5      nU RF                  R)                  [         R*                  " U5      5      nOSn[         R                  " U5      (       a0  U RH                  R)                  [         R*                  " U5      5      nOSn[         R                  " U	5      (       a0  U RJ                  R)                  [         R*                  " U	5      5      nOSn[         R                  " U5      (       a0  U RL                  R)                  [         R*                  " U5      5      nOSn[         R                  " U5      (       a0  U RN                  R)                  [         R*                  " U5      5      nOSnUb0  U RP                  R)                  [         R*                  " U5      5      n OSn  Sv •  Ub  U R&                  RS                  U5        Ub  U R,                  RS                  U5        Ub  U R:                  RS                  U5        Ub  U R<                  RS                  U5        Ub  U R>                  RS                  U5        Ub  U R@                  RS                  U5        Ub  U RF                  RS                  U5        Ub  U RH                  RS                  U5        Ub  U RJ                  RS                  U5        Ub  U RL                  RS                  U5        Ub  U RN                  RS                  U5        U b  U RP                  RS                  U 5        gg! Ub  U R&                  RS                  U5        Ub  U R,                  RS                  U5        Ub  U R:                  RS                  U5        Ub  U R<                  RS                  U5        Ub  U R>                  RS                  U5        Ub  U R@                  RS                  U5        Ub  U RF                  RS                  U5        Ub  U RH                  RS                  U5        Ub  U RJ                  RS                  U5        Ub  U RL                  RS                  U5        Ub  U RN                  RS                  U5        U b  U RP                  RS                  U 5        f f = f7f)a½  Context manager to temporarily override agent configuration.

This is particularly useful when testing.
You can find an example of this [here](../testing.md#overriding-model-via-pytest-fixtures).

Args:
    name: The name to use instead of the name passed to the agent constructor and agent run.
    deps: The dependencies to use instead of the dependencies passed to the agent run.
    model: The model to use instead of the model passed to the agent run.
    toolsets: The toolsets to use instead of the toolsets passed to the agent constructor and agent run.
    tools: The tools to use instead of the tools registered with the agent.
    native_tools: The native tools to use instead of the agent's configured native tools.
    instructions: The instructions to use instead of the instructions registered with the agent.
        Note: this also replaces capability-contributed instructions (e.g. from
        [`get_instructions`][pydantic_ai.capabilities.AbstractCapability.get_instructions]).
    metadata: The metadata to use instead of the metadata passed to the agent constructor. When set, any
        per-run `metadata` argument is ignored.
    model_settings: The model settings to use instead of the model settings passed to the agent constructor.
        When set, any per-run `model_settings` argument is ignored.
    retries: The retry budgets to use instead of the agent-level configuration. Pass an `int` to
        override both the tool-retry and output budgets, or an [`AgentRetries`][pydantic_ai.AgentRetries]
        dict to override just one (e.g. `retries={'tools': 3}`).
        When set, any per-run `retries` argument is ignored.
    spec: Optional agent spec providing defaults for override. Explicit params take precedence
        over spec values. When the spec includes `capabilities`, they replace (not merge with)
        the agent's existing capabilities. To add capabilities without replacing, pass `spec`
        to `run()` or `iter()` instead.
r¦   r¥   N)*r-   rò   r  r  ÚUNSETry  rú   r‘  rg  r„  rG   Ú	for_agentr%  r   r  r"  r$  r'  r(  rt  rÀ   ÚSomeru  Ú_effective_root_capabilityró   r	  rž  r1   rŸ  rv  rw  rx  ry  r*   r‹  rz  r{  r|  r}  r~  r  rÓ   )!rZ  r%  rÜ  r   rc  r¥   rb  r  r$  r"  r  r®  r¦  r£  Úoverride_tool_retriesrŸ  Úoverride_capsÚoverride_capabilityÚ
name_tokenÚ
deps_tokenÚmodel_capabilityÚoverride_modelÚmodel_tokenÚtoolsets_tokenÚtools_tokenÚnative_tools_tokenÚnormalized_instructionsÚinstructions_tokenÚmetadata_tokenÚmodel_settings_tokenÚoutput_retries_tokenÚtool_retries_tokenÚ	cap_tokens!                                    r±   ÚoverrideÚAgent.overrideÖ  s  é € ôb �=Š=˜×!Ñ!Ü>¸wÓGˆOØ&5×&9Ñ&9¸(ÄFÇLÁLÓ&QÐ#Ø$3×$7Ñ$7¸ÄÇÁÓ$NÑ!ä&,§l¡lÐ#Ü$*§L¡LÐ!à×%Ñ% dÓ+ˆð
 Ñ H×$7Ñ$7Ñ$CÜ  ×!4Ñ!4×!AÑ!AÓBˆMÜ% mÔ4ÜI[Ð\iÓIj×ItÑItØóJÑð #'Ðð ÒÜ—=’= ×&Ñ&¨8¯=©=Ñ+DØ—}‘}�Ü—=’= ×'Ñ'¨H¯N©NÑ,FØ Ÿ™�Ü—=’= ×.Ñ.°8×3H×3HØ'×4Ñ4�Ü—=’= ×0Ñ0°X×5LÑ5LÑ5XØ!)×!8Ñ!8�Ü—=’= ×*Ñ*¨x×/@Ñ/@Ñ/LØ#×,Ñ,�Ü—=’=Ð!8×9Ñ9¸h×>UÑ>UÑ>aØ*2×*AÑ*AÐ'Ü—=’=Ð!6×7Ñ7¸H×<QÑ<QÑ<]Ø(0×(=Ñ(=Ð%ä�=Š=˜×ÑØ×,Ñ,×0Ñ0´·²¸TÓ1BÓC‰JàˆJä�=Š=˜×ÑØ×,Ñ,×0Ñ0´·²¸TÓ1BÓC‰JàˆJä�=Š=˜×ÑØ2×W°d×6UÑ6UÓ6WÐä# E¬3×/Ñ/Ð4D×4Y×4Y‘Ô_e×_qÒ_qÐrwÓ_xð ð ×.Ñ.×2Ñ2´6·;²;¸~Ó3NÓO‰KàˆKä�=Š=˜×"Ñ"Ø!×4Ñ4×8Ñ8¼¿ºÀXÓ9NÓO‰Nà!ˆNä�=Š=˜×ÑØ×.Ñ.×2Ñ2´6·;²;¸uÓ3EÓF‰KàˆKä�=Š=˜×&Ñ&Ø!%×!<Ñ!<×!@Ñ!@ÄÇÂÈ\ÓAZÓ![Ñà!%Ðä�=Š=˜×&Ñ&Ü&3×&JÒ&JÈ<Ó&XÐ#Ø!%×!<Ñ!<×!@Ñ!@ÄÇÂÐMdÓAeÓ!fÑà!%Ðä�=Š=˜×"Ñ"Ø!×4Ñ4×8Ñ8¼¿ºÀXÓ9NÓO‰Nà!ˆNä�=Š=˜×(Ñ(Ø#'×#@Ñ#@×#DÑ#DÄVÇ[Â[ÐQ_ÓE`Ó#aÑ à#'Ð ä�=Š=Ð0×1Ñ1Ø#'×#@Ñ#@×#DÑ#DÄVÇ[Â[ÐQhÓEiÓ#jÑ à#'Ð ä�=Š=Ð.×/Ñ/Ø!%×!<Ñ!<×!@Ñ!@ÄÇÂÐMbÓAcÓ!dÑà!%Ðð
 Ñ*Ø×6Ñ6×:Ñ:¼6¿;º;ÐGZÓ;[Ó\‰IàˆIð	@ÛàÑ%Ø×#Ñ#×)Ñ)¨*Ô5ØÑ%Ø×#Ñ#×)Ñ)¨*Ô5ØÑ&Ø×$Ñ$×*Ñ*¨;Ô7ØÑ)Ø×'Ñ'×-Ñ-¨nÔ=ØÑ&Ø×$Ñ$×*Ñ*¨;Ô7Ø!Ñ-Ø×+Ñ+×1Ñ1Ð2DÔEØ!Ñ-Ø×+Ñ+×1Ñ1Ð2DÔEØÑ)Ø×'Ñ'×-Ñ-¨nÔ=Ø#Ñ/Ø×-Ñ-×3Ñ3Ð4HÔIØ#Ñ/Ø×-Ñ-×3Ñ3Ð4HÔIØ!Ñ-Ø×+Ñ+×1Ñ1Ð2DÔEØÑ$Ø×.Ñ.×4Ñ4°YÕ?ð %øð- Ñ%Ø×#Ñ#×)Ñ)¨*Ô5ØÑ%Ø×#Ñ#×)Ñ)¨*Ô5ØÑ&Ø×$Ñ$×*Ñ*¨;Ô7ØÑ)Ø×'Ñ'×-Ñ-¨nÔ=ØÑ&Ø×$Ñ$×*Ñ*¨;Ô7Ø!Ñ-Ø×+Ñ+×1Ñ1Ð2DÔEØ!Ñ-Ø×+Ñ+×1Ñ1Ð2DÔEØÑ)Ø×'Ñ'×-Ñ-¨nÔ=Ø#Ñ/Ø×-Ñ-×3Ñ3Ð4HÔIØ#Ñ/Ø×-Ñ-×3Ñ3Ð4HÔIØ!Ñ-Ø×+Ñ+×1Ñ1Ð2DÔEØÑ$Ø×.Ñ.×4Ñ4°YÕ?ð %üs    ‚Yd4Ù_ ÙE*d4ßE+d1ä1d4c               ó   • g r¼   r§   ©rZ  Úfuncs     r±   r  ÚAgent.instructionsŽ  ó   € ð :=r°   c               ó   • g r¼   r§   rì  s     r±   r  rî  “  ó	   € ð EHr°   c               ó   • g r¼   r§   rì  s     r±   r  rî  ˜  ó   € Ø[^r°   c               ó   • g r¼   r§   rì  s     r±   r  rî  ›  ó   € Øqtr°   ©r%  c              ó   • g r¼   r§   )rZ  r%  s     r±   r  rî  ž  ó	   € ð RUr°   c              óÊ   ^ ^^• Tb  [         R                  " T5        Tb(  [        R                  " [        R                  " 5       TS9OSm    SUUU 4S jjnUc  U$ U" U5      $ )a?  Decorator to register an instructions function.

Optionally takes [`RunContext`][pydantic_ai.tools.RunContext] as its only argument.
Can decorate a sync or async functions.

The decorator can be used bare (`agent.instructions`).

Overloads for every possible signature of `instructions` are included so the decorator doesn't obscure
the type of the function.

Example:
```python
from pydantic_ai import Agent, RunContext

agent = Agent('test', deps_type=str)

@agent.instructions
def simple_instructions() -> str:
    return 'foobar'

@agent.instructions
async def async_instructions(ctx: RunContext[str]) -> str:
    return f'{ctx.deps} is the best'
```

Args:
    func: The instructions function to register.
    name: An optional name for the instruction part this function produces, keyed as
        `'agent:<name>'` on [`InstructionPart.id`][pydantic_ai.messages.InstructionPart.id] so an
        application can address this part specifically, where the bare `'agent'` key addresses
        the agent's literal instructions. See [instruction parts](../agent.md#instruction-parts).
Nrö  c           	     óh   >• TR                   R                  [         R                  " U TTSS95        U $ )NT)r%  rå   Údynamic)r*   rï   ÚSourcedInstruction)Úfunc_Úinstruction_idr%  rZ  s    €€€r±   Ú	decoratorÚ%Agent.instructions.<locals>.decoratorÐ  s5   ø€ ð ×Ñ×%Ñ%Ü×0Ò0°¸TÀnÐ^bÑcôð ˆLr°   ©rý  úSystemPromptFunc[AgentDepsT]rà   r  )r*   Úvalidate_instruction_namer
  ÚInstructionIdr  )rZ  rí  r%  rÿ  rþ  s   ` ` @r±   r  rî  £  so   ú€ ðN ÑÜ×3Ò3°DÔ9àVZÑVfŒI×#Ò#¤I×$DÒ$DÓ$FÈTÒRÐlpð 	ð	Ø/ð	à)÷	ñ 	ð !™LˆyÐ=©i¸«oÐ=r°   )rÜ  r   rñ  r  r2   r"  c             ƒ  óæ  #   • U R                  U5      nU=(       d    [        R                  " 5       n[        U=(       d    / 5      nU R	                  5       nU R                  U5      n	U	(       a'  U R                  U R                  U5      X�S9I Sh  v•N OSn
Uc~  U R                  R                  5       cc  UR                  5       nUb4  [        R                  " U UU
SUUS9nU R                  X¸US9I Sh  v•N u  pÞO#U
b  U
nO[        R                  " S5      eU
c   eU
n[         ["           " UU UUUUUSS9n[$        R&                  " U R(                  U R*                  U5      I Sh  v•N $  NÚ Nx N7f)z©Resolve the agent's configured system prompts into `SystemPromptPart`s.

See [`AbstractAgent.system_prompt_parts`][pydantic_ai.agent.AbstractAgent.system_prompt_parts].
)rú   rÜ  Nrƒ   r  )rú   r	  zD`model` must either be set on the agent or supplied by a capability.)rÜ  r¾  r   r2   r  r0   r"  r  )r|  r}  r~  r‘  rÖ  r‚  r„  rƒ  rv  r  r€  r1   r…  rI  r/   rŽ  rm   rf   r,   Úresolve_system_promptsrB  rC  )rZ  rÜ  r   rñ  r  r2   r"  r0   rú   r¨  rª  ÚcontributionrK  Úselected_modelÚ_r3  s                   r±   Úsystem_prompt_partsÚAgent.system_prompt_partsÚ  s“  é € ð �~‰~˜dÓ#ˆØ×*œŸšÓ*ˆÜ˜×-¨2Ó.ˆØ×4Ñ4Ó6ˆ
Ø ŸO™O¨EÓ2Ðö !ð ×/Ñ/°×0DÑ0DÀUÓ0KÐXbÐ/Ðn×nÐnàð 	ð
 ‰=˜T×1Ñ1×5Ñ5Ó7Ñ?Ø%×/Ñ/Ó1ˆLØÑ'Ü &× <Ò <ØØØ'ØØ%Øñ!�ð +/×*KÑ*KØ ¸]ð +Lð +÷ %Ñ!� ð Ñ*Ø!.‘ä ×*Ò*Ð+qÓrÐrà Ñ,Ð,Ð,Ø*ˆNÜ ¤Ò,ØØØ ØØØØ)Øñ	
ˆô $×:Ò:Ø× Ñ  $×"?Ñ"?Àó
÷ 
ð 	
ñG oñ%ñ(
ùs8   ‚BE1ÂE+ÂA#E1Ã4E-Ã5A1E1Å&E/Å'E1Å-E1Å/E1c               ó   • g r¼   r§   rì  s     r±   r_  ÚAgent.system_prompt	  rï  r°   c               ó   • g r¼   r§   rì  s     r±   r_  r  	  rñ  r°   c               ó   • g r¼   r§   rì  s     r±   r_  r  	  s   € Ø\_r°   c               ó   • g r¼   r§   rì  s     r±   r_  r  "	  s   € Ørur°   ©rû  c              ó   • g r¼   r§   )rZ  rû  s     r±   r_  r  %	  rø  r°   c              ó´   ^ ^• Uc      SUU 4S jjnU$ T(       a   S5       eT R                   R                  [        R                  [           " UTS95        U$ )a  Decorator to register a system prompt function.

Optionally takes [`RunContext`][pydantic_ai.tools.RunContext] as its only argument.
Can decorate a sync or async functions.

The decorator can be used either bare (`agent.system_prompt`) or as a function call
(`agent.system_prompt(...)`), see the examples below.

Overloads for every possible signature of `system_prompt` are included so the decorator doesn't obscure
the type of the function, see `tests/typed_agent.py` for tests.

Args:
    func: The function to decorate
    dynamic: If True, the system prompt will be reevaluated even when `messages_history` is provided,
        see [`SystemPromptPart.dynamic_ref`][pydantic_ai.messages.SystemPromptPart.dynamic_ref]

Example:
```python
from pydantic_ai import Agent, RunContext

agent = Agent('test', deps_type=str)

@agent.system_prompt
def simple_system_prompt() -> str:
    return 'foobar'

@agent.system_prompt(dynamic=True)
async def async_system_prompt(ctx: RunContext[str]) -> str:
    return f'{ctx.deps} is the best'
```
c                ó¶   >• [         R                  [           " U TS9nTR                  R	                  U5        T(       a  UTR
                  U R                  '   U $ )Nr  )r,   ÚSystemPromptRunnerrf   rC  rï   rD  r«   )rý  Úrunnerrû  rZ  s     €€r±   rÿ  Ú&Agent.system_prompt.<locals>.decoratorR	  sO   ø€ ô (×:Ñ:¼:ÒFÀuÐV]Ñ^�Ø×-Ñ-×4Ñ4°VÔ<ÞØPV�D×9Ñ9¸%×:LÑ:LÑMØ�r°   z"dynamic can't be True in this caser  r  )rC  rï   r,   r  rf   )rZ  rí  rû  rÿ  s   ` ` r±   r_  r  *	  si   ù€ ðL ‰<ðØ3ðà-÷ð ð ÐæÐDÐ DÓD�;Ø×)Ñ)×0Ñ0´×1RÑ1RÔS]Ò1^Ð_cÐmtÑ1uÔvØˆKr°   c               ó   • g r¼   r§   rì  s     r±   Úoutput_validatorÚAgent.output_validatora	  ó	   € ð HKr°   c               ó   • g r¼   r§   rì  s     r±   r  r  f	  s	   € ð SVr°   c               ó   • g r¼   r§   rì  s     r±   r  r  k	  ó   € ð 03r°   c               ó   • g r¼   r§   rì  s     r±   r  r  p	  s   € ð ;>r°   c               ó~   • U R                   R                  [        R                  [        [
        4   " U5      5        U$ )aƒ  Decorator to register an output validator function.

Optionally takes [`RunContext`][pydantic_ai.tools.RunContext] as its first argument.
Can decorate a sync or async functions.

Overloads for every possible signature of `output_validator` are included so the decorator doesn't obscure
the type of the function, see `tests/typed_agent.py` for tests.

Example:
```python
from pydantic_ai import Agent, ModelRetry, RunContext

agent = Agent('test', deps_type=str)

@agent.output_validator
def output_validator_simple(data: str) -> str:
    if 'wrong' in data:
        raise ModelRetry('wrong response')
    return data

@agent.output_validator
async def output_validator_deps(ctx: RunContext[str], data: str) -> str:
    if ctx.deps in data:
        raise ModelRetry('wrong response')
    return data

result = agent.run_sync('foobar', deps='spam')
print(result.output)
#> success (no tool calls)
```
)r?  rï   r+   ÚOutputValidatorrf   r   rì  s     r±   r  r  u	  s3   € ðD 	×Ñ×&Ñ&¤w×'>Ñ'>¼zÌ3¸Ò'OÐPTÓ'UÔVØˆr°   c               ó   • g r¼   r§   rì  s     r±   Úon_eventÚAgent.on_eventš	  s   € ð 7:r°   )rq  c               ó   • g r¼   r§   )rZ  rq  Úevent_typess      r±   r#  r$  Ÿ	  r  r°   c               ó„   • U R                   R                  nUc  UR                  " USU06$ UR                  " U/UQ7SU06$ )u”
  Decorator to register a listener for events on this agent's run event stream.

Every event on the stream can be listened for: the framework's own model and tool events,
the application's [`CustomEvent`][pydantic_ai.messages.CustomEvent]s, and the
[`CapabilityEvent`][pydantic_ai.messages.CapabilityEvent]s published by the agent's
capabilities. Naming event classes narrows the `event` argument to their union and lets
dispatch skip the agent's listeners for anything else; a bare `@agent.on_event` sees every
[`AgentStreamEvent`][pydantic_ai.messages.AgentStreamEvent].

This is the application-level counterpart to
[`@on_event`][pydantic_ai.capabilities.on_event] on a capability, and it dispatches at the
same point. These listeners join after the agent's own capabilities, so they see the events
those emitted, and they survive an overridden root capability. Capability ordering still
applies: one asking for `position='innermost'` keeps that position and its listeners run
after these.

Dispatch happens *upstream* of
[`wrap_run_event_stream()`][pydantic_ai.capabilities.AbstractCapability.wrap_run_event_stream],
so a listener sees each event as it was emitted, not as it is finally delivered. A
capability that rewrites, replaces or drops events in its stream wrapper does so after
every listener has already run, which means a listener can see an event that no stream
consumer ever receives. To act on the delivered stream instead, wrap it yourself with
`wrap_run_event_stream` on a [`Hooks`][pydantic_ai.capabilities.Hooks] capability, or
consume [`run_stream_events()`][pydantic_ai.agent.AbstractAgent.run_stream_events].

Being application code, a listener may emit a `CustomEvent` of its own. That is how a
capability's internal event reaches a frontend: capability events are deliberately not
forwarded by the [AG-UI](../ui/ag-ui.md) and [Vercel AI](../ui/vercel-ai.md) adapters, so
you republish the part of one that is public.

For hook families other than events, pass a [`Hooks`][pydantic_ai.capabilities.Hooks]
capability to `capabilities=`, where its position among the other capabilities â€” which
decides where it sits in each wrap chain â€” is yours to choose.

Example:
```python
from dataclasses import dataclass

from pydantic_ai import Agent, CapabilityEvent, CustomEvent, RunContext

agent = Agent('test')


@dataclass(kw_only=True)
class IndexRebuiltEvent(CapabilityEvent, namespace='indexer'):
    documents: int


@dataclass(kw_only=True)
class SearchReadyEvent(CustomEvent):
    documents: int


@agent.on_event(IndexRebuiltEvent)
async def republish(ctx: RunContext[None], event: IndexRebuiltEvent) -> None:
    await ctx.emit(SearchReadyEvent(documents=event.documents))
```
rq  )r…  ÚonÚevent)rZ  Úfunc_or_event_typerq  r&  Ú	registrars        r±   r#  r$  ¤	  sJ   € ðF ×*Ñ*×-Ñ-ˆ	ØÑ%Ø—?’? KÐA¸ÑAÐAØ�ŠÐ1ÐQ°KÒQÈÑQÐQr°   c               ó   • g r¼   r§   rì  s     r±   ÚtoolÚ
Agent.toolì	  rõ  r°   Úauto)r%  ra  r  ÚprepareÚargs_validatorÚdocstring_formatÚrequire_parameter_descriptionsÚschema_generatorÚstrictÚ
sequentialÚrequires_approvalr$  rq  Údefer_loadingÚinclude_return_schemac              ó   • g r¼   r§   ©rZ  r%  ra  r  r0  r1  r2  r3  r4  r5  r6  r7  r$  rq  r8  r9  s                   r±   r-  r.  ï	  s	   € ð( hkr°   c              ór   ^ ^^^^^^^^	^
^^^^^^•     SUUUUUUUUUUUU	U UU
U4S jjnUc  U$ U" U5      $ )a¸  Decorator to register a tool function which takes [`RunContext`][pydantic_ai.tools.RunContext] as its first argument.

Can decorate a sync or async functions.

The docstring is inspected to extract both the tool description and description of each parameter,
[learn more](../tools.md#function-tools-and-schema).

We can't add overloads for every possible signature of tool, since the return type is a recursive union
so the signature of functions decorated with `@agent.tool` is obscured.

Example:
```python
from pydantic_ai import Agent, RunContext

agent = Agent('test', deps_type=int)

@agent.tool
def foobar(ctx: RunContext[int], x: int) -> int:
    return ctx.deps + x

@agent.tool(retries=2)
async def spam(ctx: RunContext[str], y: float) -> float:
    return ctx.deps + y

result = agent.run_sync('foobar', deps=1)
print(result.output)
#> {"foobar":1,"spam":1.0}
```

Args:
    func: The tool function to register.
    name: The name of the tool, defaults to the function name.
    description: The description of the tool, defaults to the function docstring.
    retries: The number of retries to allow for this tool, defaults to the agent's default retries,
        which defaults to 1.
    prepare: custom method to prepare the tool definition for each step, return `None` to omit this
        tool from a given step. This is useful if you want to customise a tool at call time,
        or omit it completely from a step. See [`ToolPrepareFunc`][pydantic_ai.tools.ToolPrepareFunc].
    args_validator: custom method to validate tool arguments after schema validation has passed,
        before execution. The validator receives the already-validated and type-converted parameters,
        with `RunContext` as the first argument.
        Raise [`ModelRetry`][pydantic_ai.exceptions.ModelRetry] to ask the model to correct the
        arguments and try again, or [`ToolFailed`][pydantic_ai.exceptions.ToolFailed] to report a
        terminal failure the model should adapt to instead of retrying. Return `None` on success.
        See [`ArgsValidatorFunc`][pydantic_ai.tools.ArgsValidatorFunc].
    docstring_format: The format of the docstring, see [`DocstringFormat`][pydantic_ai.tools.DocstringFormat].
        Defaults to `'auto'`, such that the format is inferred from the structure of the docstring.
    require_parameter_descriptions: If True, raise an error if a parameter description is missing. Defaults to False.
    schema_generator: The JSON schema generator class to use for this tool. Defaults to `GenerateToolJsonSchema`.
    strict: Whether to enforce (vendor-specific) strict schema adherence for tool calls (supported by OpenAI, Anthropic, Google, and Bedrock).
        See [`ToolDefinition`][pydantic_ai.tools.ToolDefinition] for more info.
    sequential: Whether this tool acts as a barrier that runs alone, not overlapping with other tool calls.
        See [`ToolDefinition`][pydantic_ai.tools.ToolDefinition] for more info. Defaults to False.
    requires_approval: Whether this tool requires human-in-the-loop approval. Defaults to False.
        See the [tools documentation](../deferred-tools.md#human-in-the-loop-tool-approval) for more info.
    metadata: Optional metadata for the tool. This is not sent to the model but can be used for filtering and tool behavior customization.
    timeout: Timeout in seconds for tool execution. If the tool takes longer, a retry prompt is returned to the model.
        Overrides the agent-level `tool_timeout` if set. Defaults to None (no timeout).
    defer_loading: Whether to hide this tool until it's revealed by tool search, `load_capability`,
        or another tool's `ToolReturn.tools`. Defaults to False.
        See [Tool Search](../tools-advanced.md#tool-search) for more info.
    include_return_schema: Whether to include the return schema in the tool definition sent to the model.
        If `None`, defaults to `False` unless the [`IncludeToolReturnSchemas`][pydantic_ai.capabilities.IncludeToolReturnSchemas] capability is used.
c                óZ   >• TR                   R                  U STTTTTTT	TTTT
TTTTS9  U $ )NT©Ú	takes_ctxr%  ra  r  r0  r1  r2  r3  r4  r5  r6  r7  r$  rq  r8  r9  ©rE  Úadd_function©rý  r1  r8  ra  r2  r9  r$  r%  r0  r3  r7  r  r4  rZ  r6  r5  rq  s    €€€€€€€€€€€€€€€€r±   Útool_decoratorÚ"Agent.tool.<locals>.tool_decorator[
  sX   ø€ ð ×"Ñ"×/Ñ/ØØØØ'ØØØ-Ø!1Ø/MØ!1ØØ%Ø"3Ø!ØØ+Ø&;ð# 0ñ ð& ˆLr°   )rý  ú'ToolFuncContext[AgentDepsT, ToolParams]rà   rE  r§   ©rZ  rí  r%  ra  r  r0  r1  r2  r3  r4  r5  r6  r7  r$  rq  r8  r9  rC  s   ` ``````````````` r±   r-  r.  
  s:   ÿÿ€ ðl	Ø:ð	à4÷	÷ 	ö 	ð2 "&¡ˆ~ÐG±>À$Ó3GÐGr°   c               ó   • g r¼   r§   rì  s     r±   Ú
tool_plainÚAgent.tool_plainv
  ró  r°   c              ó   • g r¼   r§   r;  s                   r±   rH  rI  y
  s	   € ð( LOr°   c              ój   ^ ^^^^^^^^	^
^^^^^^• SUUUUUUUUUUUU	U UU
U4S jjnUc  U$ U" U5      $ )uî  Decorator to register a tool function which DOES NOT take `RunContext` as an argument.

Can decorate a sync or async functions.

The docstring is inspected to extract both the tool description and description of each parameter,
[learn more](../tools.md#function-tools-and-schema).

We can't add overloads for every possible signature of tool, since the return type is a recursive union
so the signature of functions decorated with `@agent.tool` is obscured.

Example:
```python
from pydantic_ai import Agent, RunContext

agent = Agent('test')

@agent.tool
def foobar(ctx: RunContext[int]) -> int:
    return 123

@agent.tool(retries=2)
async def spam(ctx: RunContext[str]) -> float:
    return 3.14

result = agent.run_sync('foobar', deps=1)
print(result.output)
#> {"foobar":123,"spam":3.14}
```

Args:
    func: The tool function to register.
    name: The name of the tool, defaults to the function name.
    description: The description of the tool, defaults to the function docstring.
    retries: The number of retries to allow for this tool, defaults to the agent's default retries,
        which defaults to 1.
    prepare: custom method to prepare the tool definition for each step, return `None` to omit this
        tool from a given step. This is useful if you want to customise a tool at call time,
        or omit it completely from a step. See [`ToolPrepareFunc`][pydantic_ai.tools.ToolPrepareFunc].
    args_validator: custom method to validate tool arguments after schema validation has passed,
        before execution. The validator receives the already-validated and type-converted parameters,
        with [`RunContext`][pydantic_ai.tools.RunContext] as the first argument â€” even though the
        tool function itself does not take `RunContext` when using `tool_plain`.
        Raise [`ModelRetry`][pydantic_ai.exceptions.ModelRetry] to ask the model to correct the
        arguments and try again, or [`ToolFailed`][pydantic_ai.exceptions.ToolFailed] to report a
        terminal failure the model should adapt to instead of retrying. Return `None` on success.
        See [`ArgsValidatorFunc`][pydantic_ai.tools.ArgsValidatorFunc].
    docstring_format: The format of the docstring, see [`DocstringFormat`][pydantic_ai.tools.DocstringFormat].
        Defaults to `'auto'`, such that the format is inferred from the structure of the docstring.
    require_parameter_descriptions: If True, raise an error if a parameter description is missing. Defaults to False.
    schema_generator: The JSON schema generator class to use for this tool. Defaults to `GenerateToolJsonSchema`.
    strict: Whether to enforce (vendor-specific) strict schema adherence for tool calls (supported by OpenAI, Anthropic, Google, and Bedrock).
        See [`ToolDefinition`][pydantic_ai.tools.ToolDefinition] for more info.
    sequential: Whether this tool acts as a barrier that runs alone, not overlapping with other tool calls.
        See [`ToolDefinition`][pydantic_ai.tools.ToolDefinition] for more info. Defaults to False.
    requires_approval: Whether this tool requires human-in-the-loop approval. Defaults to False.
        See the [tools documentation](../deferred-tools.md#human-in-the-loop-tool-approval) for more info.
    metadata: Optional metadata for the tool. This is not sent to the model but can be used for filtering and tool behavior customization.
    timeout: Timeout in seconds for tool execution. If the tool takes longer, a retry prompt is returned to the model.
        Overrides the agent-level `tool_timeout` if set. Defaults to None (no timeout).
    defer_loading: Whether to hide this tool until it's revealed by tool search, `load_capability`,
        or another tool's `ToolReturn.tools`. Defaults to False.
        See [Tool Search](../tools-advanced.md#tool-search) for more info.
    include_return_schema: Whether to include the return schema in the tool definition sent to the model.
        If `None`, defaults to `False` unless the [`IncludeToolReturnSchemas`][pydantic_ai.capabilities.IncludeToolReturnSchemas] capability is used.
c                óZ   >• TR                   R                  U STTTTTTT	TTTT
TTTTS9  U $ )NFr>  r@  rB  s    €€€€€€€€€€€€€€€€r±   rC  Ú(Agent.tool_plain.<locals>.tool_decoratoræ
  sV   ø€ à×"Ñ"×/Ñ/ØØØØ'ØØØ-Ø!1Ø/MØ!1ØØ%Ø"3Ø!ØØ+Ø&;ð# 0ñ ð& ˆLr°   )rý  úToolFuncPlain[ToolParams]rà   rN  r§   rF  s   ` ``````````````` r±   rH  rI  �
  s*   ÿÿ€ ÷n	÷ 	ö 	ð. "&¡ˆ~ÐG±>À$Ó3GÐGr°   c               ó   • g r¼   r§   rì  s     r±   r�  ÚAgent.toolsetÿ
  s   € ØTWr°   ©Úper_run_steprå   c              ó   • g r¼   r§   )rZ  rR  rå   s      r±   r�  rP    s	   € ð HKr°   c              ó6   ^ ^^• SUUU 4S jjnUc  U$ U" U5      $ )a¿  Decorator to register a toolset function which takes [`RunContext`][pydantic_ai.tools.RunContext] as its only argument.

Can decorate a sync or async functions.

The decorator can be used bare (`agent.toolset`).

Example:
```python
from pydantic_ai import AbstractToolset, Agent, FunctionToolset, RunContext

agent = Agent('test', deps_type=str)

@agent.toolset
async def simple_toolset(ctx: RunContext[str]) -> AbstractToolset[str]:
    return FunctionToolset()
```

Args:
    func: The toolset function to register.
    per_run_step: Whether to re-evaluate the toolset for each run step. Defaults to True.
    id: An optional unique ID for the dynamic toolset. Under durable execution, construct a
        [`DynamicToolset`][pydantic_ai.toolsets.DynamicToolset] with this ID and pass it to
        `Agent(toolsets=[...])` instead; decorator registrations cannot be used inside a
        workflow or flow because they happen after durable units are created.
c                óP   >• TR                   R                  [        U TTS95        U $ )NrQ  )r’  rï   rz   )rý  rå   rR  rZ  s    €€€r±   Útoolset_decoratorÚ(Agent.toolset.<locals>.toolset_decorator-  s&   ø€ Ø×"Ñ"×)Ñ)¬.¸È\Ð^`Ñ*aÔbØˆLr°   )rý  úToolsetFunc[AgentDepsT]rà   rX  r§   )rZ  rí  rR  rå   rV  s   ` `` r±   r�  rP    s&   ú€ ÷D	ñ 	ð %)¡LÐ ÐMÑ6GÈÓ6MÐMr°   c                óz   • USL=(       d1    U R                   R                  5       SL=(       d    U R                  SL$ )zûWhether a run given `model` would have one to use, counting an `override(model=...)`.

What `_pick_raw_model` answers for, asked ahead of it by callers that would rather not have
it raise. A capability can still contribute a model when this is False.
N)rv  r  r   )rZ  r   s     r±   r‚  ÚAgent._has_model3  s7   € ð ˜DÐ ×d D×$8Ñ$8×$<Ñ$<Ó$>ÀdÐ$J×dÈdÏjÉjÐ`dÐNdÐdr°   c                óÄ   • U R                   R                  5       =n(       a  UR                  $ Ub  U$ U R                  b  U R                  $ [        R
                  " S5      e)Nr  )rv  r  r  r   r/   rŽ  )rZ  r   Ú
some_models      r±   rƒ  ÚAgent._pick_raw_model;  s[   € ð ×-Ñ-×1Ñ1Ó3Ð3ˆ:Õ3Ø×#Ñ#Ð#ØÑØˆLØ�:‰:Ñ!Ø—:‘:ÐÜ×"Ò"Ð#iÓjÐjr°   c                ól   • U R                   R                  5       nUb  UR                  $ U R                  $ )zKReturn the override capability when present, otherwise the configured root.)r  r  r  r†  )rZ  ré  s     r±   rÖ  Ú Agent._effective_root_capabilityF  s0   € à×1Ñ1×5Ñ5Ó7ˆØ!)Ñ!5ˆx�~‰~ÐP¸4×;PÑ;PÐPr°   c           	     óð  • U R                  U5      n/ U R                  QU=(       d    / QnU Vs/ s H  n[        U[        5      (       d  M  UPM     nn[	        [        U[
        R                  5      (       a  UR                  OU[        U5      [        U5      :X  a  [        S U 5       5      OS[        U R                  5       5      [        U[        5      =(       d    U R                  5       SLS9$ s  snf )a  Describe the session `_cli` is about to open, before any run has resolved anything.

Resolved the way a run resolves it rather than read off the agent as configured: an
`override()` in force, or instrumentation switched on globally by `Agent.instrument_all()`,
would otherwise have the banner describe a different session than the one about to start.

Args:
    model: Model the session was asked to use, if not the agent's own.
    toolsets: Toolsets the session will pass to each run, which aren't on the agent.
c              3  óL   #   • U  H  n[        UR                  5      v •  M     g 7fr¼   )r“  r¥   )r(  r�  s     r±   r-  Ú0Agent._startup_banner_details.<locals>.<genexpr>e  s   é € ÐBº	¨W”c˜'Ÿ-™-×(Ð(º	ùó   ‚"$N)r   r¥   rg  Úinstrumented)rƒ  rc  ró   r�   Ú_StartupBannerDetailsr1   r  rZ  r“  ÚsumrQ  rÖ  rY   r�  )rZ  r   rc  Ú
chat_modelÚsession_toolsetsr�  Ú	countables          r±   Ú_startup_banner_detailsÚAgent._startup_banner_detailsK  sÔ   € ð ×)Ñ)¨%Ó0ˆ
à>˜TŸ]™]Ð>¨h¯n¸"Ð>Ðñ -=ÓeÒ,< Ä
È7ÔTc×@d—WÑ,<ˆ	ÐeÜ$Ü)3°JÄÇÁ×)MÑ)M�*×%Ò%ÐS]ô GJÈ)ÃnÔX[Ð\lÓXmÓFm”#ÑB¹	ÓBÔBÐswÜ5°d×6UÑ6UÓ6WÓXä˜:Ô'8Ó9×q¸T×=cÑ=cÓ=eÐmqÐ=qñ

ð 
	
ùò fs   ¯C3ÁC3c                óv   • U R                   R                  5       nUb  UR                  $ Ub  U$ U R                  $ )zNResolve the effective tool-retry default: override > run/spec > agent default.)r~  r  r  rJ  )rZ  r  ré  s      r±   r{  ÚAgent._resolve_tool_retriesl  s<   € à×.Ñ.×2Ñ2Ó4ˆØÑØ—>‘>Ð!Ø!Ñ-ˆwÐI°4×3IÑ3IÐIr°   c                óÂ   • U R                   R                  5       nU R                  5       nU R                  R                  (       a  [        X R                  /5      nX!SL4$ )uk  The base capability layer for a run, plus whether it came from `override(root_capability=...)`.

`iter` and `realtime_session` both resolve the base layer through this so the override is honored
identically â€” KEEP the two call sites in sync (a realtime session that ignored the override would
silently drop a `with agent.override(root_capability=...):` block).
N)r  r  rÖ  r…  Úhas_on_eventrG   )rZ  Úoverride_capr1  s      r±   rx  ÚAgent._base_run_capabilitys  sX   € ð ×5Ñ5×9Ñ9Ó;ˆØ×.Ñ.Ó0ˆØ×Ñ×)×)ô
 & t×->Ñ->Ð&?Ó@ˆDØ¨Ð-Ð-Ð-r°   c                óN   • U Vs/ s H  o"R                  U 5      PM     sn$ s  snf )u¬  Bind per-run capabilities to this agent via `for_agent` before capability resolution.

`_resolve_run_capabilities` only ever calls `for_run`, so binding the per-run layer via
`for_agent` is the caller's responsibility. `iter` and `realtime_session` both MUST call this â€”
skipping it uses a capability that overrides `for_agent` (e.g. the durability capabilities)
unbound, a silent divergence. KEEP the two call sites in sync.
)rÔ  )rZ  r#  rú   s      r±   r  ÚAgent._bind_run_capabilities„  s(   € ñ >PÓPÒ=O¨z×$Ñ$ TÖ*Ñ=OÑPÐPùÒPs   …")r  c             ƒ  ó|  #   • [        U[        5      (       d  U$ [        U5      U4nUb  UR                  U5      =nb  U$ U R                  R                  U5      =n(       a	  Ub  XtU'   U$ [
        R                  " XS9nUR                  X�S9I Sh  v•N n	U	b  U	O[
        R                  " U5      nUb  XdU'   U$  N(7f)z@Resolve a concrete model selection through the capability chain.N)r¾  rÜ  )rZ  )	ró   r	  rå   r  r˜  r1   ÚModelResolutionContextÚresolve_model_idrŸ  )
rZ  Ú	selectionrú   rÜ  r  Ú	cache_keyÚresolved_modelÚentered_modelÚresolution_ctxrŸ  s
             r±   r„  ÚAgent._resolve_model_selection�  sÒ   é € ô ˜)¤S×)Ñ)ØÐÜ˜
“^ YÐ/ˆ	ØÑ&¸o×>QÑ>QÐR[Ó>\Ð,\¨NÑ+iØ!Ð!Ø ×=Ñ=×AÑAÀ)ÓLÐLˆ=ÕLØÑ*Ø-: 	Ñ*Ø Ð Ü×6Ò6¸TÑMˆØ#×4Ñ4°^Ð4ÐX×XˆØ%-Ñ%9™¼v×?QÒ?QÐR[Ó?\ˆØÑ&Ø)7˜IÑ&ØÐñ	 Yùs   ‚BB<ÂB:Â)B<c             ƒ  ó.  #   • [        U5      (       a  [        U5      (       d  U" U5      OUn[        R                  " U5      (       a
  UI Sh  v•N nU R	                  XRUR
                  US9I Sh  v•N nU[        U[        5      (       a  U4$ S4$  NC N"7f)zGEvaluate a static or dynamic model contribution and resolve its result.Nr  )rz  r  r  Úisawaitabler„  rÜ  ró   r	  )rZ  r  rú   r	  r  rw  r   s          r±   rI  Ú"Agent._evaluate_model_contribution©  s‘   é € ô *2°,×)?Ñ)?Ì	ÐR^×H_ÑH_‘L Ô%Ðeqˆ	Ü×Ò˜y×)Ñ)Ø'ŸˆIØ×3Ñ3Ø°3·8±8È_ð 4ð 
÷ 
ˆð ¤:¨i¼×#=Ñ#=�iÐGÐGÀ4ÐGÐGñ	 (ñ
ùs$   ‚ABÁBÁ"BÁ0BÁ1!BÂBc                óð   • [        U 5      (       af  [        U 5      (       dU  U(       aM  [        US   [        R                  5      (       a*  US   R
                  S:X  a  [        R                  " S5      eggggg)zRReject cross-run continuation when a selector cannot reconstruct the pinned model.éÿÿÿÿÚ	suspendedzÕCannot resume a suspended response with a dynamic capability model: the model that created the provider-side job cannot be reconstructed unambiguously. Pass that model explicitly to `run(model=...)` when resuming.N)rz  r  ró   r
  ÚModelResponserk  r/   rŽ  )r  rñ  s     r±   r�  Ú!Agent._check_dynamic_model_resumeº  s{   € ô �\×"Ñ"Ü˜l×+Ñ+ÞÜ˜?¨2Ñ.´	×0GÑ0G×HÑHØ Ñ#×)Ñ)¨[Ó8ä×&Ò&ðKóð ð 9ð Ið  ð ,ð #r°   c                óP  • U R                  5       nUc  U R                  R                  5       b9  U R                  U5      n[	        U5      (       a  U$ [
        R                  " U5      $ UR                  5       n[        U5      (       a&  [	        U5      (       d  [        R                  " S5      eUb  UOU R                  S5      n[        U[        5      (       a'  UR                  (       a  [        R                  " S5      e[	        U5      (       a  U$ [
        R                  " U5      $ )zOResolve a configured or static capability model where run deps are unavailable.Nz~The capability model is dynamic and can only be selected during a run with run dependencies. Pass a concrete model explicitly.zmThe configured model ID is resolved by a capability using run dependencies. Pass a concrete model explicitly.)rÖ  rv  r  rƒ  r  r1   rŸ  r€  rz  r/   rŽ  ró   r	  rž  )rZ  r   rú   rw  r  s        r±   Ú_get_model_outside_runÚAgent._get_model_outside_runÍ  sþ   € à×4Ñ4Ó6ˆ
ØÑ × 4Ñ 4× 8Ñ 8Ó :Ñ FØ×,Ñ,¨UÓ3ˆIÜ )¨)× 4Ñ 4�9ÐW¼&×:LÒ:LÈYÓ:WÐWØ!×+Ñ+Ó-ˆÜ�L×!Ñ!¬)°L×*AÑ*AÜ×&Ò&ð4óð ð %1Ñ$<‘LÀ$×BVÑBVÐW[ÓB\ˆ	Ü�i¤×%Ñ%¨*×*I×*IÜ×&Ò&ð4óð ô & i×0Ñ0ˆyÐS´f×6HÒ6HÈÓ6SÐSr°   c                ó~   • U R                   b  U R                   OU R                  nU(       d  gUSL a
  [        5       $ U$ )z]Resolve effective `InstrumentationSettings` from `Agent.instrument_all` / `agent.instrument`.NT)r5  r6  rX   )rZ  rÇ  s     r±   r�  Ú'Agent._resolve_instrumentation_settingsá  s<   € à)-×)9Ñ)9Ñ)E�T×%Ò%È4×KcÑKcˆ
ÞØØ,6¸$Ò,>Ô&Ó(ÐNÀJÐNr°   c                ó`   • U R                   R                  5       =n(       a  UR                  $ U$ )zÜGet deps for a run.

If we've overridden deps via `_override_deps`, use that, otherwise use the deps passed to the call.

We could do runtime type checking of deps against `self._deps_type`, but that's a slippery slope.
)ru  r  r  )rZ  rÜ  Ú	some_depss      r±   r|  ÚAgent._get_depsè  s-   € ð ×+Ñ+×/Ñ/Ó1Ð1ˆ9Õ1Ø—?‘?Ð"àˆKr°   c          
   ƒ  óZ  ^#   • U/UQnUb'  [        U[        5      (       d  UR                  SU5        [        R                  " U4S jU 5       6 I Sh  v•N nU[        U5      [        U5      -
  S n	UR                  TU	 V
Vs/ s H  n
[        U
5        H  o»PM     M     snn
5        US[        U5      [        U5      -
   U	4 Vs/ s H?  nU(       d  M  [        [        U5      S:”  a  [        [        U5      5      OUS   U/5      PMA     nn[        U5      S:”  a:  [        [        U5      S:”  a  [        U5      OUS   U Vs/ s H  oÌ/PM     sn5      OUS   n[        U/5        [        U5      nU(       a[  [        S UR                  5        5       5      (       a6  [        U/[        5      (       d   [        U[        5       /5      n[        U5      nUTl        XâLd  U(       a  UnOSnUbR  UR#                  5       n[        UR%                  5       5      nUR'                  5       nUR)                  5       nUb  U/O/ nOSnU R*                  nU R,                  nSn[        US   R%                  5       5      n[/        UU(       a  SOSS9  [        U5      S:”  a  [        US   R%                  5       5      O/ n[/        US	S9  U R0                  R3                  5       =n(       a$  [/        UR4                  S
S9  / UR4                  QUQn[7        UUUUUUUS9$  GNÅs  snn
f s  snf s  snf 7f)uP  Resolve the per-run capability layers and extract their contributions.

Shared by [`iter`][pydantic_ai.agent.AbstractAgent.iter] / [`run`][pydantic_ai.agent.AbstractAgent.run]
and [`realtime_session`][pydantic_ai.agent.Agent.realtime_session] so both wire capabilities up
identically: the outermost `Instrumentation` injection, per-layer `for_run` resolution (never
composing first â€” see below), optional deferred-loader injection, and the native-tool /
instruction / model-settings / toolset contributions with `override(native_tools=...)` folded
in. Each caller keeps its own surrounding logic (instrumentation *settings* resolution,
model-settings layering, output toolset, the graph vs. the connection) and cross-references
this method so the two stay in sync.

`ctx` must already carry `metadata` (and, when instrumented, `tracer` / `trace_include_content`),
since capability `for_run` hooks observe it. `base_is_override` is whether `base_capability`
came from `override(root_capability=...)` (only the graph run supports that today), used solely
for the native-tool validation error's `source`.
Nr   c              3  óD   >#   • U  H  oR                  T5      v •  M     g 7fr¼   )r–  )r(  Úcapr	  s     €r±   r-  Ú2Agent._resolve_run_capabilities.<locals>.<genexpr>  s   øé € Ð/WÊJÀS·±¸C×0@Ð0@ÊJùs   ƒ rƒ   c              3  ó<   #   • U  H  oR                   S L v •  M     g7f)TN)r8  )r(  rú   s     r±   r-  r�  I  s   é € ÐYÒCX°Z×(Ñ(¨DÕ0ÒCXùs   ‚zoverride spec capabilitiesr�  r‚  zrun capabilitieszoverride native_tools)rÌ   rg  r  rb  r"  rc  r,  )rL   rŽ  Úinsertr-   Úgatherr“  Ú_validate_runtime_capabilitiesrR   rN   rG   r‘  rˆ  Ú_build_run_capabilitiesÚanyÚvaluesr%   rg  r¡  r¢  r¤  r�  r›  rœ  r£  ry  r  r  Ú_ResolvedRunCapabilities)rZ  r	  r"  r#  r$  r%  r&  Ú
run_layersr,  Úresolved_extrasr¢  rú   r*  Úcombined_layersrÌ   rg  Ú
source_capr  rb  r"  r©  rc  Úbase_native_toolsÚextra_native_toolsÚsome_native_toolss    `                       r±   r’  ÚAgent._resolve_run_capabilitiesô  sQ  øé € ð4 =LÐ;aÐN`Ð;aˆ
ð Ñ*Ô3FÀzÔSe×3fÑ3fØ×Ñ˜aÐ!4Ô5ô !'§¢Ô/WÉJÓ/WÐ X×Xˆð *¬#¨oÓ*>ÄÐEWÓAXÑ*XÐ*ZÐ[ˆØ×6Ñ6ØÙ%4Ô`¢_˜EÔGXÐY^×G_¸ŠZÑG_‰Z¡_Ò`ô	
ð  *Ð*Z¬C°Ó,@Ä3ÐGYÓCZÑ,ZÐ[Ð]lÑmó
âm�Üó vÔ+ÌsÐSXËzÐ\]Ë~Ô,>¼tÀE»{Ô,KÐchÐijÑckÐnsÐmtÖuÙmð 	ð 
ô �?Ó# aÓ'ô	 ,Ü7:¸?Ó7KÈaÓ7OÔ" ?Ô3ÐUdÐefÑUgÙ&5Ó6¢o˜U“¡oÑ6ôð
 ! Ñ#ð 	ô 	)¨.Ð)9Ô:ô /¨~Ó>ˆö "ÜÑYÀ<×CVÑCVÔCXÓY×YÑYÜ'¨Ð(8Ô:R×SÑSä/°ÔAYÓA[Ð0\Ó]ˆNÜ2°>ÓBˆLð
 (ˆÔð Ò0Ö4DØ@N‰JàˆJØÑ!Ø%×;Ñ;Ó=ˆLÜ 
× ;Ñ ;Ó =Ó>ˆLØ'×:Ñ:Ó<ˆNØ$×0Ñ0Ó2ˆKØOZÑOf¸{¹mÐln‰HàˆLØ×1Ñ1ˆLØ!×5Ñ5ˆNØˆHô ! °Ñ!3×!DÑ!DÓ!FÓGÐÜ!ØÞ3CÑ/ÐI]ò	
ô MPÐP_ÓL`ÐcdÓLdœT /°!Ñ"4×"EÑ"EÓ"GÔHÐjlÐÜ!Ð"4Ð=OÒPð !%× ;Ñ ;× ?Ñ ?Ó AÐAÐÕAÜ%Ð&7×&=Ñ&=ÐF]Ò^ØJÐ.×4Ñ4ÐJÐ7IÐJˆLä'Ø)Ø%Ø%Ø%Ø)ØØ+ñ
ð 	
òy Yùó aùò
ùò 7ùsC   ƒAL+ÁLÁ/L+ÂLÂ!&L+ÃL!Ã7L!Ä8L+ÅL&
ÅGL+ÌL+c           	     ó„  • U R                   R                  5       nU(       a<  UR                   Vs/ s H#  n[        R                  " U[        U5      5      PM%     nnU$ / U R                  QnUR                  Ub  UOU R                  5        Ub,  UR                  S [        R                  " U5       5       5        U$ s  snf )a/  Collect the lazy agent-level instructions for final request resolution.

Toolset instructions are collected separately during run execution.

Args:
    additional_instructions: Additional instructions to include for this run.
    cap_instructions: Instructions from capabilities, resolved at run time.

c              3  óP   #   • U  H  n[         R                  " US 5      v •  M     g 7fr¼   )r*   rŒ  )r(  r  s     r±   r-  Ú*Agent._get_instructions.<locals>.<genexpr>   s'   é € ð $â'd˜ô "×5Ò5°kÀ4×HÐHÚ'dùs   ‚$&)	rz  r  r  r*   rŒ  r  rµ  rš  r‹  )rZ  rA  rB  Úoverride_instructionsr  r  s         r±   r—  ÚAgent._get_instructionsƒ  sÌ   € ð !%× ;Ñ ;× ?Ñ ?Ó AÐæ ð
 $9×#>Ò#>óâ#>�Kô ×1Ò1°+Ô?XÐYdÓ?eÖfÙ#>ð ð ð Ðð 1˜T×/Ñ/Ð0ˆLØ×ÑÐ4DÑ4PÑ 0ÐVZ×VlÑVlÔmØ&Ñ2ð ×#Ñ#ñ $ä'4×'KÒ'KÐLcÔ'dó$ô ð
 Ðùòs   °*B=c                óâ  ^
^^• [        U R                  US95      nU(       a!  U R                  R                  5       c  / UQUQn[	        U5      nUb5  Um      SU4S jjn[        Xx5      nUR                  U5      =(       d    Un[        R                  " U5      (       a  UOU R                  nUb<  Ub-  UmUb  UOU R                  m
      SU
U4S jjn	[        X5      n[	        X/5      nU$ )a¼  Get the complete toolset.

Args:
    output_toolset: The output toolset to use instead of the one built at agent construction time.
    additional_toolsets: Additional toolsets to add, unless toolsets have been overridden.
    cap_toolsets: Per-run capability toolsets to use instead of the init-time capability toolsets.
    run_capability: The per-run capability instance, used to apply wrapper toolsets.
    max_output_retries: The effective output retry budget for this run (run kwarg / spec / agent default).
        Used as `ctx.max_retries` for the `prepare_output_tools` capability hook so it sees the
        same budget the run will actually enforce. Falls back to the agent-level default.
)r;  c              “  óB   >#   • TR                  X5      I S h  v•N $  N7fr¼   )Úprepare_tools)r	  Ú	tool_defsÚfn_caps     €r±   Ú_dispatch_prepare_toolsÚ3Agent._get_toolset.<locals>._dispatch_prepare_toolsÉ  s   øé € ð $×1Ñ1°#ÓA×AÐAÑAùs   ƒ˜™c              “  óV   >#   • [        U TS9nTR                  X!5      I S h  v•N $  N7f)N)rp  )r   Úprepare_output_tools)r	  r©  Ú
output_ctxÚeffective_max_output_retriesÚ
output_caps      €€r±   Ú_dispatch_prepare_output_toolsÚ:Agent._get_toolset.<locals>._dispatch_prepare_output_toolsâ  s,   øé € ô ")¨Ð:VÑ!W�JØ!+×!@Ñ!@ÀÓ!W×WÐWÑWùs   ƒ)¢'£))r	  rt  r©  úlist[ToolDefinition]rà   r´  )r‘  Ú_build_toolset_listrw  r  r€   r‚   Úget_wrapper_toolsetr-   rò   rF  rI  )rZ  r9  r:  r;  rÌ   r<  rc  r�  r«  r²  r°  rª  r±  s             @@@r±   r•  ÚAgent._get_toolset§  s(  ú€ ô& ˜×0Ñ0¸lÐ0ÐKÓLˆæ 4×#:Ñ#:×#>Ñ#>Ó#@Ñ#HØ8˜Ð8Ð$7Ð8ˆHä/>¸xÓ/HˆàÑ%ð $ˆFðBØ+ðBØ8LðBà%÷Bô
 & gÓGˆGð %×8Ñ8¸ÓA×LÀWˆGä+1¯=ª=¸×+HÑ+H™Èd×NbÑNbˆØÑ%ØÑ)ð ,�
à*<Ñ*HÑ&Èd×NfÑNfð -ðXØ/ðXØ<PðXà)÷Xð Xô "1°Ó!`�Ü% ~Ð&?Ó@ˆGàˆr°   c                ó   • U R                   $ )zIThe root capability of the agent, containing all registered capabilities.)r†  rY  s    r±   r>  ÚAgent.root_capabilityí  s   € ð ×$Ñ$Ð$r°   c                ó"   • U R                  5       $ )z�All toolsets registered on the agent, including a function toolset holding tools that were registered on the agent directly.

Output tools are not included.
©rµ  rY  s    r±   rc  ÚAgent.toolsetsò  s   € ð ×'Ñ'Ó)Ð)r°   c                ó    • U R                  SS9$ )zÆThe toolsets this agent was built with, ignoring anything added afterwards.

Read by `pydantic_ai.durable_exec` through `construction_toolsets`, which is where the
reason it exists is written down.
T©Úignore_overridesr»  rY  s    r±   Ú_construction_toolsetsÚAgent._construction_toolsetsú  s   € ð ×'Ñ'¸Ð'Ð>Ð>r°   r¾  c               óØ  • / nU(       dL  U R                   R                  5       =n(       a+  [        UR                  SU R                  U R
                  S9nOU R                  nUR                  U5        U(       d>  U R                  R                  5       =n(       a  UR                  UR                  5        U$ UR                  U R                  5        U(       a  U R                  SU R                   OU R                  nUR                  U5        Ub  UOU R                   HE  n[        U[        5      (       a  UR                  U5        M+  UR                  [!        U5      5        MG     U$ )aE  Build the list of toolsets, optionally with per-run capability toolsets.

With `ignore_overrides`, active `override(tools=...)`/`override(toolsets=...)` values and
dynamic toolsets added with `@agent.toolset` after construction are skipped, so the result
is what the agent was built with. See
`Agent._construction_toolsets`.
Nro  )rx  r  r�  r  rL  r>  rE  rï   rw  rµ  rH  r’  r”  r™  ró   rx   rz   )	rZ  r;  r¿  rc  Ú
some_toolsÚfunction_toolsetÚsome_user_toolsetsÚdynamic_toolsetsÚcap_tss	            r±   rµ  ÚAgent._build_toolset_list  s?  € ð 79ˆæ°4×3GÑ3G×3KÑ3KÓ3MÐ%M ZÕ%Mô  5Ø× Ñ Ø Ø×*Ñ*Ø"×1Ñ1ñ	 Ñð  $×5Ñ5ÐØ�‰Ð(Ô)æ¸4×;RÑ;R×;VÑ;VÓ;XÐ%XÐ%7Õ%XØ�O‰OÐ.×4Ñ4Ô5ð  ˆð �O‰O˜D×/Ñ/Ô0ö $ð ×&Ñ&Ð'P¨×)PÑ)PÑQà×+Ñ+ð ð
 �O‰OÐ,Ô-Ø*6Ñ*B™,È×HZÑHZÒZ�Ü˜f¤o×6Ñ6Ø—O‘O FÖ+ð —O‘O¤N°6Ó$:Ö;ñ [ð ˆr°   c                ó   • g r¼   r§   ©rZ  r^  s     r±   r†  ÚAgent._prepare_output_schema2  s   € Ø^ar°   c                ó   • g r¼   r§   rÊ  s     r±   r†  rË  5  r  r°   c                ó´   • UbH  U R                   (       a  [        R                  " S5      e[        R                  R                  U5      nU$ U R                  nU$ )NzJCannot set a custom run `output_type` when the agent has output validators)r?  r/   rŽ  r+   r‰  rŠ  r>  )rZ  r^  Úschemas      r±   r†  rË  :  sR   € ØÑ"Ø×&×&Ü ×*Ò*Ð+wÓxÐxÜ×)Ñ)×/Ñ/°Ó<ˆFð ˆð ×(Ñ(ˆFàˆr°   ©rÜ  r"  r  rc  rg  r2   rõ  r$  ró  rô  rñ  Úrun_lifecyclec              óx  ^
^^^9^:^;^<^=#   • SSK JnJn  [        X5      (       d  U" U5      nU R	                  U5      n[
        R                  " T
T5      m
[
        R                  " TT5      mU R                  5       nU(       a
  [        5       OSm9[        [           " UU UUb  UO[        R                  " 5       Ub  UO[        R                  " SS9ST
TT(       a  [        T5      O/ US9
m=[
        R                   " U R"                  T=5      T=l        U R'                  [)        U5      5      nU R+                  5       nUb	  [-        US9OSnU R/                  5       /UQnU VVs/ s H/  n[1        U5        H  n[        U[,        5      (       d  M  UPM     M1     nnnU(       a  US   OSnUb  UR2                  OUnUb  UR4                  O	[7        5       T=l        USL=(       a    UR8                  T=l        Ub  UR<                  T=l        U RA                  T=U	5      T=l!        U RE                  5       u  nnU RG                  T=UUUSUS	9I Sh  v•N nURH                  m<T=RJ                  RM                  5        VVs/ s HB  u  nnURN                  SL d  M  URQ                  5       c  URS                  5       (       d   M@  UPMD     nnnU(       a2  SRU                  S U 5       5      n [V        RX                  " SU  S35      eT<T=l-        [
        R\                  " / T=R^                  TT
T=RB                  S9m;UR2                  (       a  UR2                  Ra                  5       OSn!U(       a%  U!c  URa                  5       n!OU!Rc                  U5        U!T=l2        / n"URf                   H…  n#[        U#[h        5      (       d4  U#" T=5      n$[j        Rl                  " U$5      (       a
  U$I Sh  v•N n$U$c  MJ  U$n#[        U#[n        5      (       a  U#Rp                  (       a  Mt  U"Rs                  U#5        M‡     URt                  n%U Rw                  SUURx                  T<S9n&U&R{                  T=5      I Sh  v•N n&U(       a
  [}        5       OSm:S#U:U;4S jjn'S$U9U:4S jjn([~        S%U9U
U:UU=U4S jj5       n)Sn*[�        5        ISh  v•N n+T:bÚ  T9c   eT9T=lA        U+R…                  U)" 5       5      I Sh  v•N   T9R‡                  5         U+R‰                  T9RŠ                  5        U+R…                  [�        T<T=U'U(S95      I Sh  v•N n,U,RŽ                  (       aQ   [‘        UT=[“        [•        5       5      [–        R˜                  " 5       U!S/ U%UT
TT:SS97v •  Sn* SSS5      ISh  v•N   gU+R…                  U&5      I Sh  v•N   [’        [           " U&T<US9R›                  T=5      I Sh  v•N n-U-Rœ                  n.U RŸ                  UUR                   S9n/[¢        R¤                  " U/T=5      I Sh  v•N n0U0R§                  [©        U-Rª                  T=5      I Sh  v•N 5        [¬        R®                  RU                  [¬        R®                  R±                  U05      5      n1/ T=(       d    S
Q[¬        R²                  " / U1=(       d    SS9Pn2[–        R˜                  " U.U"S9n3[–        R´                  " U3U%R·                  SS5      S9n3[–        R¸                  " U3U%R·                  S[»        5       5      5      n3U3R¼                   V4s/ s H"  n4U4RN                  (       d  M  U4R¾                  PM$     n5n4U5(       a2  SRU                  S U5 5       5      n6[V        RX                  " SU6 S35      e[À        RÂ                  " U3U3RÄ                  S 9n3T<RÆ                  (       d  T<RÈ                  (       a  U<U=4S! jOSn7[‘        UT=U-U3U!U1=(       d    SU2U%UT
TU7T:S"9n8 U87v •  Sn*SSS5      ISh  v•N   U*(       a  gT:b  T:RÊ                  c   e[‘        UT=[“        [•        5       5      [–        R˜                  " 5       U!S/ U%UT
TT:SS97v •  gs  snnf  GNs  snnf  GN” GN GNÅ GN› GNP! Sn*f = f GNù GNâ GN» GNy GNSs  sn4f ! Sn*f = f N›! , ISh  v•N  (       d  f       N°= f7f)&uî  Resolve the agent configuration shared by realtime sessions and WebRTC signaling.

With `run_lifecycle`, the run-lifecycle hooks are dispatched around the resolved configuration
as well, so that they wrap the toolset â€” and the session the caller opens inside them â€” exactly
as `iter` does. Only [`_open_realtime_session`][pydantic_ai.agent.Agent._open_realtime_session]
asks for that: signaling only reads back the instructions and tools a session would advertise,
and is not itself a run.
r&   )rš   Úinfer_realtime_modelN)Úrequest_limit)
rÜ  r¾  r   r2   rõ  r"  ró  rô  r0   rp  r  r�  Tr!  r§   z, c              3  ó8   #   • U  H  n[        U5      v •  M     g 7fr¼   r7  )r(  Úcapability_ids     r±   r-  Ú2Agent._resolve_realtime_session.<locals>.<genexpr>Ò  s   é € Ð%lÒOk¸m¤d¨=×&9Ð&9ÒOkùó   ‚z§Realtime sessions cannot reveal tools mid-session, so deferred capabilities that contribute tools or native tools are not supported; remove `defer_loading=True` from: Ú.)rñ  r2   rô  ró  r$  )r9  r:  r;  rÌ   c                 ó^   >• T b  T R                   c   eT R                   R                  T5      $ r¼   )ÚsessionÚ_build_run_result)Úlifecycle_stateÚresult_states   €€r±   Ú_build_session_resultÚ>Agent._resolve_realtime_session.<locals>._build_session_result  s1   ø€ Ø"Ñ.°?×3JÑ3JÑ3VÐVÐVØ"×*Ñ*×<Ñ<¸\ÓJÐJr°   c              “  ó¸   >#   • Tc   eTb'  TR                   (       a  [        R                  " S5      eTR                  c  U Tl        g U TR                  l        g 7f©Nz6pydantic-ai: re-asserting a requested run cancellation)Úcancel_requestedrÂ   rö   rÚ  Úshort_resultÚ_result)r–   re  rÜ  s    €€r±   Ú_finalize_session_resultÚAAgent._resolve_realtime_session.<locals>._finalize_session_result  sT   øé € Ø"Ñ.Ð.Ð.ØÑ'¨L×,I×,IÜ×,Ò,Ð-eÓfÐfØ×&Ñ&Ñ.Ø/5�Õ,à28�×'Ñ'Õ/ùs   ƒAAc                óh  >#   • Tb  Tc   eSUUUUU4S jjn  S 7v •   TR                  5         g ! [         R                   a  nU " S5      UeS nAf[        R                   a6  nU " S5      nTR	                  5       (       a  X!eUR                  U5        e S nAff = f! TR                  5         f = f7f)Nc           
     óÞ   >• Tc   eTR                   n[        R                  " U Ub  UR                  5       O
T=(       d    S[	        T=(       d    S5      TR
                  TR                  TTS9$ )Nr§   )r0   rW  r2   r$  rô  ró  )rÚ  r/   ÚRunCancelledÚall_messagesr“  r2   r$  )ÚmessagerÚ  ró  rÜ  rñ  r3  rô  s     €€€€€r±   Ú_run_cancelledÚXAgent._resolve_realtime_session.<locals>._translate_cancellation.<locals>._run_cancelled%  so   ø€ Ø&Ñ2Ð2Ð2Ø)×1Ñ1�Ü!×.Ò.ØØ7>Ñ7J˜W×1Ñ1Ô3ÐP_×PeÐceÜ&)¨/×*?¸RÓ&@Ø%×+Ñ+Ø(×1Ñ1Ø!Ø$3ñð r°   ú,The agent run was cancelled by a nested run.úThe agent run was cancelled.©rë  r	  rà   zexceptions.RunCancelled)r/   ré  rÂ   rö   ÚresolveÚ
_attach_toÚrelease_issued)	rì  rÿ   Ú	cancelledre  ró  rÜ  rñ  r3  rô  s	      €€€€€€r±   Ú_translate_cancellationÚ@Agent._resolve_realtime_session.<locals>._translate_cancellation!  s¯   øé € àÑ+°Ñ0KÐKÐK÷ó ð.Ýð ×+Ñ+Õ-øô ×*Ñ*ó ^ñ %Ð%SÓTÐZ]Ð]ûÜ×)Ñ)ó Ù*Ð+IÓJ�	Ø×'Ñ'×)Ñ)Ø#Ð,Ø×$Ñ$ SÔ)Øûðûð ×+Ñ+Õ-üs=   ƒB2™0 ŸB2°BÁ	AÁBÁ$1BÂBÂB ÂB/Â/B2F)rÊ   rÛ   )r   r3  rc  Úmodel_request_parametersr"  r  Úrequest_messagesÚmodel_profilerd  ró  rô  Ú	lifecycler¶   r=  r@  )Úpartsr  )Úfunction_toolsrb  Úsupports_tool_return_schema)rý  Úsupported_native_toolsc              3  ó8   #   • U  H  n[        U5      v •  M     g 7fr¼   r7  )r(  r%  s     r±   r-  rÖ  ¤  s   é € Ð+WÒCV¸4¬D°¯J¨JÒCVùr×  zyRealtime sessions cannot reveal tools mid-session, so tools with `defer_loading=True` are not supported; remove it from: )rü  c                ó8   >• TR                  T[        TU 5      S9$ )N)Ústream)Úwrap_run_event_streamr@   )r  rÌ   r3  s    €€r±   Ú<lambda>Ú1Agent._resolve_realtime_session.<locals>.<lambda>¹  s#   ø€  >×#GÑ#GØ#Ô,AÀ+ÈvÓ,Vð $Hñ $r°   )r   r3  rc  r÷  r"  r  rø  rù  rd  ró  rô  Úwrap_event_streamrú  rß   rã   ©rà   zAsyncGenerator[None])fÚrealtimerš   rÒ  ró   r|  r'   rŠ  r‰  r{  r;   rm   rf   r}  r~  r‹  r‘  Úbuild_validation_contextrN  rb  r  rK   r�  rŽ  rÖ  rR   r  r  r   r�  r  r�  r  r‘  r$  rx  r’  rÌ   rg  Úitemsr8  r�  r¢  Újoinr/   rŽ  r>  rˆ  r2   r   rè   r"  rb  rZ   r  r~  r[   Úoptionalrï   Úprofiler•  rc  r–  r�   r   r   r   Úenter_async_contextÚbindrð   Úfinishr  r¶   rŽ   re   r�   r1   ÚModelRequestParametersÚfor_run_stepr©  r—  r  r*   rD  rµ  r|   r�  r
  r  ÚsortedÚModelRequestÚprepare_return_schemasr  Úresolve_request_toolsÚ	frozensetrü  r%  Údataclassesr   Údeclared_function_toolsÚhas_wrap_run_event_streamro  rã  )>rZ  r   rÜ  r"  r  rc  rg  r2   rõ  r$  ró  rô  rñ  rÐ  rš   rÒ  Úmax_tool_retriesr#  rd  r$  Úinstrumentation_layersr*  ÚleafÚexplicit_instrumentationsÚexplicit_instrumentationÚ session_instrumentation_settingsr"  r&  r±  rÕ  rú   Úundeliverable_capability_idsÚformatted_idsÚeffective_model_settingsrb  Únative_toolÚresolved_nativerù  r�  rÞ  rå  rõ  ÚyieldedÚsession_stackrú  rc  r©  rE  Úinstruction_partsÚresolved_instructionsrø  r÷  r-  Údeferred_tool_namesÚformatted_namesr  Ú
resolutionre  rÜ  rÝ  rÌ   r3  s>             ```                                            @@@@@r±   Ú_resolve_realtime_sessionÚAgent._resolve_realtime_sessionD  sØ  ÿé € ÷4 	Cä˜%×/Ñ/Ù(¨Ó/ˆEà�~‰~˜dÓ#ˆô '×>Ò>¸ÐP_Ó`ˆÜ×,Ò,¨V°_ÓEˆØ×5Ñ5Ó7ÐÞ,9”Ô(¸tˆÜ ¤Ò,ØØØØ Ñ,‘%´&·/²/Ó2Cð *6Ñ)A™Äv×GYÒGYÐhlÑGmØØ+Øö />”T˜/Ô*À2Ø(ñ#
ˆô, *6×)NÒ)NÈt×OgÑOgÐitÓ)uˆÔ&ð "×8Ñ8Ô9NÈ|Ó9\Ó]ÐØ#'×#IÑ#IÓ#KÐ àE]ÑEiÔÐ(@ÒAÐosð 	ð$ #'×"AÑ"AÓ"CÐ!YÐFXÐ!YÐñ 0ô%
â/�Ü)¨%×0�Ü˜$Ô 2×3÷ á0ñ Ù/ð 	"ñ %
ö E^Ð#<¸RÒ#@ÐcgÐ à1IÑ1UÐ$×-Ò-Ð[sð 	)ð 8XÑ7cÐ,×3Ò3ÔisÓiuð 	Ôð -°DÐ8×mÐ=]×=mÑ=mð 	Ô)ð ,Ñ7Ø2R×2ZÑ2ZˆKÔ/Ø#×1Ñ1°+¸xÓHˆÔð -1×,EÑ,EÓ,GÑ)ˆÐ)Ø"×<Ñ<ØØ+Ø1Ø 3Ø#'Ø-ð =ð 
÷ 
ˆð '×5Ñ5ˆð .9×-EÑ-E×-KÑ-KÔ-Mô(
â-MÑ)�˜zØ×'Ñ'¨4Ð/ó ð ×'Ñ'Ó)Ñ5¸*×:UÑ:U×:WÑ:WÐ[]õ Ù-Mð 	%ñ (
ö (Ø ŸI™IÑ%lÑOkÓ%lÓlˆMÜ×&Ò&ðà&˜ qð*óð ð '5ˆÔ#ô $×3Ò3ØØ×#Ñ#ØØ+Ø ×)Ñ)ñ
ˆð [`×Zh×ZhÀÇÁ×ATÑATÔAVÐnrÐ ÞØ'Ñ/Ø+9×+>Ñ+>Ó+@Ñ(à(×/Ñ/°Ô?ð &>ˆÔ"ð 24ˆØ(×5Ô5ˆKÜ˜kÔ+=×>Ñ>Ù"-¨kÓ":�Ü×&Ò& ×7Ñ7Ø,;×&;�OØ"Ñ*ÙØ-�Ü˜{¬N×;Ñ;À×@T×@TÑ@TØ×#Ñ# KÖ0ñ 6ð Ÿ™ˆà×#Ñ#ØØ (Ø&×/Ñ/Ø)ð	 $ð 
ˆð  Ÿ™¨Ó4×4ˆö :GÔ3Ô5ÈDˆ÷	Kð 	K÷	9ð 	9ô 
÷	.ó 	.ó 
ð	.ð> ˆÜ!×#Ô# }ØÑ*Ø#Ñ/Ð/Ð/ð -9�Ô)Ø#×7Ñ7Ñ8OÓ8QÓR×RÐRØ×!Ñ!Ô#Ø×&Ñ& |×':Ñ':Ô;Ø"/×"CÑ"CÜ(Ø&Ø#Ø%:Ø!9ñ	ó#÷ �	ð ×,×,ð'Ü8Ø"'Ø(3Ü)4´_Ó5FÓ)GÜ5;×5RÒ5RÓ5TØ+CØ)-Ø-/Ø*7Ø5UØ,;Ø#)Ø&5Ø,0ñó ð  #'˜Ø÷W $×#Ð#ðX  ×3Ñ3°GÓ<×<Ð<Ü!,¬ZÒ!8Ø¨ÐM]ñ"ç‰l˜;Ó'÷(ˆLð %×.Ñ.ˆIð
 $(×#9Ñ#9Ø(4À}×GaÑGað $:ð $Ð ô '4×&PÒ&PÐQeÐgrÓ&s× sÐØ×$Ñ$Ô+GÈ×H\ÑH\Ð^iÓ+j×%jÔkÜ$-×$=Ñ$=×$BÑ$BÄ9×C\ÑC\×CcÑCcÐduÓCvÓ$wÐ!ð Ø!×' Rð ä×&Ò&¨RÐ>S×>[ÐW[Ñ\ð Ðô (.×'DÒ'DØ(Ø)ñ(Ð$ô (.×'DÒ'DØ(Ø,9×,=Ñ,=Ð>[Ð]bÓ,cñ(Ð$ô (.×'CÒ'CØ(¨-×*;Ñ*;Ð<TÔV_ÓVaÓ*bó(Ð$ð :R×9`Ò9`Ó"wÒ9`°Ðdh×dvÕdv£9 4§9¤9Ñ9`ÐÐ"wÞ"Ø"&§)¡)Ñ+WÑCVÓ+WÓ"W�Ü ×*Ò*ðOØO^ÐN_Ð_`ðbóð ô (3×':Ò':Ø(Ø7×OÑOñ(Ð$ð" "×;×;¸~×?Z×?Zö	ð
 ð ô  4ØØ'Ø)Ø)AØ7Ø2×:°dØ!1Ø+Ø)IØ /ØØ"3Ø)ñˆJðØ Ó à�÷c $×#öf ð ð Ñ*¨×/KÑ/KÑ/WÐWÐWÜ(ØØ#Ü$¤_Ó%6Ó7Ü%+×%BÒ%BÓ%DØ3ØØØ'Ø%EØ+ØØ%Ø ñ
ô 	
ùóE
%
ò:
ùó (
òj '<ò 5òh $ò SòøðB #'™úòU $òX =ò(ò !tÚ%jùòF #xøðb ‘ú÷c $×#×#Ð#üs‰  ŠEb:Å(aÆ

aÆB1b:Éa$É-b:É3a'Ê'a'Ê6a'Ê<Db:Ïa-Ï/b:ÐAb:Ña0ÑAb:Ò.a3Ò/b:Ò2)b Óa6ÓAb Ô)a9Ô*b Õ <a<Õ<b Õ?b:Ö
bÖb:Öb Ö$bÖ%)b ×b	×Ab ØbØ(b Ø<b
Ø=C&b Ü#bÜ<bÝB#b ß0bß5b ß7b:àbàA"b:á'b:á0b:á3b:á6b á9b á<b â b âb:âb â	b âb âb âb âbâb âb:â b7â&b)â'b7â3b:Útranscript_onlyrƒ   éd   )rÜ  r"  r  rc  rg  r2   rõ  r$  ró  rô  rñ  Úaudio_retentionÚhandle_barge_inÚretain_images_every_nÚretain_images_maxÚprovider_sessionc              óF  ^^^^^#   • SSK Jm  SSKJnJmJn  USL nU(       d  US:w  a  [        R                  " S5      eSnU R                  UUUUUUUTU	U
UTSS	9 ISh  v•N mTR                  nUc   eS)UUUUU4S
 jjnTR                  (       a9  UR                  c   e U" UR                  5      7v •  Sn SSS5      ISh  v•N   gT(       aP  TR                  R                  SS5      (       d/  [        R                  " STR                  R                  < S35      eTR                   =(       d    0 R                  SS5      nUS:X  aP  TR                  R                  SS5      (       d/  [        R                  " STR                  R                  < S35      eUc9  TR                  R#                  TR$                  TR                   TR&                  S9O9TR                  R)                  UTR$                  TR                   TR&                  S9nU ISh  v•N nT" U40 STR                  _STR*                  _SU_STR,                  _SU R.                  =(       d    S_STR0                  R2                  _ST_SU_SU_SU_SU_S T_S!TR4                  _S"TR6                  _S#TR8                  _S$TR0                  R:                  _S%TR,                  b%  U R=                  TR0                  R>                  5      OS_SU_S&TR&                  _S'TR                   _S(TR@                  _6nUUl!        UTR0                  l"        U ISh  v•N    U7v •  SnSSS5      ISh  v•N   SSS5      ISh  v•N   SSS5      ISh  v•N   U(       a  gWR                  c   eW" UR                  5      7v •  g GNT! Snf = f GNø GN§ Ny! Snf = f Nj! , ISh  v•N  (       d  f       N= f Nv! , ISh  v•N  (       d  f       N‹= f N‚! , ISh  v•N  (       d  f       N—= f7f)*aD  Worker behind [`AgentRealtime.session`][pydantic_ai.agent.AgentRealtime.session].

Opens the realtime session and drives the agent's tools. Users go through
[`agent.realtime(model).session()`][pydantic_ai.agent.AbstractAgent.realtime]; see
[`realtime`][pydantic_ai.agent.AbstractAgent.realtime] for the parameter reference.
r&   )r�   )ÚRealtimeCodecEventÚRealtimeConnectionÚRealtimeInputNr.  zïA WebRTC sideband session can't retain audio: the browser exchanges audio with the provider directly, so no audio bytes reach this connection. Leave `audio_retention` at 'transcript_only' (transcripts still build the conversation history).FTrÏ  c                óþ   >•  " S ST5      nT" U" 5       TR                   TR                  TR                  R                  TTTR                  TR
                  TR                  R                  S9	nXl        SUl        U$ )Nc                  ó(   • \ rS rSrSS jrSS jrSrg)ÚYAgent._open_realtime_session.<locals>._closed_session.<locals>._SkippedRealtimeConnectioni1  c              “  ó6   #   • [         R                  " S5      e7f©Nz<This realtime session was short-circuited before connecting.©r/   rŽ  )rZ  Úcontents     r±   ÚsendÚ^Agent._open_realtime_session.<locals>._closed_session.<locals>._SkippedRealtimeConnection.send2  s   é € Ü(×2Ò2ØZóð ùs   ‚c                ó.   • [         R                  " S5      er=  r>  rY  s    r±   Ú	__aiter__ÚcAgent._open_realtime_session.<locals>._closed_session.<locals>._SkippedRealtimeConnection.__aiter__7  s   € Ü(×2Ò2ØZóð r°   r§   N)r?  r8  rà   râ   )rà   z!AsyncIterator[RealtimeCodecEvent])r©   rª   r«   r¬   r@  rC  r¯   r§   r°   r±   Ú_SkippedRealtimeConnectionr;  1  s   † ô÷
r°   rE  )r   rc  r2   rõ  rñ  ró  rô  r$  T)	r   rc  r3  r2   ró  rô  r$  rä  Ú_closed)r–   rE  rÚ  r7  r�   rñ  rŸ  rõ  s      €€€€€r±   Ú_closed_sessionÚ5Agent._open_realtime_session.<locals>._closed_session-  sy   ø€ ô	Ð1Cô 	ñ *Ù.Ó0Ø"Ÿ.™.Ø!)×!6Ñ!6Ø"×.Ñ.×4Ñ4Ø!-Ø$3Ø$,×$<Ñ$<Ø#Ÿ?™?Ø%×1Ñ1×:Ñ:ñ
�ð #)”Ø"&�”Ø�r°   Úsupports_session_seedingzThe zJ realtime model does not support seeding a session with `message_history`.Úoutput_modalityÚaudioÚtextÚsupports_text_outputz› realtime model does not support `output_modality='text'`; it only generates audio. Read the spoken answer from the transcript on the `SpeechPart` instead.)r0   r"  r÷  r   rc  Ú
owns_mediaÚinstrumentationrn  r¾  r2   rõ  r0  r1  r2  r3  rñ  ró  rô  r  r$  Úagent_descriptionr÷  r"  r  )r–   rá   rà   r�   )#r  r�   Úrealtime.codecr6  r7  r8  r/   rŽ  r,  rú  r¶   rã  rù  r  r   Ú
model_namer"  Úconnectrø  r÷  Úconnect_webrtcrc  rd  r%  r3  r2   ró  rô  r  r$  rÝ  rÜ  r  rÚ  Úrealtime_session)rZ  r   rÜ  r"  r  rc  rg  r2   rõ  r$  ró  rô  rñ  r0  r1  r2  r3  r4  r6  r8  rN  r%  rú  rG  rJ  Úconnection_managerÚ
connectionrÚ  r7  r�   rŸ  s           `   `               @@@r±   Ú_open_realtime_sessionÚAgent._open_realtime_sessionð  sl  üé € õ8 	/ßZÑZð &¨Ð-ˆ
Þ˜oÐ1BÓBä×&Ò&ðXóð ð ˆØ×1Ñ1ØØØ)Ø%ØØ%ØØ%ØØ+ØØ+Øð 2÷ 
ñ 
ð Ø ×*Ñ*ˆIØÑ(Ð(Ð(÷ó ð< ×'×'Ø ×-Ñ-Ñ9Ð9Ð9ð
#Ù)¨)×*@Ñ*@ÓAÓAà"�GØ÷u
÷ 
ð 
öx  x×'=Ñ'=×'AÑ'AÐB\Ð^c×'dÑ'dÜ ×*Ò*Ø˜8Ÿ>™>×4Ñ4Ñ7ð 8)ð )óð ð
  (×6Ñ6×<¸"×AÑAÐBSÐU\Ó]ˆOð  &Ó(°×1GÑ1G×1KÑ1KÐLbÐdh×1iÑ1iÜ ×*Ò*Ø˜8Ÿ>™>×4Ñ4Ñ7ð 8,ð ,óð ð $Ñ+ð —‘×&Ñ&Ø%×6Ñ6Ø#+×#:Ñ#:Ø-5×-NÑ-Nð 'ñ ð —^‘^×2Ñ2Ø$Ø%×6Ñ6Ø#+×#:Ñ#:Ø-5×-NÑ-Nð	 3ð ð ÷ *Ñ)¨ZÙ)Øò à"Ÿ.š.ð ð "*×!6Ò!6ð ñ  *ð	 ð
 %-×$EÒ$Eð ð  $Ÿy™y×3¨Gøð ð #×.Ñ.×4Ò4ð ñ ".ð ñ %4ð ñ %4ð ñ +@ð ñ '8ð ñ  %4ð! ð" %-×$<Ò$<ð# ð$ $Ÿ?š?ð% ð& "*×!6Ò!6ð' ð( &×1Ñ1×:Ò:ð) ð. $×<Ñ<ÑHð ×/Ñ/°×0DÑ0D×0IÑ0IÔJà!øð1 ñ4 %4ð5 ð: .6×-NÒ-Nð; ð< $,×#:Ò#:ð= ð> '/×&@Ò&@ð? �ðB %,�	Ô!Ø8?�×$Ñ$Ô5ß"š7ð'Ø%›à"&˜÷	 #Ÿ7÷I *×)÷w
÷ 
öJ ð ð
 ×%Ñ%Ñ1Ð1Ð1Ù˜i×4Ñ4Ó5Ô5ò]
øðr #‘Gúòs
òv *ñH #øð #'™ú÷	 #Ÿ7Ÿ7˜7ú÷I *×)×)Ð)ú÷w
÷ 
÷ 
ð 
üs(  ‡AP!Á N4Á!P!Á$>PÂ#N7Â8PÂ;P!ÃN>ÃP!ÃEPÈOÈPÈD,O+Í
O
ÍO+ÍOÍOÍOÍO+Í"OÍ#O+Í'PÍ2O)Í3PÍ7P!ÎPÎ2P!Î7N;Î;PÎ>P!ÏPÏO+ÏO
	Ï
OÏO+ÏO&ÏOÏO&Ï"O+Ï)PÏ+P	Ï1O4Ï2P	Ï>PÐP!ÐPÐPÐPÐP!c              ƒ  ód  #   • U R                    ISh  v•N   U R                  S:X  Gaœ  [        5        ISh  v•N nU R                  5       nUR	                  U5      I Sh  v•N   U R                  5       nUR                  5       nU R                  R                  5       nUb  UR                  nO5[        U5      (       a  [        U5      (       d  SnOUb  UnOU R                  nUb¹  [        U[        5      (       a  UR                  (       d“  [        U5      (       a  UO[         R"                  " U5      nUR	                  U5      I Sh  v•N   U R$                  R'                  [)        U5      5        [        U[        5      (       a  XpR*                  [)        U5      U4'   UR-                  5       U l        SSS5      ISh  v•N   U =R                  S-  sl        SSS5      ISh  v•N   U $  GNÙ GN¸ GN’ N« N6! , ISh  v•N  (       d  f       NK= f N-! , ISh  v•N  (       d  f       U $ = f7f)a  Enter the agent context.

This will start all [`MCPToolset`s][pydantic_ai.mcp.MCPToolset] registered as `toolsets` so they are ready to be used,
and enter the model so the provider's HTTP client will be closed cleanly on exit.

This is a no-op if the agent has already been entered.
Nr   rƒ   )r[  rS  r   r•  r  rÖ  r€  rv  r  r  rz  r  r   ró   r	  rž  r1   rŸ  r—  Úaddrå   r˜  Úpop_allrU  )rZ  Ú
exit_stackr�  rú   Úcapability_modelrÝ  Ústatic_selectionr   s           r±   Ú
__aenter__ÚAgent.__aenter__«  sÆ  é € ð ×#×#Ó#Ø×"Ñ" aÔ'Ü)×+Ô+¨zØ"×/Ñ/Ó1�GØ$×8Ñ8¸ÓA×AÐAà!%×!@Ñ!@Ó!B�JØ'1×';Ñ';Ó'=Ð$Ø%)×%9Ñ%9×%=Ñ%=Ó%?�NØ%Ñ1Ø+9×+?Ñ+?Ñ(Ü!Ð"2×3Ñ3¼IÐFV×<WÑ<Wà+/Ñ(Ø)Ñ5Ø+;Ñ(à+/¯:©:Ð(Ø'Ñ3Ü"Ð#3´S×9Ñ9¸j×>]×>]ô 1:Ð:J×0KÑ0KÑ,ÔQW×QcÒQcÐdtÓQuð ð )×<Ñ<¸UÓC×CÐCØ×/Ñ/×3Ñ3´B°u³IÔ>Ü%Ð&6¼×<Ñ<Øbg×=Ñ=¼bÀ»nÐN^Ð>^Ñ_à'1×'9Ñ'9Ó';�DÔ$÷7 ,×+ð8 ×Ò 1Ñ$Õ÷= $×#ð> ˆò? $â+âAñ( D÷- ,×+×+Ð+ú÷ $×#×#ð> ˆüs¯   ‚H0“G,”H0— H·G/¸H»%G9Á G2Á!C(G9Å	G5Å
A+G9Æ5HÇ G7ÇHÇH0Ç%HÇ&H0Ç/HÇ2G9Ç5G9Ç7HÇ9H	Ç?HÈ H	ÈHÈH0ÈH-ÈHÈH-È(H0c              ‡  ó6  #   • U R                    IS h  v•N   U =R                  S-  sl        U R                  S:X  ak  U R                  b^   U R                  R                  5       I S h  v•N   S U l        U R                  R                  5         U R                  R                  5         S S S 5      IS h  v•N   g  N¥ NR! S U l        U R                  R                  5         U R                  R                  5         f = f NI! , IS h  v•N  (       d  f       g = f7f)Nrƒ   r   )r[  rS  rU  Úacloser—  rç   r˜  )rZ  Úargss     r±   Ú	__aexit__ÚAgent.__aexit__Ô  sÐ   é € Ø×#×#Ó#Ø×Ò 1Ñ$ÕØ×"Ñ" aÓ'¨D×,<Ñ,<Ñ,Hð>Ø×*Ñ*×1Ñ1Ó3×3Ð3à'+�DÔ$Ø×+Ñ+×1Ñ1Ô3Ø×5Ñ5×;Ñ;Ô=÷ $×#Ò#ñ 4øà'+�DÔ$Ø×+Ñ+×1Ñ1Ô3Ø×5Ñ5×;Ñ;Õ=ú÷ $×#×#Ð#üsn   ‚D“B9”D—3C?ÁB=Á(B;Á)B=Á-;C?Â(DÂ3C=Â4DÂ;B=Â==C:Ã:C?Ã=DÃ?DÄDÄDÄDc                óØ  ^^•  U(       a  [         R                  " U5      OU R                  5       mSSK	J
m  SUU4S jjnU R                  5       R                  U5        g! [        R                   au  nU R                  5       nUcF  [        UR                  5       5      (       d  UR                  (       a  [        R                  " S5      Ue[        R                  " S5      UeSnAff = f)z¨Set the sampling model on all [`MCPToolset`s][pydantic_ai.mcp.MCPToolset] registered with the agent.

If no sampling model is provided, the agent's model will be used.
Nz{The capability model requires run dependencies and cannot be used for MCP sampling setup. Pass a concrete model explicitly.z9No sampling model provided and no model set on the agent.r&   )Ú
MCPToolsetc                óL   >• [        U T5      (       a  U R                  T5        g g r¼   )ró   Úset_sampling_model)r�  rh  Úsampling_models    €€r±   Ú_set_sampling_modelÚ9Agent.set_mcp_sampling_model.<locals>._set_sampling_modelñ  s#   ø€ Ü˜' :×.Ñ.Ø×*Ñ*¨>Õ:ð /r°   )r�  úAbstractToolset[AgentDepsT]rà   râ   )r1   rŸ  r†  r/   rŽ  rÖ  rz  r€  rž  Úmcprh  r•  r   )rZ  r   Úerú   rl  rh  rk  s        @@r±   Úset_mcp_sampling_modelÚAgent.set_mcp_sampling_modelß  sË   ù€ ð
		kÞ:?œV×/Ò/°Ô6ÀT×E`ÑE`ÓEbˆNõ 	%÷	;ð 	;ð 	×ÑÓ×!Ñ!Ð"5Õ6øô ×#Ñ#ó 	kØ×8Ñ8Ó:ˆJØ‰}¤(¨:×+?Ñ+?Ó+A×"BÑ"BÀj×Fe×FeÜ ×*Ò*ð8óð ðô ×&Ò&Ð'bÓcÐijÐjûð	kús   „-A  Á C)Á4A0C$Ã$C)©r1   rÜ  r"  r  Úhtml_sourceÚallowed_hostsc          
     ó&   • SSK Jn  U" U UUUUUUS9$ )a
  Create a Starlette app that serves a web chat UI for this agent.

This method returns a pre-configured Starlette application that provides a web-based
chat interface for interacting with the agent. By default, the UI is fetched from a
CDN and cached on first use.

The returned Starlette application can be mounted into a FastAPI app or run directly
with any ASGI server (uvicorn, hypercorn, etc.).

Note that the `deps` and `model_settings` will be the same for each request.
To provide different `deps` for each request use the lower-level adapters directly.

The agent's configured native tools (registered via `capabilities=[NativeTool(...)]`
or higher-level capabilities like `WebSearch()`) are automatically exposed as
options in the UI.

Args:
    models: Additional models to make available in the UI. Can be:
        - A sequence of model names/instances (e.g., `['openai:gpt-5', 'anthropic:claude-sonnet-4-6']`)
        - A dict mapping display labels to model names/instances
          (e.g., `{'GPT 5': 'openai:gpt-5', 'Claude': 'anthropic:claude-sonnet-4-6'}`)
        The agent's model is always included. Native tool support is automatically
        determined from each model's profile.
    deps: Optional dependencies to use for all requests.
    model_settings: Optional settings to use for all model requests.
    instructions: Optional extra instructions to pass to each agent run.
    html_source: Path or URL for the chat UI HTML. Can be:
        - None (default): Fetches from CDN and caches locally
        - A Path instance: Reads from the local file
        - A URL string (http:// or https://): Fetches from the URL
        - A file path string: Reads from the local file
    allowed_hosts: Additional hostnames to answer to, e.g. `['ui.example.com']` or
        `['*.example.com']` (subdomains only, so list the apex separately if you serve it).
        IP addresses and `localhost` are always allowed; any other `Host` header is refused
        with a `421`, so that a website cannot reach the UI on your machine by pointing a
        hostname it controls at you (DNS rebinding). Pass `['*']` to answer to any host,
        only if something in front of the app already authenticates requests.

Returns:
    A configured Starlette application ready to be served (e.g., with uvicorn)

Example:
    ```python
    from pydantic_ai import Agent
    from pydantic_ai.capabilities import NativeTool
    from pydantic_ai.native_tools import WebSearchTool

    agent = Agent('openai:gpt-5', capabilities=[NativeTool(WebSearchTool())])

    # Simple usage - uses agent's model and native tools
    app = agent.to_web()

    # Or provide additional models for UI selection
    app = agent.to_web(models=['openai:gpt-5', 'anthropic:claude-sonnet-4-6'])

    # Then run with: uvicorn app:app --reload
    ```
r&   )Úcreate_web_apprs  )Úui._webrw  )rZ  r1   rÜ  r"  r  rt  ru  rw  s           r±   Úto_webÚAgent.to_web÷  s*   € õH 	-áØØØØ)Ø%Ø#Ø'ñ
ð 	
r°   )0rš  rœ  r›  r™  rR  r”  r<  r/  r’  rS  r—  r˜  r…  rP  rU  rE  r*   r5  rI  rJ  r:  r,  r-  r>  rF  r3  r?  ru  rz  r{  rv  r|  rt  ry  r}  r  r~  rx  rw  r†  rD  rC  rB  rL  rH  rN  r0  r"  )rà   z
anyio.Lockr¼   )&r   r+  r^  r2  r  úAgentInstructions[AgentDepsT]r_  ústr | Sequence[str]r`  r;  r%  r  ra  r.  r"  r1  r  úint | AgentRetries | Nonerb  rM  r¥   ú<Sequence[Tool[AgentDepsT] | ToolFuncEither[AgentDepsT, ...]]rc  ú)Sequence[AgentToolset[AgentDepsT]] | Nonerd  rµ   r0  r4   r$  r9  re  rK  rf  ú _concurrency.AnyConcurrencyLimitrg  ú,Sequence[AgentCapability[AgentDepsT]] | Nonerà   râ   )(r®  údict[str, Any] | AgentSpecr«  ú'Sequence[type[AbstractCapability[Any]]]r   r+  r^  úOutputSpec[Any]r  úAgentInstructions[Any]r_  r|  r%  r  ra  úTemplateStr[Any] | str | Noner"  r!  r  r}  rb  r   r¥   ú.Sequence[Tool[Any] | ToolFuncEither[Any, ...]]rc  ú"Sequence[AgentToolset[Any]] | Nonerd  rµ   r0  úEndStrategy | Noner$  úAgentMetadata[Any] | Nonere  rK  rf  r€  rg  ú%Sequence[AgentCapability[Any]] | Nonerà   úAgent[object, str])*r®  r‚  r`  útype[T]r«  rƒ  r   r+  r^  r„  r  r…  r_  r|  r%  r  ra  r†  r"  r!  r  r}  rb  r   r¥   r‡  rc  rˆ  rd  rµ   r0  r‰  r$  rŠ  re  rK  rf  r€  rg  r‹  rà   úAgent[T, str])*r®  r‚  r`  ú	type[Any]r«  rƒ  r   r+  r^  r„  r  r…  r_  r|  r%  r  ra  r†  r"  r!  r  r}  rb  r   r¥   r‡  rc  rˆ  rd  rµ   r0  r‰  r$  rŠ  re  rK  rf  r€  rg  r‹  rà   úAgent[Any, Any])*rÁ  ú
Path | strr¿  úLiteral['yaml', 'json'] | Noner«  rƒ  r   r+  r^  r„  r  r…  r_  r|  r%  r  ra  r†  r"  r!  r  r}  rb  r   r¥   r‡  rc  rˆ  rd  rµ   r0  r‰  r$  rŠ  re  rK  rf  r€  rg  r‹  rà   rŒ  ),rÁ  r‘  r¿  r’  r`  r�  r«  rƒ  r   r+  r^  r„  r  r…  r_  r|  r%  r  ra  r†  r"  r!  r  r}  rb  r   r¥   r‡  rc  rˆ  rd  rµ   r0  r‰  r$  rŠ  re  rK  rf  r€  rg  r‹  rà   rŽ  ),rÁ  r‘  r¿  r’  r`  r�  r«  rƒ  r   r+  r^  r„  r  r…  r_  r|  r%  r  ra  r†  r"  r!  r  r}  rb  r   r¥   r‡  rc  rˆ  rd  rµ   r0  r‰  r$  rŠ  re  rK  rf  r€  rg  r‹  rà   r�  )T)rÇ  zInstrumentationSettings | boolrà   râ   )rà   r4  )r  r4  rà   râ   )rà   r+  )r  r+  rà   râ   )rà   r  )r  r  rà   râ   )r  r.  rà   râ   )rÜ  rf   rà   r  )rà   rî  )rà   r2  )rà   rO  )rà   rM  ©rà   r	  )(rú  ú,str | Sequence[_messages.UserContent] | Noner^  râ   rñ  ú'Sequence[_messages.ModelMessage] | Nonerò  úDeferredToolResults | Noneró  r  rô  r  r   r+  r  r{  rÜ  rf   r"  r1  rõ  ú_usage.UsageLimits | Nonerö  úCancellationToken | Noner2   ú_usage.RunUsage | Noner$  r9  r  r}  r÷  rµ   rc  ú,Sequence[AbstractToolset[AgentDepsT]] | Nonerg  r�  r®  ú!dict[str, Any] | AgentSpec | Nonerà   z>AbstractAsyncContextManager[AgentRun[AgentDepsT, OutputDataT]])(rú  r”  r^  úOutputSpec[RunOutputDataT]rñ  r•  rò  r–  ró  r  rô  r  r   r+  r  r{  rÜ  rf   r"  r1  rõ  r—  rö  r˜  r2   r™  r$  r9  r  r}  r÷  rµ   rc  rš  rg  r�  r®  r›  rà   zAAbstractAsyncContextManager[AgentRun[AgentDepsT, RunOutputDataT]])(rú  r”  r^  úOutputSpec[Any] | Nonerñ  r•  rò  r–  ró  r  rô  r  r   r+  r  r{  rÜ  rf   r"  r1  rõ  r—  rö  r˜  r2   r™  r$  r9  r  r}  r÷  rµ   rc  rš  rg  r�  r®  r›  rà   z)AsyncGenerator[AgentRun[AgentDepsT, Any]])&rú  r”  r^  r�  rñ  r•  rò  r–  ró  r  rô  r  r   r+  r  r{  rÜ  rf   r"  r1  rõ  r—  rö  r˜  r2   r™  r$  r9  r  r}  rc  rš  rg  r�  r®  r›  rà   z"_PreparedAgentRun[AgentDepsT, Any])r	  rt  r¹  r9  rà   r#  )r¿  r9  r	  rt  rà   r#  )rÂ  z[GraphRunContext[_agent_graph.GraphAgentState, _agent_graph.GraphAgentDeps[AgentDepsT, Any]]r$  r9  rà   r#  )r§   )r®  r›  r«  rƒ  rà   z_ResolvedSpec | None)r%  zstr | _utils.UnsetrÜ  zAgentDepsT | _utils.Unsetr   z9models.Model | models.KnownModelName | str | _utils.Unsetrc  z4Sequence[AbstractToolset[AgentDepsT]] | _utils.Unsetr¥   zKSequence[Tool[AgentDepsT] | ToolFuncEither[AgentDepsT, ...]] | _utils.Unsetrb  z4Sequence[AgentNativeTool[AgentDepsT]] | _utils.Unsetr  z,AgentInstructions[AgentDepsT] | _utils.Unsetr$  z(AgentMetadata[AgentDepsT] | _utils.Unsetr"  z-AgentModelSettings[AgentDepsT] | _utils.Unsetr  z!int | AgentRetries | _utils.Unsetr®  r›  rà   zGenerator[None])rí  ú.Callable[[RunContext[AgentDepsT]], str | None]rà   rž  )rí  ú9Callable[[RunContext[AgentDepsT]], Awaitable[str | None]]rà   rŸ  )rí  úCallable[[], str | None]rà   r   )rí  ú#Callable[[], Awaitable[str | None]]rà   r¡  )r%  r  rà   úFCallable[[SystemPromptFunc[AgentDepsT]], SystemPromptFunc[AgentDepsT]])rí  ú#SystemPromptFunc[AgentDepsT] | Noner%  r  rà   úeCallable[[SystemPromptFunc[AgentDepsT]], SystemPromptFunc[AgentDepsT]] | SystemPromptFunc[AgentDepsT])rÜ  rf   r   r+  rñ  r•  r  r”  r2   r™  r"  r!  rà   z list[_messages.SystemPromptPart])rû  rµ   rà   r¢  )rí  r£  rû  rµ   rà   r¤  )rí  ú<Callable[[RunContext[AgentDepsT], OutputDataT], OutputDataT]rà   r¥  )rí  úGCallable[[RunContext[AgentDepsT], OutputDataT], Awaitable[OutputDataT]]rà   r¦  )rí  ú$Callable[[OutputDataT], OutputDataT]rà   r§  )rí  ú/Callable[[OutputDataT], Awaitable[OutputDataT]]rà   r¨  )rí  ú4_output.OutputValidatorFunc[AgentDepsT, OutputDataT]rà   r©  )rí  ú+OnEventHookFunc[_messages.AgentStreamEvent]rà   rª  )r&  útype[EventT]rq  rK  rà   z<Callable[[OnEventHookFunc[EventT]], OnEventHookFunc[EventT]])r*  zAOnEventHookFunc[_messages.AgentStreamEvent] | type[EventT] | Noner&  r«  rq  rK  rà   r   )rí  rE  rà   rE  ) r%  r  ra  r  r  r&  r0  ú"ToolPrepareFunc[AgentDepsT] | Noner1  ú0ArgsValidatorFunc[AgentDepsT, ToolParams] | Noner2  rj   r3  rµ   r4  útype[GenerateJsonSchema]r5  úbool | Noner6  rµ   r7  rµ   r$  r#  rq  rK  r8  rµ   r9  r¯  rà   z\Callable[[ToolFuncContext[AgentDepsT, ToolParams]], ToolFuncContext[AgentDepsT, ToolParams]])"rí  z.ToolFuncContext[AgentDepsT, ToolParams] | Noner%  r  ra  r  r  r&  r0  r¬  r1  r­  r2  rj   r3  rµ   r4  r®  r5  r¯  r6  rµ   r7  rµ   r$  r#  rq  rK  r8  rµ   r9  r¯  rà   r   )rí  rN  rà   rN  ) r%  r  ra  r  r  r&  r0  r¬  r1  r­  r2  rj   r3  rµ   r4  r®  r5  r¯  r6  rµ   r7  rµ   r$  r#  rq  rK  r8  rµ   r9  r¯  rà   z@Callable[[ToolFuncPlain[ToolParams]], ToolFuncPlain[ToolParams]])"rí  z ToolFuncPlain[ToolParams] | Noner%  r  ra  r  r  r&  r0  r¬  r1  r­  r2  rj   r3  rµ   r4  r®  r5  r¯  r6  rµ   r7  rµ   r$  r#  rq  rK  r8  rµ   r9  r¯  rà   r   )rí  rX  rà   rX  )rR  rµ   rå   r  rà   z<Callable[[ToolsetFunc[AgentDepsT]], ToolsetFunc[AgentDepsT]])rí  zToolsetFunc[AgentDepsT] | NonerR  rµ   rå   r  rà   r   )r   r+  rà   rµ   )r   r+  rà   z*models.Model | models.KnownModelName | str)rà   zCombinedCapability[AgentDepsT])r   r+  rc  rš  rà   re  )r  r&  rà   r¤   )rà   z+tuple[CombinedCapability[AgentDepsT], bool])r#  ú$list[AbstractCapability[AgentDepsT]]rà   r°  )
rw  rH   rú   úAbstractCapability[AgentDepsT]rÜ  rf   r  ú*dict[tuple[int, str], models.Model] | Nonerà   úmodels.Model)
r  zAgentModel[AgentDepsT]rú   r±  r	  rv  r  r²  rà   rw  )r  zAgentModel[AgentDepsT] | Nonerñ  r•  rà   râ   )r   r+  rà   r³  )rà   zInstrumentationSettings | None)rZ  zAgent[T, OutputDataT]rÜ  r  rà   r  )r	  rt  r"  r±  r#  r°  r$  zInstrumentationCap | Noner%  rµ   r&  rµ   rà   z$_ResolvedRunCapabilities[AgentDepsT])NN)rA  r{  rB  ú9list[_instructions.SourcedInstruction[AgentDepsT]] | Nonerà   r@  )r9  z1AbstractToolset[AgentDepsT] | None | _utils.Unsetr:  rš  r;  r  rÌ   z%AbstractCapability[AgentDepsT] | Noner<  r&  rà   rn  )rà   z%Sequence[AbstractToolset[AgentDepsT]])r;  r  r¿  rµ   rà   rG  )r^  râ   rà   r=  )r^  rœ  rà   z$_output.OutputSchema[RunOutputDataT])r^  r�  rà   ú_output.OutputSchema[Any])r   ú,RealtimeModel | KnownRealtimeModelName | strrÜ  rf   r"  úRealtimeModelSettings | Noner  ú+_instructions.AgentInstructions[AgentDepsT]rc  rš  rg  r�  r2   r™  rõ  r—  r$  r9  ró  r  rô  r  rñ  r•  rÐ  rµ   rà   z6AsyncGenerator[_RealtimeSessionResolution[AgentDepsT]])$r   r¶  rÜ  rf   r"  r·  r  r¸  rc  rš  rg  r�  r2   r™  rõ  r—  r$  r9  ró  r  rô  r  rñ  r•  r0  r—   r1  rµ   r2  r¤   r3  r&  r4  zRealtimeProviderSession | Nonerà   zAsyncGenerator[RealtimeSession])rà   r    )rd  r   rà   r¯  )r   r+  rà   râ   )r1   rž   rÜ  rf   r"  r!  r  r  rt  zstr | Path | Noneru  zSequence[str] | Nonerà   r’   )fr©   rª   r«   r¬   r­   r®   r6  r  Úfieldr:  r<  r>  r?  r*   rB  rC  rD  rE  rF  rH  rI  rJ  rL  rN  rP  rR  rS  rU  rœ  Úcached_propertyr[  r   r	  Úobjectrj  Úclassmethodr¯  rî  rÂ  ÚstaticmethodrÈ  ÚpropertyrÇ  Úsetterr   r%  ra  rÝ  r`  r^  rä  rb  rê  rï  rû  r   r  r‘  r¸  rž  ry  r   r-   rÓ  ré  r  r
  r_  r  r#  r-  rk   rH  r�  r‚  rƒ  rÖ  rj  r{  rx  r  r„  rI  r�  r†  r�  r|  r’  r—  r•  r>  rc  rÀ  rµ  r†  r,  rX  r`  re  rq  ry  r¯   r§   r°   r±   rŸ   rŸ   ½  s!  ‡ ñð& >Ó=àÓØ6Ó6ØÓð	ð :Ó9ðð *Ó)à6Ó6ðð EJÐÐAÓIØ2=×2CÒ2CÈÑ2O€IÐ/ÓOà#.×#4Ò#4¸%Ñ#@€JÐ Ó@Ø8C×8IÒ8IÈuÑ8U€NÐ5ÓUØQ\×QbÒQbÐhmÑQnÐÐNÓnØHS×HYÒHYÐ_dÑHe€MÐEÓeØ'2×'8Ò'8¸eÑ'D€O�_ÓDØT_×TeÒTeÐkpÑTqÐÐQÓqØal×arÒarØñbÐ$Ð&^ó ð 6A×5FÒ5FÈEÑ5RÐÐ2ÓRØ8C×8IÒ8IÈuÑ8U€OÐ5ÓUØ8C×8IÒ8IÈuÑ8U€NÐ5ÓUØ*×0Ò0°eÑ<Ð˜Ó<Ø(×.Ò.°EÑ:Ð�sÓ:Ø"-×"3Ò"3¸Ñ"?€M�<Ó?ØIT×IZÒIZÐ`eÑIfÐÐFÓfàCN×CTÒCTÐZ_ÑC`ÐÐ@Ó`àKV×K\ÒK\ÐbgÑKhÐÐHÓhà%×+Ò+°Ñ7€N�CÓ7Ø)4×):Ò):ÀÑ)F€KÐ&ÓFà×Ñóó ðð ð DHðð 03Ø6:Ø-/Ø&,ØØ<@Ø@DØ-1ØLPØNPØ>BØ"'Ø$.Ø59Ø%)Ø<@ØEIñ)à@ðð -ð	ð
 4ðð +ðð $ðð ðð :ðð >ðð +ðð Jðð Lðð <ðð  ðð  "ð!ð" 3ð#ð$ #ð%ð& :ð'ð( Cð)ð* 
õ+ó ðð. ð DHðð 03Ø6:Ø-/Ø&,ØØ<@Ø@DØ-1ØLPØNPØ>BØ"'Ø$.Ø59Ø%)Ø<@ØEIñ)à@ðð -ð	ð
 4ðð +ðð $ðð ðð :ðð >ðð +ðð Jðð Lðð <ðð  ðð  "ð!ð" 3ð#ð$ #ð%ð& :ð'ð( Cð)ð* 
õ+ó ðð2 DHðE'ð 03Ø6:Ø-/Ø&,ØØ<@Ø@DØ-1ØLPØNPØ>BØ"'Ø$.Ø59Ø%)Ø<@ØEIñ)E'à@ðE'ð -ð	E'ð
 4ðE'ð +ðE'ð $ðE'ð ðE'ð :ðE'ð >ðE'ð +ðE'ð JðE'ð LðE'ð <ðE'ð  ðE'ð  "ð!E'ð" 3ð#E'ð$ #ð%E'ð& :ð'E'ð( Cð)E'ð* 
ö+E'ðN Øð
 LNØCGØ'*Ø/3Ø-/ØØ59Ø/3Ø-1Ø"&Ø@BØ7;Ø"'Ø+/Ø.2Ø%)Ø<@Ø>Bñ+!à(ð!ð "Ið	!ð
 Að!ð %ð!ð -ð!ð +ð!ð ð!ð 3ð!ð -ð!ð +ð!ð  ð!ð >ð!ð 5ð!ð   ð!!ð" )ð#!ð$ ,ð%!ð& #ð'!ð( :ð)!ð* <ð+!ð, 
ô-!ó ó ð!ð0 Øð LNØCGØ'*Ø/3Ø-/ØØ59Ø/3Ø-1Ø"&Ø@BØ7;Ø"'Ø+/Ø.2Ø%)Ø<@Ø>Bñ-à(ðð ð	ð
 "Iðð Aðð %ðð -ðð +ðð ðð 3ðð -ðð +ðð  ðð >ðð  5ð!ð"  ð#ð$ )ð%ð& ,ð'ð( #ð)ð* :ð+ð, <ð-ð. 
ô/ó ó ðð2 ñ
  $ D›zØKMØCGØ'*Ø/3Ø-/ØØ59Ø/3Ø-1Ø"&Ø@BØ7;Ø"'Ø+/Ø.2Ø%)Ø<@Ø>Bñ-kà(ðkð ð	kð
 "Iðkð Aðkð %ðkð -ðkð +ðkð ðkð 3ðkð -ðkð +ðkð  ðkð >ðkð  5ð!kð"  ð#kð$ )ð%kð& ,ð'kð( #ð)kð* :ð+kð, <ð-kð. 
ô/kó ðkðZ Øð
 /3ØKMØCGØ'*Ø/3Ø-/ØØ59Ø/3Ø-1Ø"&Ø@BØ7;Ø"'Ø+/Ø.2Ø%)Ø<@Ø>Bñ-!àð!ð ,ð	!ð
 "Ið!ð Að!ð %ð!ð -ð!ð +ð!ð ð!ð 3ð!ð -ð!ð +ð!ð  ð!ð >ð!ð  5ð!!ð"  ð#!ð$ )ð%!ð& ,ð'!ð( #ð)!ð* :ð+!ð, <ð-!ð. 
ô/!ó ó ð!ð2 Øð
 /3àKMØCGØ'*Ø/3Ø-/ØØ59Ø/3Ø-1Ø"&Ø@BØ7;Ø"'Ø+/Ø.2Ø%)Ø<@Ø>Bñ/àðð ,ð	ð
 ðð "Iðð Aðð %ðð -ðð +ðð ðð 3ðð -ðð +ðð  ðð  >ð!ð" 5ð#ð$  ð%ð& )ð'ð( ,ð)ð* #ð+ð, :ð-ð. <ð/ð0 
ô1ó ó ðð4 ð
 /3Ù# D›zØKMØCGØ'*Ø/3Ø-/ØØ59Ø/3Ø-1Ø"&Ø@BØ7;Ø"'Ø+/Ø.2Ø%)Ø<@Ø>Bñ/:àð:ð ,ð	:ð
 ð:ð "Ið:ð Að:ð %ð:ð -ð:ð +ð:ð ð:ð 3ð:ð -ð:ð +ð:ð  ð:ð  >ð!:ð" 5ð#:ð$  ð%:ð& )ð':ð( ,ð):ð* #ð+:ð, :ð-:ð. <ð/:ð0 
ô1:ó ð:ðx õ/ó ð/ð ó ó ð ð ×Ñó!ó ð!ð óó ðð ‡\�\óó ðð ó4ó ð4ð 
‡[�[óó ðð ó&ó ð&ð ×Ñó"ó ð"ö!ð óó ðð ó!ó ð!ð ó*ó ð*ð ó(ó ð(ô(ô@ð ð EIðMð !ØCGØ<@Ø&*Ø!ØCGØ6:ØØ@DØ26Ø7;Ø(,Ø59Ø-1ØØAEØEIØ26ñ+MàAðMð ð	Mð
 AðMð  :ðMð $ðMð ðMð AðMð 4ðMð ðMð >ðMð 0ðMð 5ðMð &ðMð  3ð!Mð" +ð#Mð$ ð%Mð& ?ð'Mð( Cð)Mð* 0ð+Mð, 
Hõ-Mó ðMð0 ð EIðPð
 DHØ<@Ø&*Ø!ØCGØ6:ØØ@DØ26Ø7;Ø(,Ø59Ø-1ØØAEØEIØ26ñ+PàAðPð 0ð	Pð
 AðPð  :ðPð $ðPð ðPð AðPð 4ðPð ðPð >ðPð 0ðPð 5ðPð &ðPð  3ð!Pð" +ð#Pð$ ð%Pð& ?ð'Pð( Cð)Pð* 0ð+Pð, 
Kõ-Pó ðPð0 ð EIðPð /3ØCGØ<@Ø&*Ø!ØCGØ6:ØØ@DØ26Ø7;Ø(,Ø59Ø-1ØØAEØEIØ26ñ+PàAðPð ,ð	Pð
 AðPð  :ðPð $ðPð ðPð AðPð 4ðPð ðPð >ðPð 0ðPð 5ðPð &ðPð  3ð!Pð" +ð#Pð$ ð%Pð& ?ð'Pð( Cð)Pð* 0ð+Pð, 
3õ-Pó ðPðh EIðw
ð /3ØCGØ<@Ø&*Ø!ØCGØ6:ØØ@DØ26Ø7;Ø(,Ø59Ø-1ØAEØEIØ26ñ)w
àAðw
ð ,ð	w
ð
 Aðw
ð  :ðw
ð $ðw
ð ðw
ð Aðw
ð 4ðw
ð ðw
ð >ðw
ð 0ðw
ð 5ðw
ð &ðw
ð  3ð!w
ð" +ð#w
ð$ ?ð%w
ð& Cð'w
ð( 0ð)w
ð* 
,ö+w
ðx AEð-à#ð-ð >ð-ð 
õ	-ð à0ðð $ðð 
ô	ð!àrð!ð 3ð!ð 
ô	!ð LNð+
à/ð+
ð "Ið+
ð 
õ	+
ðZ ð $*§<¡<Ø*0¯,©,ØKQÏ<É<ØIOÏÉØ]c×]iÑ]iØMSÏ\É\ØEKÇ\Á\Ø=C¿\¹\ØHNÏÉØ5;·\±\Ø26ñu@ð !ðu@ð (ð	u@ð
 Iðu@ð Gðu@ð [ðu@ð Kðu@ð Cðu@ð ;ðu@ð Fðu@ð 3ðu@ð 0ðu@ð 
ôu@ó ðu@ðn ð=ØBð=à	7ó=ó ð=ð ðHØMðHà	BóHó ðHð Û^ó Ø^àÛtó Øtàà'+ñUØ$ðUà	OôUó ðUð 59ð5>ð
  ñ5>à1ð5>ð
 ð5>ð 
oö5>ðt  ØCGØCGØ?CØ(,Ø/3ñ9
ð ð9
ð Að	9
ð
 Að9
ð =ð9
ð &ð9
ð -ð9
ð 
*õ9
ðv ð=ØBð=à	7ó=ó ð=ð ðHØMðHà	BóHó ðHð Û_ó Ø_àÛuó Øuàà$)ñUØ!ðUà	OôUó ðUð 59ð5ð
 ñ5à1ð5ð
 ð5ð 
oö5ðn ðKØPðKà	EóKó ðKð ðVØ[ðVà	PóVó ðVð ð3Ø8ð3à	-ó3ó ð3ð ð>ØCð>à	8ó>ó ð>ð#ØHð#à	=ô#ðJ ð:Ø?ð:à	4ó:ó ð:ð àBFñKØ(ðKØ3?ðKà	EôKó ðKð aeðFRð !%ñ	FRà]ðFRð #ðFRð ð	FRð
 
öFRðP Ûtó Øtàð
  Ø"&Ø"Ø6:ØKOØ,2Ø/4Ø5KØ"Ø Ø"'Ø*.Ø $Ø#Ø-1ñ%kð ð	kð
  ðkð ðkð 4ðkð Iðkð *ðkð )-ðkð 3ðkð ðkð ðkð  ðkð (ðkð  ð!kð" ð#kð$  +ð%kð& 
fô'kó ðkð. @DðoHð
  Ø"&Ø"Ø6:ØKOØ,2Ø/4Ø5KØ"Ø Ø"'Ø*.Ø $Ø#Ø-1ñ'oHà<ðoHð
 ðoHð  ðoHð ðoHð 4ðoHð IðoHð *ðoHð )-ðoHð 3ðoHð ðoHð ðoHð  ðoHð  (ð!oHð" ð#oHð$ ð%oHð&  +ð'oHð( 
ö)oHðb Û^ó Ø^àð
  Ø"&Ø"Ø6:ØKOØ,2Ø/4Ø5KØ"Ø Ø"'Ø*.Ø $Ø#Ø-1ñ%Oð ð	Oð
  ðOð ðOð 4ðOð IðOð *ðOð )-ðOð 3ðOð ðOð ðOð  ðOð (ðOð  ð!Oð" ð#Oð$  +ð%Oð& 
Jô'Oó ðOð. 26ðnHð
  Ø"&Ø"Ø6:ØKOØ,2Ø/4Ø5KØ"Ø Ø"'Ø*.Ø $Ø#Ø-1ñ'nHà.ðnHð
 ðnHð  ðnHð ðnHð 4ðnHð IðnHð *ðnHð )-ðnHð 3ðnHð ðnHð ðnHð  ðnHð  (ð!nHð" ð#nHð$ ð%nHð&  +ð'nHð( 
ö)nHð` ÛWó ØWàð
 "ØñKð ð	Kð
 ðKð 
FôKó ðKð 04ð&Nð
 "Øñ&Nà,ð&Nð
 ð&Nð ð&Nð 
ö&NôPeð	kØFð	kà	3ô	kôQð BFð
à@ð
ð ?ð
ð 
õ	
öBJô.ð"
QØ"Fð
Qà	-ô
Qð$ GKñà!ðð 3ð	ð
 ðð Dðð 
õð> GKñHà,ðHð 3ð	Hð
 6ðHð DðHð 
)õHð" ðØ3ðà@ðð 
óó ðö$Tô(Oô
ðM
à#ðM
ð 8ð	M
ð
 AðM
ð 7ðM
ð !%ðM
ð ðM
ð 
.ôM
ðb BFØVZð"à!>ð"ð Tð"ð 
<õ	"ðL MSÏLÉLØLPØBFØ@DØ)-ðDàIðDð JðDð @ð	Dð
 >ðDð 'ðDð 
%öDðL ó%ó ð%ð ô*ó ð*ð ô?ó ð?ð CGð-ð "'ñ	-à?ð-ð ð	-ð
 
+÷-ð^ Üaó Øaàð3Ø5ð3à	-ô3ó ð3õð ð
  Ø7;ØDHØAEØEIØ(,Ø26Ø59Ø&*Ø!ØCGØ#ñi
à;ði
ð ð	i
ð
 5ði
ð Bði
ð ?ði
ð Cði
ð &ði
ð 0ði
ð 3ði
ð $ði
ð ði
ð Aði
ð ði
ð  
@õ!i
ó ði
ðV ð
  Ø7;ØDHØAEØEIØ(,Ø26Ø59Ø&*Ø!ØCGØ*;Ø %Ø%&Ø(+Ø;?ñ'x6à;ðx6ð ð	x6ð
 5ðx6ð Bðx6ð ?ðx6ð Cðx6ð &ðx6ð 0ðx6ð 3ðx6ð $ðx6ð ðx6ð Aðx6ð (ðx6ð  ð!x6ð"  #ð#x6ð$ &ð%x6ð& 9ð'x6ð( 
)õ)x6ó ðx6õt'õR	>÷7ð6 #ØØ/3Ø#'Ø)-Ø.2ñN
ð ðN
ð ð	N
ð
 -ðN
ð !ðN
ð 'ðN
ð ,ðN
ð 
÷N
ñ N
r°   rŸ   c                  óf   • \ rS rSr% SrS\S'   \R                  " SSSS9rS\S	'   SS
 jr	SS jr
Srg)r™  iH  zAEnter every model selected by a run on its shared resource stack.zset[int]Úentered_model_idsNF)r  r)  r8  rT  Ú_stackc                ó.   • U R                   b   eXl         g r¼   ©rÂ  )rZ  Ústacks     r±   Ú
bind_stackÚ_RunModelResources.bind_stackO  s   € Ø�{‰{Ñ"Ð"Ð"Ø�r°   c              ƒ  óà   #   • [        U5      nX R                  ;   a  g U R                  c   eU R                  R                  U5      I S h  v•N   U R                  R	                  U5        g  N 7fr¼   )rå   rÁ  rÂ  r  r[  )rZ  r  Úmodel_identitys      r±   r]  Ú_RunModelResources.enter_modelS  s_   é € Ü˜NÓ+ˆØ×3Ñ3Ó3ØØ�{‰{Ñ&Ð&Ð&Ø�k‰k×-Ñ-¨nÓ=×=Ð=Ø×Ñ×"Ñ" >Õ2ñ 	>ùs   ‚A	A.ÁA,Á!A.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™  H  s0   ‡ áKàÓØ$/×$5Ò$5¸dÈÐUZÑ$[€FÐ!Ó[ô÷3r°   r™  c                  óÄ   • \ rS rSr% SrS\S'   S\S'   S\S'   S	\S
'   S\S'   S\S'   S\S'   S\S'   S\S'   S\S'   S\S'   S\S'   S\S'   S\S'   S\S '   \S$S! j5       rS"rg#)%r›  i\  zGThe fully assembled inputs and resources for one graph-based agent run.zÈGraph[_agent_graph.GraphAgentState, _agent_graph.GraphAgentDeps[_PreparedDepsT, _PreparedOutputT], _agent_graph.UserPromptNode[_PreparedDepsT, _PreparedOutputT], _result.FinalResult[_PreparedOutputT]]rj  z_agent_graph.GraphAgentStaterk  z=_agent_graph.GraphAgentDeps[_PreparedDepsT, _PreparedOutputT]rl  z=_agent_graph.UserPromptNode[_PreparedDepsT, _PreparedOutputT]rm  r	  rn  zRunBinding | Nonero  r˜  rö  r³  r   rµ   rp  r™  rq  z"AbstractCapability[_PreparedDepsT]rÌ   zAbstractToolset[_PreparedDepsT]r�  z_usage.UsageLimitsrõ  rQ  rr  z�Callable[[GraphRunContext[_agent_graph.GraphAgentState, _agent_graph.GraphAgentDeps[_PreparedDepsT, _PreparedOutputT]]], dict[str, Any] | None]rs  c               ó  ^ ^	^
^#   • T R                   m
T R                  mTR                  n[        U[        R
                  5      (       d   e[        S
U
U4S jj5       n[        5        IS h  v•N nUR                  U" 5       5      I S h  v•N   T
R                  R                  5         UR                  T
R                  R                  5        UR                  UR                  5        T R                  b%  T
R                  R                  T R                  5        T R                   R#                  U5        UR                  [$        R&                  " T R(                  ST R*                   35      5      I S h  v•N   T R,                  (       a-  T R                   R/                  T R0                  5      I S h  v•N   UR                  T R2                  R5                  T R6                  TT
S SS95      I S h  v•N n[9        U5      m	T R:                  b  T	T R:                  l        T R?                  T	R@                  5        [B        RD                  " T	R@                  5      nSU	U
U 4S jjnSU	4S jjnSU	4S jjn[G        T RH                  UUUUU	4S jUS	9 IS h  v•N   UR                  T RJ                  5      I S h  v•N    T	7v •  T	RL                  b  T R?                  T	R@                  5        S S S 5      IS h  v•N   S S S 5      IS h  v•N   g  GN¡ GN† GN� GNb GN' N… Nd! T	RL                  b  T R?                  T	R@                  5        f f = f NV! , IS h  v•N  (       d  f       Nk= f Nb! , IS h  v•N  (       d  f       g = f7f)Nc                óœ  >#   • SUU4S jjn  S 7v •   TR                  R                  5         g ! [         R                   a  nU " S5      UeS nAf[        R                   aG  nTR                  R                  5       nU(       a	  U " S5      UeU " S5      R                  U5        e S nAff = f! TR                  R                  5         f = f7f)Nc                ó4   >• [         R                  " U TT5      $ r¼   )r'   Úrun_cancelled_snapshot)rë  rl  rk  s    €€r±   rì  ÚO_PreparedAgentRun.open.<locals>._translate_cancellation.<locals>._run_cancelled�  s   ø€ Ü#×:Ò:¸7ÀEÈ:ÓVÐVr°   rî  rï  z@The agent run was cancelled by an external asyncio cancellation.rð  )r/   ré  rÂ   rö   re  rñ  rò  ró  )rì  rÿ   Úfirst_partyrl  rk  s      €€r±   rõ  Ú7_PreparedAgentRun.open.<locals>._translate_cancellation  sº   øé € ÷Wð Wð9Ýð6 ×'Ñ'×6Ñ6Õ8øô5 ×*Ñ*ó 	^ñ %Ð%SÓTÐZ]Ð]ûÜ×)Ñ)ó 	Ø(×5Ñ5×=Ñ=Ó?�ÞÙ(Ð)GÓHÈcÐQñ
 ÐaÓb×mÑmÐnqÔrØûð	ûð  ×'Ñ'×6Ñ6Õ8üs>   ƒ
CŽ/ ”C¯B*Á	AÁB*Á#AB%Â%B*Â*B- Â-C	Ã	Czagent:F)Úinputsrk  rÜ  Úspanr÷  c              “  óÈ   >#   • TR                   R                  U R                  5        TR                  R                  (       a  [
        R                  " S5      eU Tl        g 7frá  )rõ  Ú
check_costr2   re  râ  rÂ   rö   Ú_result_override)r–   r  rl  rZ  s    €€€r±   rÜ   Ú0_PreparedAgentRun.open.<locals>._finalize_resultÍ  sI   øé € Ø×!Ñ!×,Ñ,¨V¯\©\Ô:ð ×*Ñ*×;×;Ü!×0Ò0Ð1iÓjÐjØ-3�	Õ*ùs   ƒAA"c                ó.   >• TR                   =(       d    U $ r¼   )Ú_node_error)rÞ   r  s    €r±   Ú_extract_errorÚ._PreparedAgentRun.open.<locals>._extract_errorÕ  s   ø€ ð !×,Ñ,×5°Ð5r°   c                 ó*   >• TR                   n U c   eU $ r¼   r•   )r–   r  s    €r±   Ú_build_resultÚ-_PreparedAgentRun.open.<locals>._build_resultÚ  s   ø€ Ø"×)Ñ)�ØÑ)Ð)Ð)Ø�r°   c                 ó    >• T R                   S L$ r¼   r•   )r  s   €r±   r  Ú(_PreparedAgentRun.open.<locals>.<lambda>å  s   ø€  Y×%5Ñ%5¸TÑ%Ar°   )rÊ   rÛ   r·   r¸   r¹   r  rã   )rÞ   rî   rà   rî   rß   )'rl  rk  r  ró   r)   ÚPendingMessageQueuer   r   r  re  r  rð   r  Úcloserö  Úattach_tokenrq  rÆ  r•  Úget_concurrency_contextrr  rn  rp  r]  r   rj  rû  rm  r_   ro  r  rs  r	  r'   r7   r  rÌ   r�  r–   )rZ  Úpending_message_queuerõ  rÅ  Ú	graph_runrÍ   rÜ   rÛ  rÞ  r  rl  rk  s   `        @@@r±   r  Ú_PreparedAgentRun.openx  sâ  ûé € à—_‘_ˆ
Ø—
‘
ˆØ %× 6Ñ 6ÐÜÐ/´×1MÑ1M×NÑNÐNÐNä	÷ 	9ó 
ð 	9ôD "×#Ô# uà×+Ñ+Ñ,CÓ,EÓF×FÐFð ×#Ñ#×(Ñ(Ô*Ø�N‰N˜:×2Ñ2×9Ñ9Ô:ð �N‰NÐ0×6Ñ6Ô7Ø×&Ñ&Ñ2Ø×'Ñ'×4Ñ4°T×5LÑ5LÔMà× Ñ ×+Ñ+¨EÔ2Ø×+Ñ+Ü×4Ò4°T×5MÑ5MÐQWÐX\×XgÑXgÐWhÐOiÓjó÷ ð ð ×1×1Ø×*Ñ*×6Ñ6°t·z±zÓB×BÐBØ#×7Ñ7Ø—
‘
—‘Ø×0Ñ0ØØ#ØØ$ð  ð ó÷ ˆIô ! Ó+ˆIØ�|‰|Ñ'ð *3�—‘Ô&Ø×!Ñ! )§-¡-Ô0ô #×4Ò4°Y·]±]ÓCˆG÷4ñ 4÷6÷
ô
 ,Ø×#Ñ#ØØ*Ø)Ø,ÜAà#(÷	ó 	ð ×/Ñ/°·±Ó=×=Ð=ð=Ø#“Oà ×'Ñ'Ñ3Ø×-Ñ-¨i¯m©mÔ<÷#	÷ 	÷{ $×#Ó#âFò ò CòñL	ñ >øð !×'Ñ'Ñ3Ø×-Ñ-¨i¯m©mÕ<ð 4ú÷!	÷ 	÷ 	ð 	ú÷{ $×#×#Ð#üs  †A&NÁ,LÁ-NÁ0M,Â
LÂC+M,Å6LÅ7=M,Æ4LÆ5=M,Ç2LÇ3B#M,ÊLÊM,ÊMÊ9LÊ:MÊ?L Ë(MË,M,Ë7MË8M,Ë<NÌM*ÌNÌM,ÌM,ÌM,ÌM,ÌM,ÌMÌ +MÍMÍM,ÍM'	ÍMÍM'	Í#M,Í*NÍ,NÍ2M5Í3NÍ?Nr§   N)rà   z:AsyncGenerator[AgentRun[_PreparedDepsT, _PreparedOutputT]])	r©   rª   r«   r¬   r­   r®   r   r  r¯   r§   r°   r±   r›  r›  \  s~   ‡ áQðó ð (Ó'ØMÓMØSÓSØƒOØÓØ0Ó0ØÓØ#'Ó'Ø'Ó'Ø6Ó6Ø,Ó,Ø$Ó$ØGÓGðó ð
 ów=ó ów=r°   r›  c                ó`   • [        U5      nUR                  [        U 5      5        U(       d  gU$ )zuMerge an explicit `retries=` value with the retry fields on an `AgentSpec`.

Explicit kwarg keys win over spec keys.
N)rÈ  rè   r  )Úexplicitr®  Úmergeds      r±   r·  r·  ó  s+   € ô (¨Ó-€FØ
‡M�MÔ2°8Ó<Ô=ÞØØ€Mr°   c                óP   • SU R                   ;   a  [        U R                  5      $ 0 $ )z<Return retry fields explicitly configured on an `AgentSpec`.r  )Úmodel_fields_setr  r  ©r®  s    r±   rÈ  rÈ    s%   € à=FÈ$×J_ÑJ_Ó=_Ô+¨D¯L©LÓ9ÐgÐegÐgr°   )ra  r0  re  rr  Údeps_schemarA  rÉ  z)tuple[type[AbstractCapability[Any]], ...]Ú_AUTO_INJECT_CAPABILITY_TYPESc                ó8   • [        S [        U 5       5       5      $ )zÙCount the capabilities the user registered, for a `pydantic_ai._display` banner.

Infrastructure capabilities are injected for every agent, so counting those would say nothing
about the agent the user actually wrote.
c              3  óL   #   • U  H  n[        U[        5      (       + v •  M     g 7fr¼   )ró   rð  )r(  r  s     r±   r-  Ú/_registered_capability_count.<locals>.<genexpr>  s    é € ÐmÒOlÀt”:˜dÔ$AÓB×BÑBÒOlùrc  )rf  rR   )rú   s    r±   rQ  rQ    s   € ô ÑmÔO`ÐakÔOlÓmÓmÐmr°   c                  óD   • \ rS rSr% SrS\S'   S\S'    S\S'   S	\S
'   Srg)re  i   zNWhat a chat session can say about itself before any run has resolved anything.r	  r   r&  r¥   r¤   rg  rµ   rd  r§   Nr¨   r§   r°   r±   re  re     s   ‡ ÙXàƒJØÓØbØÓØÖr°   re  c                ón   • [          H+  n[        X5      (       a  M  U R                  U" 5       5        M-     g)zÔEnsure all auto-injected infrastructure capabilities are present.

Each capability's own `CapabilityOrdering` (e.g. `position='outermost'`)
determines its final placement, so insertion order here doesn't matter.
N)rð  rL   rï   )rg  Úcap_types     r±   r„  r„  *  s)   € ÷ 2ˆÜ" <×:Ó:Ø×Ñ¡£
Ö+ò 2r°   c                ó>  • 0 nU  GH
  nUR                   SL a#  UR                  c  [        R                  " S5      eUR                  c  ME  [        R
                  " UR                  SS9  UR                  UR                  5      nUbc  [        UR                  U[        U5      15        [        [        U5      5      (       d)  [        R                  " [        UR                  5      5      eUR                  UR                  [        U5      5        GM     [        U5      $ )aI  Validate capability `id`s and return the set of explicit ones.

Rejects deferred capabilities that lack an explicit `id`, and ids shared by capabilities that
have not said how they compose. Capabilities whose class declares a default `id` (what
`_declares_default_id` reads off the class body -- `Thinking` declares one and overrides
nothing) are allowed to repeat: their duplication is resolved over the whole composed tree at
run setup by `_combine_duplicate_capabilities`, the only place `combine` is called. Rejecting
the rest here means the common mistake still surfaces in `Agent(...)` rather than on the first
run.

Shared by construction-time validation over the statically-provided capabilities and run-time
assembly, which also covers capabilities supplied per-run or returned by `for_run` and so can't
be checked at construction.
TzjDeferred capabilities must use stable explicit `id` values. Pass `id=...` when using `defer_loading=True`.zCapability id)Úkind)r8  rå   r/   rŽ  r*   Úvalidate_instruction_id_segmentr  rP   rî  rO   rQ   Ú
setdefaultrÀ   )rg  Úownersr�  Úowners       r±   r‡  r‡  5  sã   € ð 8:€FÜˆØ×Ñ Ò$¨¯©©Ü×&Ò&ðAóð ð �6‰6‰>ÙÜ×5Ò5°c·f±fÀ?ÒSð —
‘
˜3Ÿ6™6Ó"ˆØÑÜ% c§f¡f¨u´d¸3³iÐ.@ÔAÜ'¬¨S«	×2Ñ2Ü ×*Ò*Ô+?ÀÇÁÓ+GÓHÐHØ×Ñ˜#Ÿ&™&¤$ s£)×,ñ# ô$ ˆv‹;Ðr°   c                óR  • 0 nU  HŸ  n[        U[        5      (       a  UR                  OU4nU Hr  nUR                  c  M  UR	                  UR                  U5      =oTLd  M4  [        [        U5      5      (       a  MO  [        R                  " SUR                  < S35      e   M¡     g)aé  Reject two instruction sources that would contribute parts under one `capability:<id>` key.

`_validate_capability_ids` walks the flattened capabilities, but a `CombinedCapability` subclass
that overrides `get_instructions` contributes as a source in its own right and is deliberately
retained rather than splatted, so it never appears in that list. Its `id` therefore went
unchecked, and a sibling could share it -- leaving an application unable to tell whose text
`capability:<id>` addresses, which is the one thing the key exists to make unambiguous.

Runs at construction, after `for_agent`, and again on the tree a run actually resolves to.
The last of those is not redundant: a capability passed to `run()` joins the retained container
the same way a registered sibling does, and `for_run` may hand back a capability carrying a
different `id` than the one construction saw.

Sources whose class declares a default `id` are exempt at construction for the same reason they
are in `_validate_capability_ids`: the run resolves them to one source before any instructions
are collected, so the `capability:<id>` key is unambiguous by the time it is used. The run-setup
call sees the already-combined tree, where a surviving duplicate is a genuine conflict.
NzCapability id zk is used by multiple capabilities that contribute instructions. Capability ids must be unique within a run.)	ró   rG   Ú_instruction_sourcesrå   rú  rO   rî  r/   rŽ  )rg  Úsources_by_idrú   Úsourcesrƒ  rü   s         r±   rˆ  rˆ  Z  s¯   € ð& 9;€MÛ"ˆ
ô ˜*Ô&8×9Ñ9ð ×+Ò+à�ð 	ó
 ˆFØ�y‰yÑ ÙØ)×4Ñ4°V·Y±YÀÓGÐG�ÔVÔ_sÜ�V“÷`ó `ô !×*Ò*Ø$ X§[¡[¡Oð 4Pð Póð ó ò #r°   c               óæ   • 0 nU  Hi  n[        U[        5      (       d  M  UR                  UR                  U5      nXCLd  M<  XC:w  d  MC  [        R
                  " SUR                  < SU S35      e   g)a×  Reject native tools that share a `unique_id` but carry conflicting definitions.

Native tools are keyed by `unique_id` when request parameters are deduplicated (see
`Model.prepare_request`). That dedup is intentionally last-wins *across* layers, so a run-level
native tool can override an agent-level default with the same id. *Within* a single layer,
though, two different tools sharing an id are ambiguous: the silent last-wins would bind a
stable id (e.g. an `MCPServerTool` id) to an unexpected definition such as a different server
URL or authorization token. Fail fast here instead. Identical duplicates are allowed and
collapsed later.

`NativeToolFunc` callables are skipped: they have no stable `unique_id` to key on.
zNative tool id z$ maps to conflicting definitions in z;. Native tool ids must be unique within a capability layer.N)ró   rZ   rú  Ú	unique_idr/   rŽ  )rb  rƒ  Úseenr-  rü   s        r±   r£  r£  €  sx   € ð +-€DÛˆÜ˜$Ô 2×3Ñ3ÙØ—?‘? 4§>¡>°4Ó8ˆØÔ HÕ$4Ü×&Ò&Ø! $§.¡.Ñ!3Ð3WÐX^ÐW_ð `Lð Lóð ò r°   c                  ó`   • \ rS rSr% SrS\S'   S\S'   S\S'   S	\S
'   S\S'   S\S'   S\S'   Srg)r˜  i™  aª  The per-run capability state shared by `run`/`iter` and `realtime_session`.

Produced by [`Agent._resolve_run_capabilities`][]: the resolved capability tree plus the
contributions extracted from it (instructions, native tools, model settings, toolsets), so both a
graph run and a realtime session wire capabilities up identically. See the cross-references on the
two call sites for the surrounding logic each keeps to itself.
r±  rÌ   ú)dict[str, AbstractCapability[AgentDepsT]]rg  r´  r  z!list[AgentNativeTool[AgentDepsT]]rb  r1  r"  z%list[AgentToolset[AgentDepsT]] | Nonerc  r°  r,  r§   Nr¨   r§   r°   r±   r˜  r˜  ™  s9   ‡ ñð 3Ó2Ø;Ó;ØKÓKØ3Ó3Ø9Ó9Ø3Ó3Ø9Ó9ò_r°   r˜  r0  c               ó~   • UnX0l         U H.  n[        U5      (       a  U" U 5      OUn[        X55      nX0l         M0     U$ )u'  Merge model-settings layers left-to-right, stamping `run_context.model_settings` before each.

Each layer is a static `ModelSettings`, a callable resolved against the run context, or `None`.
Stamping the merged-so-far onto `run_context.model_settings` before a callable layer runs lets it
observe the previous layers â€” the agent -> capability -> run order both `iter` (per model-request
step) and `realtime_session` (once, at connect) rely on. `base` is the model's own settings for a
graph run; a realtime model has none, so it defaults to `None`.
)r"  rz  rb   )r3  Úlayersr1  rë  r*  rŸ  s         r±   r2  r2  ¯  sD   € ð €FØ!'ÔÛˆÜ)1°%¯©‘5˜Ô%¸eˆÜ% fÓ7ˆØ%+Ö"ñ ð €Mr°   c                óÚ   • / nU R                  UR                  5        [        U5      n0 nU H:  nUR                  nUc$  [	        [        U5      UR                  5       U-  S9nXCU'   M<     U$ )N)Útaken)r   rï   r‡  rå   Ú_synthetic_capability_idrî  r˜  )rú   rg  Úexplicit_idsÚby_idr�  rÕ  s         r±   r•  r•  Æ  sp   € Ø9;€LØ×Ñ�\×(Ñ(Ô)ô ,¨LÓ9€Là79€EÛˆØŸ™ˆØÑ Ü4´T¸#³YÀeÇjÁjÃlÐUaÑFaÑbˆMØ"ˆmÓñ	 ð €Lr°   c               ó|   • [        U R                  5      n SU S[        5       R                  SS  S3nX1;  a  U$ M'  )aÙ  A key for a capability the user never named, shaped so nobody mistakes it for a name.

Every capability in a run needs a key, including the ones with no `id`, or `ctx.capabilities`
could not list them. Nothing carries such a key out of the run: the paths that persist one --
the load records progressive disclosure reads back out of message history -- all require
`defer_loading=True`, which in turn requires an explicit `id`. So this is a run-local handle,
and the only thing wrong with the `thinking` / `thinking_2` it used to be was that it looked
exactly like an `id` somebody chose.

It looked stable, too, and wasn't: the ordinal counted from attachment order, so listing two
anonymous capabilities of one class the other way round swapped which of them owned
`thinking_2`. Nothing depended on that, because nothing may -- but a reader who copied the key
out of `ctx.capabilities` had no way to tell.

Angle brackets say "the framework named this", the way `'<agent>'` and `'<output>'` already do
for toolsets. The class name keeps the registry and a traceback readable. The random suffix is
the part that matters: it differs every run, so relying on it fails immediately and visibly
rather than the next time someone reorders a list.
Ú<Ú:Né   Ú>)r   r©   r   Úhex)r­  r	  Úbase_idÚ	candidates       r±   r
  r
  Ú  sG   € ô( �s—|‘|Ó$€GØ
Ø˜�y ¤%£'§+¡+¨b¨q /Ð!2°!Ð4ˆ	ØÓ!ØÐñ r°   c                ó¦   • SU[        S5      La  UOS0n[        U [        5      (       a  [        R                  " XS9nOU nUR
                  US'   X24$ )zµValidate a spec dict/object and build the template context.

Shared by `Agent.from_spec()` and `Agent._resolve_spec()`.

Returns:
    A tuple of (validated_spec, template_context).
r`  N)Úcontextrï  )rî  ró   Údictr�   Úmodel_validaterï  )r®  r`  r¹  r¸  s       r±   r´  r´  õ  s\   € ð 	 )´4¸³:Ò"=‘YÀ4ð(Ðô �$œ×ÑÜ"×1Ò1°$ÑQ‰àˆØ&4×&@Ñ&@Ð�]Ñ#ØÐ+Ð+r°   c           	     ó|  ^• SSK Jn  [        U5      n        SU4S jjnUR                  XES9nUR                  R                  U5      n / nU R                   H!  n	[        UU	SSUS9n
UR                  U
5        M#     UUR                  R                  U5        $ ! UR                  R                  U5        f = f)	z†Instantiate capabilities from an AgentSpec using the capability registry.

Shared by `Agent.from_spec()` and `Agent._resolve_spec()`.
r   rî  c                óF   >• [        XUT5      u  pU R                  " U0 UD6$ r¼   )rB   r¯  )Úcap_clsrd  Úkwargsr¹  s      €r±   Ú_instantiate_capÚ1_capabilities_from_spec.<locals>._instantiate_cap  s,   ø€ ô
 /¨w¸fÐFVÓW‰ˆØ× Ò  $Ð1¨&Ñ1Ð1r°   )ÚregistryÚinstantiaterú   r«  )ÚlabelÚcustom_types_paramr   )r  útype[AbstractCapability[Any]]rd  ztuple[Any, ...]r  ru  rà   úAbstractCapability[Any])
Úpydantic_ai.agentr®  r�   ÚCapabilitySpecContextÚcapability_spec_contextrÀ   rg  r$   rï   rÓ   )r®  r«  r¹  Ú_agent_specr  r  r	  rÔ   rg  Úcap_specrú   s     `        r±   r¶  r¶    sØ   ø€ õ 6ä&Ð'>Ó?€Hð2Ø.ð2àð2ð ð2ð 
!÷	2ð ×
+Ñ
+°XÐ
+Ð
\€CØ×/Ñ/×3Ñ3°CÓ8€Eð9Ø68ˆØ×)Ô)ˆHÜ+ØØØ"Ø#<Ø,ñˆJð ×Ñ 
Ö+ñ *ð à×+Ñ+×1Ñ1°%Õ8øˆ×+Ñ+×1Ñ1°%Õ8ús   Á4B ÂB;c                  ó„   ^ • \ rS rSr% S\S'   / 4SSSS.         S
U 4S jjjjr\SS j5       r\SS j5       rS	r	U =r
$ )r�  i3  rµ  rr  N©rp  rq  rå   c               ó.   >• XPl         [        TU ]	  XX4S9  g )Nr+  )rr  Úsuperrj  )rZ  r¥   rp  rq  rå   rr  Ú	__class__s         €r±   rj  Ú_AgentFunctionToolset.__init__7  s   ø€ ð +ÔÜ‰Ñ˜ÀÐÒPr°   c                ó   • [         $ r¼   r~   rY  s    r±   rå   Ú_AgentFunctionToolset.idC  s   € äÐr°   c                ó   • g)Nz	the agentr§   rY  s    r±   r!  Ú_AgentFunctionToolset.labelG  s   € àr°   )rr  )
r¥   r~  rp  r&  rq  rK  rå   r  rr  rµ  r“  )r©   rª   r«   r¬   r®   rj  r¾  rå   r!  r¯   Ú__classcell__)r.  s   @r±   r�  r�  3  sŠ   ø‡ à,Ó,ð OQð
Qð #'Ø $Øñ
QàKð
Qð  ð	
Qð
 ð
Qð ð
Qð 1÷
Qñ 
Qð ó ó ð ð óó ör°   r�  )rÌ   r$  rÍ   zRunContext[Any]rÊ   z!Callable[[], AgentRunResult[Any]]rÛ   z0Callable[[AgentRunResult[Any]], Awaitable[None]]r·   z/Callable[[BaseException], BaseException] | Noner¸   zCallable[[], bool] | Noner¹   rT  rà   zAsyncGenerator[_RunLifecycle])r  r»  rà   zTypeIs[models.Model[Any]])r  z#_instructions.AgentInstruction[Any]rà   z"_messages.InstructionSource | None)r  rˆ   r  r¤   rà   r¢   )r  r}  rà   rˆ   )rê  r}  r®  r�   rà   zAgentRetries | None)r®  r�   rà   rˆ   )rú   r$  rà   r¤   )rg  úlist[AbstractCapability[Any]]rà   râ   )rg  ú!Sequence[AbstractCapability[Any]]rà   zset[str])rg  r6  rà   râ   )rb  zSequence[AgentNativeTool[Any]]rƒ  r	  rà   râ   )r3  rt  r  z/Sequence[AgentModelSettings[AgentDepsT] | None]r1  r!  rà   r!  )rú   r±  rà   r  )r­  r#  r	  zCollection[str]rà   r	  )r®  r‚  r`  r�  rà   z tuple[AgentSpec, dict[str, Any]])r®  r�   r«  rƒ  r¹  ru  rà   r5  )þÚ
__future__r   Ú_annotationsrÂ   r¾   r  rœ  r  rÌ  Úcollections.abcr   r   r   r   r   r	   r
   r   Ú
contextlibr   r   r   r   r   r   r   Úpathlibr   Útypingr   r   r   r   r   r   r   r   Úuuidr   rW  Úopentelemetry.tracer   Úpydantic.alias_generatorsr   Úpydantic.json_schemar   Útyping_extensionsr    r!   r"   Úpydantic_ai._instrumentationr#   Úpydantic_ai._specr$   Ú4pydantic_ai.capabilities._deferred_capability_loaderr%   Ú r'   r(   r)   r*   r+   r,   r-   r.   r•  r/   r0   r
  r1   r2   r}  r3   r4   r5   r6   r7   r8   Ú_cancelr9   r:   r;   r<   Ú_deferred_capabilitiesr=   r>   r?   Ú_run_contextr@   rA   Ú	_templaterB   Ú	_warningsrC   rg  rD   rE   rF   rG   rH   rI   rJ   ÚToolSearchCapÚcapabilities._dynamicrK   Úcapabilities._orderingrL   Úcapabilities._pending_messagesrM   Úcapabilities.abstractrN   rO   rP   rQ   rR   Úcapabilities.combinedrS   Úcapabilities.hooksrT   rU   rV   Úcapabilities.instrumentationrW   rŽ  Úmodels.instrumentedrX   rY   rb  rZ   Únative_tools._tool_searchr[   r¦   r\   r]   r^   Úrunr_   r`   r  ra   rb   Útemplaterc   rc  rd   re   r¥   rf   rg   rh   ri   rj   rk   rl   rm   rn   ro   rp   rq   rr   rs   rt   ru   rv   rw   rc  rx   ry   Útoolsets._dynamicrz   r{   Ú toolsets._instruction_collectionr|   Útoolsets._tool_searchr}   Útoolsets.abstractr   Útoolsets.combinedr€   Útoolsets.functionr�   Útoolsets.preparedr‚   Úabstractr„   r…   r†   r‡   rˆ   r‰   rŠ   r‹   rŒ   r�   rŽ   r®  r�   r�   Úwrapperr‘   Ústarlette.applicationsr’   Úpydantic_graphr“   r”   r–   rä  r  r—   r˜   r™   rš   r›   rœ   r�   rx  rž   Ú__all__Ú	dataclassr¢   r³   r  r  r  r  r  r  r  r  r  rî  ÚNoneTyper  rŸ   r™  r›  r·  rÈ  rÉ  r®   rð  rQ  re  r„  r‡  rˆ  r£  r˜  r2  r•  r
  r´  r¶  r�  r§   r°   r±   Ú<module>re     st  ðÞ 2ã Û Û Û Û Û ÷	÷ 	ó 	÷ó õ #Ý Ý Ý ß ]× ]Ó ]Ý ã Ý *Ý .Ý 3ß 3Ñ 3å HÝ 0Ý Y÷÷ ÷ ó ÷÷ ÷ WÓ VÝ EÝ -Ý #ß IÝ /Ý 4÷÷ ñ õ :Ý 8Ý J÷õ õ ;ß ?Ñ ?Ý Pß LÝ -Ý 6ß <Ñ <ß *ß :Ý "ß =÷÷ ÷ ÷ ÷ ÷( 5÷õ LÝ :Ý 0Ý /Ý /Ý /÷÷ ÷ ñ ÷ 5Ý !æÝ0ç5å$÷÷ ñ õ &ð€ð6 ×Ó˜dÑ#÷ð ó $ðð ×Ó˜dÑ#÷ð ó $ðð ð FJØ.2Ø04ñr$Ø+ðr$àðr$ð 4ð	r$ð
 ?ðr$ð Cðr$ð ,ðr$ð .ðr$ð #ôr$ó ðr$ôj+ô
uð GH÷ mô
ñ ˆCƒL€ÙˆCƒL€ÙÐ)Ó*€ÙÐ-Ó.Ð Ù�‹:€ð ×Ò÷
ð 
ó ð
ð ×Ó˜EÑ"ôG:
ˆM˜* kÐ1Ñ2ó G:
ó #ðG:
ðTt ×Ò÷3ð 3ó ð3ð& ×ÒôS=˜ Ð0@Ð @ÑAó S=ó ðS=ðlØ'ðà
ðð ôôhð
-Ð ˜/ó ð Dð Ø!ðLÐ ÐHó ð Jônô˜Jô ô,ô"ôJ#ôLð2 ×Òô_˜w zÑ2ó _ó ð_ð2 "&ñ	Ø'ðà;ðð ð	ð
 õô.ô(ð6,Ø
$ð,àð,ð &ô,ð,%9Ø
ð%9àDð%9ð %ð%9ð #ô	%9ðP ×Ó˜EÑ"ô˜O¨JÑ7ó ó #ñr°   