ó
    ±"³j© ã                  ó0  • % S SK Jr  S SKrS SKJr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JrJr  S SKJr  S	S
KJrJr  S	SKJr  S	SKJrJrJr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.  S	SKJ/r/J0r0J1r1  S	SK2J3r3J4r4J5r5J6r6J7r7  S	SK8J9r9J:r:  S	SK;J<r<  \(       a  S	SK=J>r>  \S   r? \
" SSS9r@S\AS'   \\3\4/\S   4   rB \\C/\S   4   rD \ " S S\\"   5      5       rE " S S\'5      rF " S S\G5      rHS#S  jrI\ " S! S"\\"   5      5       rJg)$é    )ÚannotationsN)Ú	AwaitableÚCallableÚ	Generator)Úcontextmanager)Ú
ContextVar)Ú	dataclassÚfieldÚreplace)ÚTYPE_CHECKINGÚAnyÚGenericÚLiteral)ÚValidationErroré   )Ú_usage_attributionÚmessages)Úfilter_deferred_results)ÚOutputSchemaÚOutputToolsetÚrun_output_process_hooksÚrun_output_validate_hooks)Ú
AgentDepsTÚ
RunContext)
ÚApprovalRequiredÚCallDeferredÚ
ModelRetryÚSkipToolExecutionÚSkipToolValidationÚ
ToolFailedÚToolFailedErrorÚToolRetryErrorÚUnexpectedModelBehaviorÚ	UserError)ÚRetryPromptPartÚToolCallPartÚ
ToolReturn)ÚDeferredToolRequestsÚDeferredToolResultsÚToolApprovedÚToolDefinitionÚ
ToolDenied)ÚAbstractToolsetÚToolsetTool)ÚRunUsage)ÚAbstractCapability)ÚparallelÚ
sequentialÚparallel_ordered_eventsÚparallel_execution_moder1   )Údefaultz!ContextVar[ParallelExecutionMode]Ú _parallel_execution_mode_ctx_varc                  óx   • \ rS rSr% SrS\S'    S\S'    S\S'    S	\S
'    SrS\S'    SrS\S'    SrS\S'   Sr	g)ÚValidatedToolCallé8   a0  Result of validating a tool call's arguments (may represent success or failure).

This separates validation from execution, allowing callers to:
1. Know if validation passed before executing
2. Emit accurate `args_valid` status in events
3. Handle validation failures differently from execution failures
r&   ÚcallúToolsetTool[AgentDepsT] | NoneÚtoolúRunContext[AgentDepsT]ÚctxÚboolÚ
args_validNúdict[str, Any] | NoneÚvalidated_argsz'ToolRetryError | ToolFailedError | NoneÚvalidation_errorz&CallDeferred | ApprovalRequired | NoneÚdeferral© )
Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__Ú__annotations__rB   rC   rD   Ú__static_attributes__rE   ó    ÚU/home/mande/repo/quber/.venv/lib/python3.13/site-packages/pydantic_ai/tool_manager.pyr8   r8   8   s`   ‡ ñð ÓØ&Ø
(Ó(Ø>Ø	ÓØ-ØÓØIØ,0€NÐ)Ó0ðð AEÐÐ=ÓDØMØ7;€HÐ4Ó;òrM   r8   c                  ó0   ^ • \ rS rSrSrSU 4S jjrSrU =r$ )Ú_ToolUnavailableéb   uø  A `ModelRetry` refusing a call because the tool is not available yet.

A distinct type only so `_make_validation_failure` can recognise it. It
reaches the model as an ordinary retry prompt, exactly like the `ModelRetry` it replaced.

Carries the tool it refused: the refusal is raised while resolving, before the caller has
bound the resolved tool, and the budget this failure is charged against is the tool's own
`max_retries` â€” not the manager's default, which is all an unresolved name could offer.
c                ó0   >• [         TU ]  U5        X l        g ©N)ÚsuperÚ__init__r<   )ÚselfÚmessager<   Ú	__class__s      €rN   rU   Ú_ToolUnavailable.__init__m   s   ø€ Ü‰Ñ˜Ô!Ø�	rM   )r<   )rW   Ústrr<   zToolsetTool[Any]©rF   rG   rH   rI   rJ   rU   rL   Ú__classcell__©rX   s   @rN   rP   rP   b   s   ø† ñ÷õ rM   rP   c                  ó0   ^ • \ rS rSrSrSU 4S jjrSrU =r$ )Ú_ValidationDeferralér   a‡  Internal signal that validation requested approval for or deferred the tool call.

Raised for a deferral from the tool's `args_validator` or from a validation hook that already
has validated arguments. Carries those arguments alongside the user's deferral so
`validate_tool_call` can report the call as valid and re-raise the deferral at the execution
boundary. Never escapes `ToolManager`.
c                ó:   >• Xl         X l        [        TU ]  5         g rS   )rD   rB   rT   rU   )rV   rD   rB   rX   s      €rN   rU   Ú_ValidationDeferral.__init__{   s   ø€ Ø ŒØ,ÔÜ‰ÑÕrM   )rD   rB   )rD   úCallDeferred | ApprovalRequiredrB   údict[str, Any]r[   r]   s   @rN   r_   r_   r   s   ø† ñ÷õ rM   r_   c                óL   • [        SU  S[        U5      R                   S35      $ )uo  Build the error for a tool validation hook that deferred before the arguments were validated.

A tool call may only be deferred once its arguments are known to be valid â€” whoever resolves the
deferral is shown those arguments. Hooks that run before validation (or after it failed) have
none, so they get this error instead; the message names the positions that do.
Ú`z
` raised `z½`, but a tool call can only be deferred once its arguments have been validated. Raise it from `after_tool_validate`, from the tool's `args_validator`, or from `before_tool_execute` instead.)r$   ÚtyperF   )Ú	hook_nameÚerrors     rN   Ú_validate_hook_deferral_errorrj   �   s3   € ô Ø
ˆIˆ;�j¤ e£×!5Ñ!5Ð 6ð 7)ð 	)óð rM   c                  ó   • \ rS rSr% SrS\S'    SrS\S'    SrS\S	'    SrS
\S'    \	" \
\   S9rS\S'    \	" \
\   S9rS\S'    \	" \
\   S9rS\S'    SrS\S'    SrS\S'    \\S;S<S jj5       5       rS=S jr\S>S j5       rS?S jrS@S jrSAS jrSBS jr\SCS j5       r\SDS j5       rSSS .           SES! jjrSS".           SFS# jjr          SGS$ jr S%S&.       SHS' jjr!SIS( jr"SJS) jr#          SKS* jr$            SLS+ jr%SSS%S,.         SMS- jjr&S%S&.     SNS. jjr'SS%S/.         SOS0 jjr(S%S&.       SPS1 jjr)SS%S/.         SQS2 jjr*S%S&.       SHS3 jjr+S%S&.       SHS4 jjr,SSS%SSS5.             SRS6 jjr-    SSS7 jr.S%SS8.         STS9 jjr/S:r0g)UÚToolManageré�   z€Manages tools for an agent run step. It caches the agent run's toolset's tool definitions and handles calling tools and retries.zAbstractToolset[AgentDepsT]ÚtoolsetNz%AbstractCapability[AgentDepsT] | NoneÚroot_capabilityzRunContext[AgentDepsT] | Noner>   z)dict[str, ToolsetTool[AgentDepsT]] | NoneÚtools)Údefault_factoryzset[str]Úfailed_toolsÚsucceeded_toolsÚavailability_refusedr   ÚintÚdefault_max_retrieszfrozenset[str] | NoneÚresolved_capability_idsc              #  óž   #   • [         R                  U5      n Sv •  [         R                  U5        g! [         R                  U5        f = f7f)a�  Set the parallel execution mode during the context.

Args:
    mode: The execution mode for tool calls:
        - 'parallel': Run tool calls in parallel, yielding events as they complete (default).
        - 'sequential': Run tool calls one at a time in order.
        - 'parallel_ordered_events': Run tool calls in parallel, but events are emitted in order, after all calls complete.
N)r6   ÚsetÚreset)ÚclsÚmodeÚtokens      rN   r4   Ú#ToolManager.parallel_execution_mode¾   s<   é € ô 1×4Ñ4°TÓ:ˆð	:Ûä,×2Ñ2°5Õ9øÔ,×2Ñ2°5Õ9üs   ‚A™3 �A³A
Á
Ac              ƒ  ó  #   • [        UR                  5      nSnU R                  bú  UR                  U R                  R                  :X  a1  X R                  :X  a  U $ Sn[        XR                  R                  S9nO¥U R                  R                  R                  5        VVs0 s H  u  pEX@R                  ;  d  M  XE_M     nnnUR                  U R                   Vs0 s H,  nXpR                  R                  R                  US5      S-   _M.     sn5        [        XS9nU(       a  U R                  O"U R                  R                  U5      I Sh  v•N nU R                  UU R                  UUR!                  U5      I Sh  v•N U R"                  U R$                  UU(       a  U R                  O[&        [(           " 5       U(       a  U R                  O[&        [(           " 5       S9	n	X‘l        U	$ s  snnf s  snf  N© Nz7f)aU  Build a new tool manager for the next run step, carrying over the retries from the current run step.

Re-resolves within a step as well, when capability availability moved since the cached tools
were resolved (see `resolved_capability_ids`), so a capability that became active mid-step
still gets its `prepare_tools` say over its own tools.
FNT)Úretriesr   r   )	rn   ro   r>   rp   rv   rt   rw   rr   rs   )Ú	frozensetÚ_dispatch_active_capability_idsr>   Úrun_steprw   r   r€   Úitemsrs   Úupdaterr   Úgetrn   Úfor_run_steprX   ro   Ú	get_toolsrv   rt   ry   rZ   Útool_manager)
rV   r>   rw   Ú	same_stepÚ	tool_nameÚcountr€   Úfailed_tool_namern   Únew_tms
             rN   r‡   ÚToolManager.for_run_stepÏ   sÇ  é € ô #,¨C×,OÑ,OÓ"PÐØˆ	Ø�8‰8ÑØ�|‰|˜tŸx™x×0Ñ0Ó0Ø*×.JÑ.JÓJØ�Kð
 !�	Ü˜c¯8©8×+;Ñ+;Ñ<‘ð -1¯H©H×,<Ñ,<×,BÑ,BÔ,Dôâ,DÑ(˜	Ø ×(<Ñ(<Ñ<ó %�IÒ$Ù,Dð ñ ð
 —‘ð 15×0AÒ0Aóâ0AÐ,ð )¯(©(×*:Ñ*:×*>Ñ*>Ð?OÐQRÓ*SÐVWÑ*WÒWÙ0Añôô ˜cÑ3�ö #,�$—,’,°t·|±|×7PÑ7PÐQTÓ7U×1Uˆà—‘ØØ ×0Ñ0ØØ×)Ñ)¨#Ó.×.Ø $× 8Ñ 8Ø!%×!:Ñ!:Ø$;ö /8˜×*Ò*¼SÄºX»ZÞ4=˜D×0Ò0Ä3ÄsÂ8Ã:ð  ð 
ˆð  "ÔØˆùóIùòñ 2Vñ /ùsD   ‚B!H Â#G1Â<G1ÃH Ã3G7ÄAH ÅG<Å0H ÆG>ÆA9H Ç>H c                ó¤   • U R                   c  [        S5      eU R                   R                  5        Vs/ s H  oR                  PM     sn$ s  snf )z8The tool definitions for the tools in this tool manager.ú4ToolManager has not been prepared for a run step yet)rp   Ú
ValueErrorÚvaluesÚtool_def)rV   r<   s     rN   Ú	tool_defsÚToolManager.tool_defs	  sC   € ð �:‰:ÑÜÐSÓTÐTà*.¯*©*×*;Ñ*;Ô*=Ó>Ò*= $—”Ñ*=Ñ>Ð>ùÒ>s   µAc                ó*   • [         R                  5       $ )a¬  Get the run-scoped parallel execution mode set via [`parallel_execution_mode`][pydantic_ai.tool_manager.ToolManager.parallel_execution_mode].

Per-tool `sequential=True` barriers are applied separately during execution and don't
affect this run-scoped mode: a single barrier tool no longer forces the whole batch
serial (the v1 behavior). Use `parallel_execution_mode('sequential')` to opt the entire
run into serial execution.
)r6   r†   )rV   s    rN   Úget_parallel_execution_modeÚ'ToolManager.get_parallel_execution_mode  s   € ô 0×3Ñ3Ó5Ð5rM   c                óf   • U R                  UR                  5      nUSL=(       a    UR                  $ )zóWhether a tool call must run as a barrier (`sequential=True`), executing alone.

Tools emitted before a barrier complete first; the barrier runs by itself; tools emitted
after it start only once it finishes. Other tools parallelize around it.
N)Úget_tool_defr‹   r2   )rV   r:   r”   s      rN   Úis_sequentialÚToolManager.is_sequential  s.   € ð ×$Ñ$ T§^¡^Ó4ˆØ˜tÐ#×;¨×(;Ñ(;Ð;rM   c                óŠ   • U R                   c  [        S5      eU R                   R                  U5      nUb  UR                  $ S$ )zPGet the tool definition for a given tool name, or `None` if the tool is unknown.Nr‘   )rp   r’   r†   r”   )rV   Únamer<   s      rN   r›   ÚToolManager.get_tool_def$  s>   € à�:‰:ÑÜÐSÓTÐTØ�z‰z�~‰~˜dÓ#ˆØ $Ñ 0ˆt�}‰}Ð:°dÐ:rM   c                óž   • U R                   c   eU R                   R                  R                  US5      U:¼  a  [        SU< SU S35      Ueg)zGRaise UnexpectedModelBehavior if the tool has exceeded its max retries.Nr   úTool z exceeded max retries count of z�. Consider raising the retry limit, or see the docs on tool retries: https://pydantic.dev/docs/ai/tools-toolsets/tools-advanced/#tool-retries)r>   r€   r†   r#   )rV   rŸ   Úmax_retriesri   s       rN   Ú_check_max_retriesÚToolManager._check_max_retries+  se   € à�x‰xÑ#Ð#Ð#ð �8‰8×Ñ×Ñ  aÓ(¨KÓ7Ü)Ø˜‘xÐ>¸{¸mð LCð Cóð ðð 8rM   c                óV   • [         R                  " X UR                  S9n[        U5      $ )zSConvert a ValidationError or ModelRetry to a ToolRetryError with a RetryPromptPart.)r‹   Útool_call_id)r%   Ú
from_errorr§   r"   ©rŸ   r:   ri   Úms       rN   Ú_wrap_error_as_retryÚ ToolManager._wrap_error_as_retry6  s'   € ô ×&Ò& uÈ4×K\ÑK\Ñ]ˆÜ˜aÓ Ð rM   c                ón   • [         R                  " U UR                  UR                  SS9n[	        U5      $ )zGConvert a ToolFailed to a ToolFailedError with a failed ToolReturnPart.Úfailed)r‹   Úcontentr§   Úoutcome)Ú	_messagesÚToolReturnPartrW   r§   r!   r©   s       rN   Ú_wrap_error_as_failedÚ!ToolManager._wrap_error_as_failed<  s7   € ô ×$Ò$ØØ—M‘MØ×*Ñ*Øñ	
ˆô ˜qÓ!Ð!rM   F)ÚapprovedÚmetadatac               óî   • U R                   c   e[        U R                   U UR                  UR                  U R                   R                  R                  UR                  S5      UR                  UUUS9	$ )z,Build the execution context for a tool call.r   )r‰   r‹   r§   Úretryr£   Útool_call_approvedÚtool_call_metadataÚpartial_output)r>   r   r‹   r§   r€   r†   r£   )rV   r:   r<   Úallow_partialrµ   r¶   s         rN   Ú_build_tool_contextÚToolManager._build_tool_contextG  sm   € ð �x‰xÑ#Ð#Ð#ÜØ�H‰Hð
 Ø—n‘nØ×*Ñ*Ø—(‘(×"Ñ"×&Ñ& t§~¡~°qÓ9Ø×(Ñ(Ø'Ø'Ø(ñ
ð 	
rM   )Úargs_overridec             ƒ  óò  #   • Ub  UOUR                   nU(       a  SOSnUR                  n[        U[        5      (       a$  UR	                  U=(       d    SXsR
                  S9n	O#UR                  U=(       d    0 XsR
                  S9n	UR                  b;   UR                  " U40 U	D6n
[        R                  " U
5      (       a
  U
I Sh  v•N   U	$ U	$  N! [        [        4 a  n[        X¹5      UeSnAff = f7f)a^  Validate tool arguments using Pydantic schema and custom args_validator_func.

Returns:
    The validated arguments as a dictionary.

Raises:
    ValidationError: If argument validation fails.
    ModelRetry: If argument validation fails with a retry request.
    _ValidationDeferral: If the custom validator requested approval or deferred the call.
Nztrailing-stringsÚoffz{})r¼   Úcontext)ÚargsÚargs_validatorÚ
isinstancerZ   Úvalidate_jsonÚvalidation_contextÚvalidate_pythonÚargs_validator_funcÚinspectÚisawaitabler   r   r_   )rV   r:   r<   r>   r¼   r¿   Úraw_argsÚpyd_allow_partialÚ	validatorÚ	args_dictÚresultÚes               rN   Ú_validate_tool_argsÚToolManager._validate_tool_argsb  sý   é € ð& %2Ñ$=‘=À4Ç9Á9ˆÞ2?Ñ.ÀUÐØ×'Ñ'ˆ	Ü�h¤×$Ñ$Ø!×/Ñ/Ø× ˜DÐ0A×KaÑKað 0ð ‰Ið "×1Ñ1Ø—˜BÐ.?×I_ÑI_ð 2ð ˆIð ×#Ñ#Ñ/ð?Ø×1Ò1°#ÑC¸ÑC�Ü×&Ò& v×.Ñ.Ø —L�Lð ÐˆyÐñ !øÜ Ô"2Ð3ó ?ô *¨!Ó7¸QÐ>ûð	?üs<   ‚BC7Â3C ÃCÃ	C ÃC7ÃC ÃC4Ã#C/Ã/C4Ã4C7c          	   ƒ  ó  ^ ^^^^^#   • T R                   nSmS
UUUUU U4S jjnUb¯  TR                  R                  S:w  a•  TR                  nTR                  b  TR                  O0 n UR	                  TTXxS9I Sh  v•N nSn
 UR                  TTXxUS9I Sh  v•N n UR                  TTX{S9I Sh  v•N nU
b  [        U
R                  U5      U
e U$ U" TR                  b  TR                  O0 5      I Sh  v•N nU$  Nƒ! [
        [        4 a  n	[        SU	5      U	eSn	A	ff = f N�! [         a  n	U	n
U	R                  n Sn	A	N¨Sn	A	f[
        [        4 a(  n	Tc  [        SU	5      U	e[        U	T5      n
Tn Sn	A	NÞSn	A	f[        [        4 aL  n	 UR                  TTXxU	S9I Sh  v•N  n Sn	A	GN! [
        [        4 a  n[        S	U5      UeSnAff = fSn	A	ff = f GN+! [
        [        4 a  n	[        X›5      U	eSn	A	ff = f GN7f)z:Run validation with before/wrap/after tool_validate hooks.Nc              “  óN   >#   • TR                  TTTTU S9I S h  v•N nUmU$  N7f)N)r¼   r¿   )rÒ   )rÃ   Ú	validatedr¼   r:   r>   Úhandler_validated_argsrV   r<   s     €€€€€€rN   Údo_validateÚ4ToolManager._run_validate_hooks.<locals>.do_validateš  s<   øé € ð #×6Ñ6°t¸TÀ3ÐVcÐswÐ6Ðx×xˆIð &/Ð"ØÐñ	 yùs   ƒ%š#›	%Úoutput©r:   r”   rÃ   Úbefore_tool_validate©r:   r”   rÃ   ÚhandlerÚwrap_tool_validate©r:   r”   rÃ   ri   Úon_tool_validate_error)rÃ   ústr | dict[str, Any]Úreturnrd   )ro   r”   ÚkindrÃ   rÜ   r   r   rj   rß   r_   rB   r   r   rá   Úafter_tool_validaterD   )rV   r:   r<   r>   r¼   ÚcaprØ   r”   rÌ   rÑ   rD   rB   Úhook_deferralr×   s   `````        @rN   Ú_run_validate_hooksÚToolManager._run_validate_hooksŽ  sN  ýé € ð ×"Ñ"ˆØ8<Ð÷	ô 	ð ‰?˜tŸ}™}×1Ñ1°XÓ=Ø—}‘}ˆHð ;?¿)¹)Ñ:O¨T¯YªYÐUWˆHðVØ!$×!9Ñ!9¸#ÀDÐS[Ð!9Ð!k×k�ð
 48ˆHðtØ'*×'=Ñ'=Ø˜d¨XÈkð (>ð (÷ "�ð:DØ'*×'>Ñ'>¸sÈÐX`Ð'>Ð'v×!v�ð
 Ñ#ô *¨(×*;Ñ*;¸^ÓLÐRZÐZð $ð Ðñ $/¸D¿I¹IÑ<Q¨t¯yªyÐWYÓ#Z×ZˆNàÐñc løÜ Ô"2Ð3ó VÜ3Ð4JÈAÓNÐTUÐUûðVúñ"øô 'ó 2ð
 �Ø!"×!1Ñ!1•ûÜ Ô"2Ð3ó 8ð *Ñ1Ü7Ð8LÈaÓPÐVWÐWÜ.¨qÐ2HÓI�Ø!7•ûÜ#¤ZÐ0ó tðtØ+.×+EÑ+EØ $°ÐPQð ,Fð ,÷ &ð &–Nøô %Ô&6Ð7ó tä7Ð8PÐR_Ó`ÐfsÐsûðtþðtúò "wøÜ Ô"2Ð3ó Dä)¨!Ó<À!ÐCûðDúò [ùsý   ˆA H	Á)D Á=DÁ>D ÂH	ÂD* ÂD(ÂD* Â G" Â4GÂ5G" Â9AH	Ã:HÃ;H	ÄD ÄD%ÄD Ä D%Ä%H	Ä(D* Ä*
GÄ4EÅH	ÅGÅE=Å8H	Å=GÆF2Æ&F)Æ'F2Æ,H	Æ2GÇGÇGÇGÇGÇH	ÇG" Ç"HÇ2G>Ç>HÈH	T©Úwrap_validation_errorsc          	   ƒ  óH  ^ ^^^#   • TR                   c   eTR                  c   eT R                  nTR                  nTR                  nSU UUU4S jjnUb“  TR                   R
                  R                  S:w  ao  TR                   R
                  n UR                  XeUTR                  S9I Sh  v•N n	 UR                  XeX‰US9I Sh  v•N n
UR%                  XeX‰U
S9I Sh  v•N n
U
$ U" TR                  5      I Sh  v•N n
U
$  NU N=! [        [        [        [        [        4 a    e [        [        4 a    e [          a$  nUR#                  XeX‰US9I Sh  v•N  n
 SnAN“SnAff = f N†! [&        [        4 an  nT(       d  e UR(                  nT R+                  UTR                   R,                  U5        T R.                  R1                  U5        T R3                  XÅU5      UeSnAf[         a*  nT(       d  e T R5                  UR(                  X[5      UeSnAff = f GN 7f)	z8Run execution with before/wrap/after tool_execute hooks.Nc              “  óV   >#   • [        TU S9nTR                  UTTS9I S h  v•N $  N7f)N)rB   ©Úusagerë   )r   Ú_raw_execute)rÃ   Úmodified_validatedrV   rï   rÖ   rë   s     €€€€rN   Ú
do_executeÚ2ToolManager._run_execute_hooks.<locals>.do_executeí  s=   øé € ä!(¨À4Ñ!HÐØ×*Ñ*Ø"¨%ÐH^ð +ð ÷ ð ñ ùs   ƒ)¢'£)rÚ   rÛ   rÝ   rà   )r:   r”   rÃ   rÐ   )rÃ   rd   rã   r   )r<   rB   ro   r:   r>   r”   rä   Úbefore_tool_executeÚwrap_tool_executer   r   r   r"   r!   r    r   Ú	ExceptionÚon_tool_execute_errorÚafter_tool_executer   r‹   r¤   r£   rr   Úaddr«   r³   )rV   rÖ   rï   rë   ræ   r:   r>   rò   r”   rÃ   Útool_resultrÑ   rŸ   s   ````         rN   Ú_run_execute_hooksÚToolManager._run_execute_hooksÞ  s  ûé € ð �~‰~Ñ)Ð)Ð)Ø×'Ñ'Ñ3Ð3Ð3à×"Ñ"ˆØ�~‰~ˆØ�m‰mˆ÷	ò 	ð ‰?˜yŸ~™~×6Ñ6×;Ñ;¸xÓGØ —~‘~×.Ñ.ˆHð!Qà ×4Ñ4°SÈhÐ]f×]uÑ]uÐ4Ðv×v�ð	yØ(+×(=Ñ(=Ø°Èjð )>ð )÷ #�Kð %(×$:Ñ$:Ø¨XÈð %;ð %÷ �ð( Ðñ !+¨9×+CÑ+CÓ D×DˆKàÐñG wñ#øô *¬<Ô9IÌ>Ô[jÐkó ØÜ"¤JÐ/ó ØÜ ó yØ(+×(AÑ(AÀ#Ð[cÐvwÐ(AÐ(x×"xÐ"x•Kûðyúñøô $¤ZÐ0ó 	Fö .ØØ—~‘~�Ø×'Ñ'¨¨i¯n©n×.HÑ.HÈ!ÔLØ×!Ñ!×%Ñ% dÔ+Ø×/Ñ/°¸AÓ>ÀAÐEûÜó QÞ-ØØ×0Ñ0°·±ÀÓIÈqÐPûðQúò
 Eùs©   †BH"ÂE, Â0DÂ1E, Â6D
 Ã
DÃD
 ÃE, Ã#E*Ã$E, Ã(H"Ã?HÄ H"ÄE, ÄD
 Ä
9E'ÅE"ÅEÅE"ÅE, Å"E'Å'E, Å,HÅ<A)G%Ç%HÇ2%HÈHÈH"c                óê  ^ • T R                   b  T R                  c  [        S5      eUR                  nT R                   R	                  U5      nUcx  [        U 4S jT R                   R                  5        5       5      nU(       a  SSR                  S U 5       5       3nOT R                   (       a  SnOSn[        SU< S	U 35      eT R                  UR                  5      =nb  [        Xc5      eX#4$ )
zWResolve tool name to ResolvedTool, raising ModelRetry for unknown or unavailable tools.r‘   c              3  ó„   >#   • U  H5  u  pTR                   R                  UR                  5      (       d  M1  Uv •  M7     g 7frS   )r>   Úis_tool_availabler”   )Ú.0ÚnÚtrV   s      €rN   Ú	<genexpr>Ú,ToolManager._resolve_tool.<locals>.<genexpr>+  s/   øé € ÐjÒ-?¡T QÀ4Ç8Á8×C]ÑC]Ð^_×^hÑ^h×CiŸq™qÒ-?ùs
   ƒ0A ·	A zAvailable tools: z, c              3  ó(   #   • U  H  o< v •  M
     g 7frS   rE   )r   r  s     rN   r  r  -  s   é € Ð3PÂiÀ±e´HÂiùs   ‚z:No tools are available yet: search for the tools you need.zNo tools available.zUnknown tool name: z. )rp   r>   r’   r‹   r†   Úsortedr„   Újoinr   Ú_unavailable_reasonr”   rP   )rV   r:   rŸ   r<   Ú	availableÚmsgÚunavailables   `      rN   Ú_resolve_toolÚToolManager._resolve_tool   s×   ø€ à�:‰:Ñ §¡Ñ!1ÜÐSÓTÐTà�~‰~ˆØ�z‰z�~‰~˜dÓ#ˆØ‰<ô Ôj¨T¯Z©Z×-=Ñ-=Ô-?ÓjÓjˆIÞØ)¨$¯)©)Ñ3PÁiÓ3PÓ*PÐ)QÐR‘Ø——ØR‘à+�ÜÐ2°4±(¸"¸S¸EÐBÓCÐCØ×3Ñ3°D·M±MÓBÐBˆKÑOÜ" ;Ó5Ð5ØˆzÐrM   c                óþ   • U R                   c   eU R                   R                  U5      (       a  gUR                  =nb.  X R                   R                  ;  a  SUR                  < SU< S3$ SUR                  < S3$ )u#  Why this tool cannot be called yet, or `None` when it is available.

A deferred tool is callable only once the model has been shown it. The message says *not
available yet* rather than "unknown tool" so the model searches or loads again instead of
concluding the tool does not exist â€” and the resulting search/load exchange restores the
history that justifies the call, which is what keeps a compacted history coherent.

Both requirements apply to a capability-owned tool: an active capability is what makes
its tools *eligible* to be shown, not proof that any of them were. An always-on capability
can own search-gated tools, and loading a deferred one reveals its tools through the same
availability delta everything else uses â€” so discovery stays the single answer to "has the
model seen this?".
Nr¢   z0 is not available yet: it belongs to capability zo. Call `load_capability` for it first, then call the tool again once you've read the capability's instructions.z[ is not available yet: search for it first, then call it again once you've seen its schema.)r>   rÿ   Úcapability_idÚactive_capability_idsrŸ   )rV   r”   r  s      rN   r  ÚToolManager._unavailable_reason7  s”   € ð �x‰xÑ#Ð#Ð#Ø�8‰8×%Ñ% h×/Ñ/Øð &×3Ñ3Ð3ˆMÑ@Ø§¡×!?Ñ!?Ó?ð ˜Ÿ™Ñ(Ð(XØ Ñ#ð $BðBðð �H—M‘MÑ$ð %+ð +ð	
rM   c           	     ó   • [        UUUSUSS9$ )zRBuild a successful `ValidatedToolCall`. Counterpart to `_make_validation_failure`.TN©r:   r<   r>   r@   rB   rC   )r8   )rV   r:   r<   r>   rB   s        rN   Ú_make_validation_successÚ$ToolManager._make_validation_successX  s#   € ô !ØØØØØ)Ø!ñ
ð 	
rM   c           	     ó  • Ub  UR                   OU R                  n[        U[        5      (       a+  [        UR                  [
        5      (       a  UR                  OUn[        U[        5      (       a+  XR                  ;  a  U R                  R                  U5        O-U R                  XU5        U R                  R                  U5        [        U[        5      (       a  UOU R                  XU5      n[        UUUSSUS9$ )a  Handle validation failure: check retries, mark failed, wrap error.

Only called when wrapping is requested (`wrap_validation_errors=True`); when
False (streaming, or sandboxed callers that want raw errors), the caller lets
the exception propagate without going through this helper.
NFr  )r£   rv   rÅ   r"   Ú	__cause__rö   rP   rt   rù   r¤   rr   r«   r8   )	rV   rŸ   r:   r<   r>   ri   r£   ÚcauserC   s	            rN   Ú_make_validation_failureÚ$ToolManager._make_validation_failurei  sà   € ð +/Ñ*:�d×&Ò&À×@XÑ@Xˆä)¨%´×@Ñ@ÄZÐPU×P_ÑP_Ôaj×EkÑEkˆE�OŠOÐqvð 	ô �eÔ-×.Ñ.°4×?XÑ?XÓ3XØ×%Ñ%×)Ñ)¨$Õ/à×#Ñ# D°uÔ=Ø×Ñ×!Ñ! $Ô'Ü$.¨u´n×$EÑ$E™5È4×KdÑKdÐeiÐqvÓKwÐÜ ØØØØØØ-ñ
ð 	
rM   ©rµ   r¶   rë   c             ƒ  ó"  #   • U R                   c   eU R                   nSn U R                  U5      u  pvU R                  XSX#S9nU R                  XUSS9I Sh  v•N nU R	                  XXX5      $  N! [
         a+  n	Uc   eU R	                  XXYR                  5      s Sn	A	$ Sn	A	f[         a=  n	Uc   e[        U R	                  XXYR                  5      U	R                  S9s Sn	A	$ Sn	A	f[        [        4 aP  n	U(       d  e [        U	[        5      (       a  U	R                  nU R                  UR                   XXY5      s Sn	A	$ Sn	A	f["         a:  n	U(       d  e [%        UUUSSU R'                  UR                   X5      S9s Sn	A	$ Sn	A	ff = f7f)u  Validate tool arguments without executing the tool.

This method validates arguments BEFORE the tool is executed, allowing the caller to:
1. Emit `FunctionToolCallEvent` / `OutputToolCallEvent` with accurate `args_valid` status
2. Handle validation failures differently from execution failures
3. Decide whether to execute or defer based on validation result

A tool call can be deferred during validation by raising
[`ApprovalRequired`][pydantic_ai.exceptions.ApprovalRequired] or
[`CallDeferred`][pydantic_ai.exceptions.CallDeferred] â€” but only once its arguments are known
to be valid, which the caller is shown. That means the tool's `args_validator`,
`after_tool_validate`, or `wrap_tool_validate` after its handler has returned; the same
exception raised before validation has run raises a `UserError` naming the alternatives.

A permitted deferral is control flow rather than a validation failure: the returned
`ValidatedToolCall` has `args_valid=True` and carries the exception on
[`deferral`][pydantic_ai.tool_manager.ValidatedToolCall.deferral], which `execute_tool_call`
raises in place of running the tool, so callers handle deferrals in one place.

Args:
    call: The tool call part to validate.
    approved: Whether the tool call has been approved.
    metadata: Additional metadata from DeferredToolResults.metadata.
    wrap_validation_errors: If True (default), wrap `ValidationError` / `ModelRetry`
        as `ToolRetryError` on the returned `ValidatedToolCall.validation_error`,
        count the call against the retry budget, and add it to `failed_tools`.
        `ToolFailed` is wrapped as `ToolFailedError` without consuming the retry
        budget. If False, propagate the raw exception and leave retry-budget state
        untouched â€” useful for nested callers (e.g. sandboxed tool dispatch) where
        validation failures shouldn't consume the agent's retry budget and the raw
        exception is what the caller wants to surface.

Returns:
    ValidatedToolCall with validation results, ready for execution via execute_tool_call().
NF)r¼   rµ   r¶   ©r¼   )rD   r  )r>   r  r½   rè   r  r   rB   r_   r   rD   r   r   rÅ   rP   r<   r  r‹   r    r8   r³   )
rV   r:   rµ   r¶   rë   r>   r<   Ú_namerB   rÑ   s
             rN   Úvalidate_tool_callÚToolManager.validate_tool_call‘  sƒ  é € ðV �x‰xÑ#Ð#Ð#Ø�h‰hˆØ/3ˆð$	Ø×,Ñ,¨TÓ2‰KˆEØ×*Ñ*¨4ÀUÐU]Ð*ÐqˆCØ#'×#;Ñ#;¸DÈÐ[`Ð#;Ð#a×aˆNØ×0Ñ0°¸SÓQÐQñ bøä!ó 	TØÑ#Ð#Ð#à×0Ñ0°¸S×BRÑBRÓSÕSûÜ"ó 	rØÑ#Ð#Ð#ô ˜4×8Ñ8¸ÀS×JZÑJZÓ[Ðfg×fpÑfpÑqÕqûÜ¤Ð,ó 	UÞ)ØÜ˜!Ô-×.Ñ.ð —v‘v�Ø×0Ñ0°·±ÀÈSÓTÕTûÜó 
	Þ)ØÜ$ØØØØ Ø#Ø!%×!;Ñ!;¸D¿N¹NÈDÓ!Tñõ ûð
	üs�   ‚F¡8A2 ÁA0ÁA2 Á/FÁ0A2 Á2
FÁ< B"ÂFÂFÂ"FÂ/2C'Ã!FÃ"FÃ'FÃ:AEÄ?FÅ FÅFÅ/FÆFÆFÆFÆFc             ƒ  ó–   #   • U R                   c  [        S5      eU R                  XR                   R                  US9I Sh  v•N $  N7f)a–  Execute a validated tool call via capability hooks.

The Instrumentation capability (if present) creates trace spans via its
wrap_tool_execute hook.

Args:
    validated: The validation result from validate_tool_call().
    wrap_validation_errors: If True (default), `ModelRetry` raised by the tool
        body or by execute-stage capability hooks (`before_tool_execute`,
        `after_tool_execute`, `wrap_tool_execute`) is wrapped as `ToolRetryError`
        after counting against the retry budget. If False, the raw
        `ModelRetry` / `ValidationError` propagates and retry-budget state is
        left untouched.

Returns:
    The tool result if validation passed and execution succeeded.

Raises:
    ToolRetryError: If validation failed with a retry prompt or the tool raised
        `ModelRetry`. Only when `wrap_validation_errors=True`.
    ToolFailedError: If validation failed with `ToolFailed`, or the tool raised
        `ToolFailed`. Only when `wrap_validation_errors=True`.
    ModelRetry / ValidationError / ToolFailed: When `wrap_validation_errors=False`.
    CallDeferred / ApprovalRequired: If the tool's `args_validator` deferred the call
        (see [`ValidatedToolCall.deferral`][pydantic_ai.tool_manager.ValidatedToolCall.deferral])
        or the tool function raised one of these itself. The tool is not executed in the
        former case.
    RuntimeError: If trying to execute an external tool.
Nr‘   rî   )r>   r’   Ú_execute_tool_call_implrï   )rV   rÖ   rë   s      rN   Úexecute_tool_callÚToolManager.execute_tool_callæ  sN   é € ðF �8‰8ÑÜÐSÓTÐTà×1Ñ1ØŸX™XŸ^™^ÐDZð 2ð 
÷ 
ð 	
ñ 
ùs   ‚A A	ÁAÁA	)r¼   rë   c          
   ƒ  óâ  ^^^#   • U R                   c   eU R                  U5      u  pV[        UR                  [        5      (       d'   S[        UR                  5      R                   35       eU R                  XTS9mUR                  nUR                  U   mTR                  USXR                  S9nS	UUU4S jjn	U R                  n
U
c   S5       e UR                  b  UR                  O0 n[        U
TUUU	TUS9I Sh  v•N nTR                  =nb  XÜ0nOUnU R                  XTU5      $  N,! [         ["        [$        4 a&  nU(       d  e U R'                  XQUTU5      s SnA$ SnAff = f7f)
aÙ  Validate output tool args through output validate hooks (skipping tool hooks).

Output tools use output hooks for validation instead of tool hooks. The Pydantic
schema validation is used as the inner handler wrapped by output validate hooks.

`schema` is the run's output schema; it's forwarded to
[`OutputContext`][pydantic_ai.output.OutputContext] so hooks can see the full shape
of what the schema accepts.

Raises:
    UnexpectedModelBehavior: If max retries exceeded.
NzExpected output tool, got r  r<   ©r|   Ú	tool_callr”   c              “  ó6   >#   • TR                  U TTS9u  pU$ 7f)N)Úrun_contextr¼   )Úhook_validate)rÃ   ÚsemanticÚ_stater¼   r>   Ú	processors      €€€rN   rØ   Ú:ToolManager.validate_output_tool_call.<locals>.do_validate6  s&   øé € Ø(×6Ñ6°tÈÐ\iÐ6ÐjÑˆHØˆOùs   ƒz2validate_output_tool_call requires root_capability)r)  Úoutput_contextrÚ   rØ   r¼   rë   )rÃ   râ   rã   r   )r>   r  rÅ   rn   r   rg   rF   r½   Ú
processorsÚget_output_contextr”   ro   rÃ   r   Úhook_unwrap_keyr  r"   r   r   r  )rV   r:   Úschemar¼   rë   rŸ   r<   rn   r/  rØ   ræ   rÌ   Úsemantic_valueÚkrB   rÑ   r>   r-  s      `            @@rN   Úvalidate_output_tool_callÚ%ToolManager.validate_output_tool_call  s‡  úé € ð( �x‰xÑ#Ð#Ð#ð ×'Ñ'¨Ó-‰
ˆÜ˜$Ÿ,™,¬×6Ñ6ÐrÐ:TÔUYÐZ^×ZfÑZfÓUg×UpÑUpÐTqÐ8rÓrÐ6Ø×&Ñ& tÀÐ&ÐOˆà—,‘,ˆØ×&Ñ& tÑ,ˆ	Ø"×5Ñ5°fÀ6ÐUY×dqÑdqÐ5Ðrˆ÷	ñ 	ð ×"Ñ"ˆØ‰ÐTÐ TÓTˆð	KØ:>¿)¹)Ñ:O¨T¯YªYÐUWˆHÜ#<ØØØ-ØØ'Ø+Ø'=ñ$÷ ˆNð  ×.Ñ.Ð.�Ñ;Ø9:Ð8K‘à!/�Ø×0Ñ0°¸SÀ.ÓQÐQñ)øô* ¤´Ð<ó 	KÞ)ØØ×0Ñ0°¸TÀ3ÈÓJÕJûð	KüsH   …CE/Ã-D1 ÄD/Ä+D1 Ä.E/Ä/D1 Ä1E,ÅE'Å!E,Å"E/Å'E,Å,E/c          	   ƒ  óV  ^^^^#   • TR                   (       d   eTR                  c   eU R                  c   eTR                  R                  nTR                  R
                  m[        T[        5      (       d   eTR                  nTR                  U   mTR                  USTR                  UR                  S9nTR                  =nb1  [        TR                  [        5      (       d   eTR                  U   nOTR                  nTR                  c   e[        TR                  U R                  R                   TR                  S9mSUUUU4S jjn	U R"                  n
U
c   S5       e [%        U
TR                  UUU	US9I Sh  v•N nU(       a  U R2                  R1                  U5        U$  N(! [&         aj  n[        UR(                  [*        5      (       a  UR(                  OUnU R-                  XER                  U5        U R.                  R1                  U5        e SnAff = f7f)	aa  Execute output tool through output process hooks (skipping tool hooks).

Output validators run inside process hooks (inside wrap_output_process), ensuring
the complete output pipeline is wrapped. Validators see the global output retry
context (from self.ctx), not the per-tool context, matching the text output path.

`schema` is the run's output schema; it's forwarded to
[`OutputContext`][pydantic_ai.output.OutputContext] so hooks can see the full shape
of what the schema accepts.

Raises:
    ToolRetryError: If execution or output validation fails.
    UnexpectedModelBehavior: If max retries exceeded.
Nr<   r&  )r¸   r£   c              “  óÚ   >#   •  TR                  U S TR                  SS9I S h  v•N nTR                   H  nUR	                  UT5      I S h  v•N nM     U$  N3! [         a    e f = f N7f)NF)r)  rë   )Úhook_executer>   r   Úoutput_validatorsÚvalidate)rÚ   rÐ   rÎ   r-  rn   rÖ   Úvalidator_ctxs      €€€€rN   Ú
do_processÚ8ToolManager.execute_output_tool_call.<locals>.do_process’  s€   øé € ð	Ø(×5Ñ5Ø˜D¨i¯m©mÐTYð  6ð  ÷ �ð %×6Ô6�	Ø(×1Ñ1°&¸-ÓH×H’ñ 7àˆMñøô ó ð
 ðúñ Iùs7   ƒA+…A ¤A¥A ©$A+ÁA)Á
A+ÁA ÁA&Á&A+z1execute_output_tool_call requires root_capability)r)  r/  rÚ   r>  rë   )rÚ   r   rã   r   )r@   r<   r>   r:   r‹   rn   rÅ   r   r0  r1  r”   r2  rB   Údictr£   r   r¸   ro   r   r"   r  rö   r¤   rr   rù   rs   )rV   rÖ   r3  rë   rŸ   r<   r/  r5  r4  r>  ræ   rÐ   rÑ   r  r-  rn   r=  s    `            @@@rN   Úexecute_output_tool_callÚ$ToolManager.execute_output_tool_callY  sò  ûé € ð* ×#×#Ð#Ð#Ø�~‰~Ñ)Ð)Ð)ð �x‰xÑ#Ð#Ð#à�~‰~×'Ñ'ˆØ—.‘.×(Ñ(ˆÜ˜'¤=×1Ñ1Ð1Ð1à�~‰~ˆØ×&Ñ& tÑ,ˆ	Ø"×5Ñ5Ø˜¨9¯>©>ÀDÇMÁMð 6ð 
ˆð ×*Ñ*Ð*ˆAÑ7Ü˜i×6Ñ6¼×=Ñ=Ð=Ð=Ø"+×":Ñ":¸1Ñ"=‰Nà&×5Ñ5ˆNð ×"Ñ"Ñ.Ð.Ð.Ü 	§¡°T·X±X·^±^ÐQX×QdÑQdÑeˆ÷	ò 	ð* ×"Ñ"ˆØ‰ÐSÐ SÓSˆð	Ü3ØØ%ŸM™MØ-Ø%Ø%Ø'=ñ÷ ˆFö "Ø× Ñ ×$Ñ$ TÔ*Øˆñ#øô ó 	Ü#-¨a¯k©k¼9×#EÑ#E�A—K’KÈ1ˆEØ×#Ñ# D×*:Ñ*:¸EÔBØ×Ñ×!Ñ! $Ô'Øûð		üs=   †E%H)Å,F2 ÆF0ÆF2 Æ$H)Æ0F2 Æ2
H&Æ<A%H!È!H&È&H)c             ƒ  óÐ   #   • U R                  UUUUS9I Sh  v•N nUR                  (       d  UR                  c   eUR                  eU R                  UUUS9I Sh  v•N $  NI N7f)z¿Handle an output tool call using output hooks (not tool hooks).

Convenience method combining validate_output_tool_call and execute_output_tool_call.
Used by the streaming path in result.py.
)r3  r¼   rë   N)r3  rë   )r6  r@   rC   rA  )rV   r:   r3  r¼   rë   rÖ   s         rN   Úhandle_output_tool_callÚ#ToolManager.handle_output_tool_call½  s†   é € ð ×8Ñ8ØØØ'Ø#9ð	 9ð 
÷ 
ˆ	ð ×#×#Ø×-Ñ-Ñ9Ð9Ð9Ø×,Ñ,Ð,Ø×2Ñ2ØØØ#9ð 3ð 
÷ 
ð 	
ñ
ñ
ùs"   ‚A&˜A"™AA&ÁA$ÁA&Á$A&c             ƒ  óF  #   • UR                   b  UR                   eUR                  (       d  UR                  c   eUR                  eUR                  c   eUR                  c   eUR                  R
                  R                  S:X  a  [        S5      e U R                  XUS9I Sh  v•N nU(       a/  U R                  R                  UR                  R                   5        U$  N<! [         a,  n[        R                  " U5        UR                  n SnANkSnAff = f7f)a›  Execute a validated tool call without tracing, with capability hooks.

`wrap_validation_errors` here only governs errors raised *during* execution
(tool body or execute-stage hooks). A `ValidatedToolCall` that already failed
validation carries a pre-wrapped `ToolRetryError`; raw-mode callers get raw
errors at the `validate_tool_call(wrap_validation_errors=False)` boundary.

A `ValidatedToolCall` carrying a `deferral` (its `args_validator` requested approval or
deferred the call) re-raises that exception here without executing the tool.

Raises ToolRetryError if validation previously failed with a retry prompt or the
tool raises ModelRetry (when `wrap_validation_errors=True`). Raises ToolFailedError
if validation previously failed with ToolFailed or the tool raises ToolFailed.
When False, ModelRetry / ToolFailed from the tool body or hooks propagates raw.
Raises UnexpectedModelBehavior if max retries exceeded.
NÚexternalzExternal tools cannot be calledrî   )rD   r@   rC   r<   rB   r”   rä   ÚRuntimeErrorrû   r   r   Úrecord_tool_callrÐ   rs   rù   r:   r‹   )rV   rÖ   rï   rë   rú   rÑ   s         rN   r"  Ú#ToolManager._execute_tool_call_implÚ  s  é € ð. ×ÑÑ)ð
 ×$Ñ$Ð$ð ×#×#Ø×-Ñ-Ñ9Ð9Ð9Ø×,Ñ,Ð,à�~‰~Ñ)Ð)Ð)Ø×'Ñ'Ñ3Ð3Ð3à�>‰>×"Ñ"×'Ñ'¨:Ó5ÜÐ@ÓAÐAð	#Ø $× 7Ñ 7ØÐ?Uð !8ð !÷ ˆKö "Ø× Ñ ×$Ñ$ Y§^¡^×%=Ñ%=Ô>ØÐñøô !ó 	#Ü×/Ò/°Ô6ØŸ(™(�Kûð	#üsB   ‚BD!ÂC( Â)C&Â*C( Â.8D!Ã&C( Ã(
DÃ2"DÄD!ÄDÄD!c             ƒ  ó„  #   • UR                   c   eUR                  c   eUR                  R                  n U R                  R                  UUR                  UR                  UR                   5      I Sh  v•N n[        R                   " U5        U$  N! [         a*  nU(       d  e U R                  XAR                  U5      UeSnAf[         ak  nU(       d  e U R                  XAR                   R                  U5        U R                  R                  U5        U R                  XAR                  U5      UeSnAff = f7f)z7Execute a validated tool call without hooks or tracing.N)r<   rB   r:   r‹   rn   Ú	call_toolr>   r    r³   r   r¤   r£   rr   rù   r«   r   rI  )rV   rÖ   rï   rë   rŸ   rú   rÑ   s          rN   rð   ÚToolManager._raw_execute  s  é € ð �~‰~Ñ)Ð)Ð)Ø×'Ñ'Ñ3Ð3Ð3à�~‰~×'Ñ'ˆð	LØ $§¡× 6Ñ 6ØØ×(Ñ(Ø—‘Ø—‘ó	!÷ ˆKô" 	×+Ò+¨EÔ2àÐñ'øô ó 	MÞ)ØØ×,Ñ,¨T·>±>À1ÓEÈ1ÐLûÜó 	LÞ)ØØ×#Ñ# D¯.©.×*DÑ*DÀaÔHØ×Ñ×!Ñ! $Ô'Ø×+Ñ+¨D·.±.À!ÓDÈ!ÐKûð	LüsG   ‚5E ¸?B Á7BÁ8B Á<E ÂB Â
D=Â %CÃD=ÃA&D8Ä8D=Ä=E )rµ   r¶   rë   Úon_inline_deferredÚon_validatec             ƒ  óf  #   •  U R                  UUUUS9I Sh  v•N nUb  U" UR                  5      I Sh  v•N    U(       dv  UR                  (       ae  UR                  cX  UR                  =nbI  UR
                  R                  (       a.  UR
                  R                  S:X  a
  [        5       e[        5       eU R                  XtS9I Sh  v•N $  N¶! [         a    Ub  U" S5      I Sh  v•N    e f = f N¾ N+! [        [        4 a%  n	U R                  UU	UUS9I Sh  v•N  s Sn	A	$ Sn	A	ff = f7f)uÁ	  Handle a tool call by validating the arguments, calling the tool, and handling retries.

This is a convenience method that combines validate_tool_call() and execute_tool_call().

If the tool or its `args_validator` raises
[`ApprovalRequired`][pydantic_ai.exceptions.ApprovalRequired] or
[`CallDeferred`][pydantic_ai.exceptions.CallDeferred], the capability handler
(if any) is invoked to resolve it inline; otherwise the exception propagates.

Args:
    call: The tool call part to handle.
    approved: Whether the tool call has been approved.
    metadata: Additional metadata from DeferredToolResults.metadata.
    wrap_validation_errors: If True (default), validation failures surface as
        `ToolRetryError` (after counting against the retry budget) or
        `ToolFailedError` (without consuming the retry budget). If False, the
        raw `ValidationError` / `ModelRetry` / `ToolFailed` propagates and
        retry-budget state is left untouched â€” useful for nested callers (e.g.
        sandboxed tool dispatch) where the call shouldn't consume the agent's
        retry budget and the raw exception is what the caller wants to surface.
    on_inline_deferred: Internal callback invoked when a capability resolves a deferred call inline.
    on_validate: Internal callback invoked with the argument-validation outcome before execution.

Returns:
    The tool's return value on success â€” possibly a [`ToolReturn`][pydantic_ai.messages.ToolReturn]
    wrapper if the tool or handler supplied one.

    A [`ToolDenied`][pydantic_ai.tools.ToolDenied] instance if a
    [`HandleDeferredToolCalls`][pydantic_ai.capabilities.HandleDeferredToolCalls]
    handler denied the call. **Callers must `isinstance`-check the result**
    before treating it as a successful tool return â€” `ToolDenied` is *not* a
    valid tool result and the message string alone is indistinguishable from
    a real return value. Surfacing the denial (e.g. recording
    `ToolReturnPart(outcome='denied')` in message history, or raising inside
    a sandbox) is the caller's responsibility.

Raises:
    ToolRetryError: The handler requested a retry, or the (re-)executed tool
        raised `ModelRetry`. Only when `wrap_validation_errors=True`.
    ValidationError / ModelRetry: When `wrap_validation_errors=False` and the
        arguments fail validation or a hook raises `ModelRetry`.
    CallDeferred / ApprovalRequired: No handler resolved the call, or the
        approved tool re-raised a deferral.
r  NFrG  rê   ©rë   rN  )r  ÚBaseExceptionr@   rD   r<   r”   Údeferrä   r   r   r#  Ú_resolve_single_deferred)
rV   r:   rµ   r¶   rë   rN  rO  rÖ   Údeferred_toolÚexcs
             rN   Úhandle_callÚToolManager.handle_call5  sC  é € ðl	Ø"×5Ñ5ØØ!Ø!Ø'=ð	 6ð ÷ ˆIð Ñ"Ù˜i×2Ñ2Ó3×3Ð3ð	æØ×(×(Ø×&Ñ&Ñ.Ø&/§n¡nÐ4�]ÑAØ!×*Ñ*×0×0ð
 )6×(>Ñ(>×(CÑ(CÀzÓ(Q”l“nÐiÔWgÓWiÐiØ×/Ñ/°	Ð/Ði×iÐiñMøô ó 	ð Ñ&Ù! %Ó(×(Ñ(Øð	úñ 4ñ0 jøÜÔ.Ð/ó 	Ø×6Ñ6ØØØ'=Ø#5ð	 7ð ÷ ð õ ûð	üs�   ‚D1„C ™CšC žD1¶C5·D1¼BC9 ÃC7ÃC9 ÃD1ÃC ÃC2Ã*C-Ã+C2Ã2D1Ã7C9 Ã9D.Ä	D)ÄD!ÄD)Ä#D.Ä$D1Ä)D.Ä.D1c              ƒ  ó¼   #   • U R                   b  U R                  c  gU R                   R                  U R                  US9I Sh  v•N nUb  [        X5      $ S$  N7f)a  Invoke the capability handler to resolve deferred tool calls.

Args:
    requests: The deferred tool requests to resolve.

Returns:
    `DeferredToolResults` with results for some or all calls, or `None` if
    no handler is available or the handler declined to handle the requests.
N)Úrequests)ro   r>   Úhandle_deferred_tool_callsr   )rV   rZ  Úresultss      rN   Úresolve_deferred_tool_callsÚ'ToolManager.resolve_deferred_tool_calls›  s_   é € ð ×ÑÑ'¨4¯8©8Ñ+;ØØ×,Ñ,×GÑGÈÏÉÐ[cÐGÐd×dˆØ=DÑ=PÔ& xÓ9ÐZÐVZÐZñ eùs   ‚AAÁAÁArQ  c             ƒ  óÎ  #   • [        [        U[        5      (       a  U/O/ [        U[        5      (       a  U/O/ UR                  (       a  UR
                  UR                  0O0 S9nU R                  U5      I Sh  v•N nUc  UeUR                  5       R                  UR
                  5      nUc  UeUb  U" XV5      I Sh  v•N   [        U[        5      (       a  U$ [        U[        5      (       a%  U(       d  UeU R                  UR                  X5      e[        U[        5      (       ax  UnUR                  b  [        XR                  S9nUR                  R                  UR
                  5      n	U R!                  USU	US9I Sh  v•N n
U R#                  X£S9I Sh  v•N $ [        U[$        5      (       a=  ['        [(        R*                  " UR,                  UR                  UR
                  S95      e[        U[(        R*                  5      (       a-  UR                  Ul        UR
                  Ul        ['        U5      eUR.                  UR
                     $  GNà GN� NØ NÃ7f)u  Resolve a single deferred tool call inline using the capability handler.

Dispatches the handler's result for `call` on the same set of
[`DeferredToolResult`][pydantic_ai.tools.DeferredToolResult] variants as the
batch path in `_agent_graph._call_tool`, but returns a raw tool-like value
(what the tool "would have returned") rather than a message-history part.

NOTE: keep the dispatch branches here in sync with
[`_call_tool`][pydantic_ai._agent_graph._call_tool] â€” both paths must accept the
full [`DeferredToolResult`][pydantic_ai.tools.DeferredToolResult] surface.

`wrap_validation_errors` is forwarded to the post-approval re-validation and
re-execution so callers passing `False` (e.g. sandboxed dispatch) keep the
same raw-error contract through deferred-tool resolution. Handler-constructed
retry signals (`ModelRetry` / `RetryPromptPart` returned by the handler) still
surface as `ToolRetryError` regardless â€” those are handler outputs, not
exceptions raised by validation or the tool body.

Returns:
    For approved calls, the raw tool return (possibly a `ToolReturn` wrapper).
    For external-call results, the value the handler supplied verbatim (plain
    value or `ToolReturn`).
    For denied calls, the [`ToolDenied`][pydantic_ai.tools.ToolDenied] instance
    from the handler â€” callers must `isinstance`-check before treating the
    return value as a successful tool result.

Raises:
    ToolRetryError: Handler requested a retry via `ModelRetry` or `RetryPromptPart`,
        or the approved tool re-raised `ModelRetry` (only when
        `wrap_validation_errors=True`).
    ToolFailedError: Handler reported a failure via `ToolFailed`, or the approved
        tool raised `ToolFailed` (only when `wrap_validation_errors=True`).
    ValidationError / ModelRetry / ToolFailed: When `wrap_validation_errors=False` and the
        approved tool's re-validation fails or its body raises `ModelRetry` or `ToolFailed`.
    CallDeferred / ApprovalRequired: Handler couldn't resolve the call, or the
        approved tool re-raised a deferral.
)Ú	approvalsÚcallsr¶   N)rÃ   Tr  rê   )r¯   r‹   r§   )r(   rÅ   r   r   r¶   r§   r]  Úto_tool_call_resultsr†   r,   r    r³   r‹   r*   Úoverride_argsr   r  r#  r   r"   r±   r%   rW   ra  )rV   r:   rV  rë   rN  rZ  Údeferred_resultsÚtool_call_resultÚvalidate_callÚcall_metadatarÖ   s              rN   rT  Ú$ToolManager._resolve_single_deferred­  s4  é € ôZ (Ü *¨3Ô0@× AÑ A�t‘fÀrÜ& s¬L×9Ñ9�4‘&¸rØ:=¿,¿,�d×'Ñ'¨¯©Ñ6ÈBñ
ˆð
 "&×!AÑ!AÀ(Ó!K×KÐØÑ#ØˆIð ,×@Ñ@ÓB×FÑFÀt×GXÑGXÓYÐØÑ#ØˆIàÑ)Ù$ XÓ@×@Ð@äÐ&¬
×3Ñ3ð $Ð#ÜÐ&¬
×3Ñ3Þ)Ø&Ð&Ø×,Ñ,¨T¯^©^¸TÓTÐTÜÐ&¬×5Ñ5Ø ˆMØ×-Ñ-Ñ9Ü '¨×3QÑ3QÑ R�Ø,×5Ñ5×9Ñ9¸$×:KÑ:KÓLˆMØ"×5Ñ5ØØØ&Ø'=ð	 6ð ÷ ˆIð ×/Ñ/°	Ð/Ði×iÐiÜÐ&¬
×3Ñ3Ü Ü×)Ò)Ø,×4Ñ4Ø"Ÿn™nØ!%×!2Ñ!2ñóð ô Ð&¬	×(AÑ(A×BÑBØ)-¯©ÐÔ&Ø,0×,=Ñ,=ÐÔ)Ü Ð!1Ó2Ð2ð  ×%Ñ% d×&7Ñ&7Ñ8Ð8òc Lò Añ ñ jùsK   ‚A9I%Á;IÁ<AI%ÃIÃCI%ÆI!Æ	I%ÆI#Æ B<I%ÉI%É!I%É#I%rE   )r1   )r|   ÚParallelExecutionModerã   zGenerator[None])r>   r=   rã   zToolManager[AgentDepsT])rã   zlist[ToolDefinition])rã   ri  )r:   r&   rã   r?   )rŸ   rZ   rã   zToolDefinition | None)rŸ   rZ   r£   ru   ri   rö   rã   ÚNone)rŸ   rZ   r:   r&   ri   zValidationError | ModelRetryrã   r"   )rŸ   rZ   r:   r&   ri   r    rã   r!   )r:   r&   r<   úToolsetTool[AgentDepsT]r¼   r?   rµ   r?   r¶   r   rã   r=   )r:   r&   r<   rk  r>   r=   r¼   r?   r¿   zstr | dict[str, Any] | Nonerã   rd   )
r:   r&   r<   rk  r>   r=   r¼   r?   rã   rd   )rÖ   úValidatedToolCall[AgentDepsT]rï   r/   rë   r?   rã   r   )r:   r&   rã   z#tuple[str, ToolsetTool[AgentDepsT]])r”   r+   rã   z
str | None)
r:   r&   r<   r;   r>   r=   rB   rA   rã   rl  )rŸ   rZ   r:   r&   r<   r;   r>   r=   ri   z-ToolRetryError | ValidationError | ModelRetryrã   rl  )
r:   r&   rµ   r?   r¶   r   rë   r?   rã   rl  )rÖ   rl  rë   r?   rã   r   )
r:   r&   r3  úOutputSchema[Any]r¼   r?   rë   r?   rã   rl  )rÖ   rl  r3  rm  rë   r?   rã   r   )
r:   r&   r3  rm  r¼   r?   rë   r?   rã   r   )r:   r&   rµ   r?   r¶   r   rë   r?   rN  ú"InlineDeferredResultHandler | NonerO  zToolValidationHandler | Nonerã   ú"ToolDenied | ToolReturn[Any] | Any)rZ  r(   rã   zDeferredToolResults | None)
r:   r&   rV  rc   rë   r?   rN  rn  rã   ro  )1rF   rG   rH   rI   rJ   rK   ro   r>   rp   r
   ry   rZ   rr   rs   rt   rv   rw   Úclassmethodr   r4   r‡   Úpropertyr•   r˜   rœ   r›   r¤   Ústaticmethodr«   r³   r½   rÒ   rè   rû   r  r  r  r  r  r#  r6  rA  rD  r"  rð   rW  r]  rT  rL   rE   rM   rN   rl   rl   �   sè  ‡ ñ Kà(Ó(Ø@Ø=A€OÐ:ÓAØ2Ø)-€CÐ	&Ó-Ø8Ø7;€EÐ4Ó;ðá"°3°s±8Ñ<€L�(Ó<Ø6Ù %°c¸#±hÑ ?€O�XÓ?Ø9Ù%*¸3¸s¹8Ñ%DÐ˜(ÓDðð  !Ð˜Ó Ø1Ø59ÐÐ2Ó9ðð& Øõ:ó ó ð:ô8ðt ó?ó ð?ô6ô<ô;ô	ð ó!ó ð!ð
 ó"ó ð"ð  Øñ
àð
ð &ð
ð
 ð
ð ð
ð ð
ð 
 õ
ðD 6:ñ*àð*ð &ð*ð $ð	*ð ð*ð 3ð*ð 
õ*ðXNàðNð &ðNð $ð	Nð ðNð 
ôNðj (,ñ@à0ð@ð ð	@ð
 !%ð@ð 
õ@ôDô.
ðB
àð
ð -ð
ð $ð	
ð
 .ð
ð 
'ô
ð"&
àð&
ð ð&
ð -ð	&
ð
 $ð&
ð =ð&
ð 
'ô&
ðX ØØ'+ñSàðSð ð	Sð
 ðSð !%ðSð 
'õSðr (,ñ	(
à0ð(
ð !%ð	(
ð
 
õ(
ðb $Ø'+ñEKàðEKð "ð	EKð
 ðEKð !%ðEKð 
'õEKðX (,ñbà0ðbð "ð	bð
 !%ðbð 
õbðR $Ø'+ñ
àð
ð "ð	
ð
 ð
ð !%ð
ð 
õ
ðD (,ñ6à0ð6ð ð	6ð
 !%ð6ð 
õ6ðz (,ñ!à0ð!ð ð	!ð
 !%ð!ð 
õ!ðN ØØ'+ØAEØ48ñdàðdð ð	dð
 ðdð !%ðdð ?ðdð 2ðdð 
,õdðL[à&ð[ð 
$ô[ð. (,ØAEñc9àðc9ð -ðc9ð
 !%ðc9ð ?ðc9ð 
,÷c9ð c9rM   rl   )rh   rZ   ri   rc   rã   r$   )KÚ
__future__r   rÊ   Úcollections.abcr   r   r   Ú
contextlibr   Úcontextvarsr   Údataclassesr	   r
   r   Útypingr   r   r   r   Úpydanticr   Ú r   r   r±   Ú	_deferredr   Ú_outputr   r   r   r   Ú_run_contextr   r   Ú
exceptionsr   r   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   rp   r(   r)   r*   r+   r,   Útoolsets.abstractr-   r.   rï   r/   Úcapabilities.abstractr0   ri  r6   rK   ÚInlineDeferredResultHandlerr?   ÚToolValidationHandlerr8   rP   rö   r_   rj   rl   rE   rM   rN   Ú<module>rƒ     s1  ðÞ "ã ß :Ñ :Ý %Ý "ß 1Ñ 1ß 7Ó 7å $ç 7Ý .÷ó ÷ 1÷÷ ÷ ÷ @Ñ ?ß fÕ fß ;Ý æÝ9àÐ SÑTÐ ðjñ GQØ zñGÐ  Ð"Có ð 'Ð(<Ð>QÐ'RÐT]Ð^bÑTcÐ'cÑdÐ Ø Xà  $ ¨°4©Ð!8Ñ9Ð Ø Oð ô&˜ 
Ñ+ó &ó ð&ôR�zô ô ˜)ô ôð ô@9�'˜*Ñ%ó @9ó ñ@9rM   