ó
    ±"³jM  ã                  óT  • % 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  S SKJr  S SKJrJr  S S	KJr  S
SKJrJr  S
SKJr  \\\   /\\   S-  \\\   S-     -  4   rS\S'    \ " S S\\   5      5       r\ " S S\\   5      5       r      SS jr    SS jrg)é    )ÚannotationsN)Ú	AwaitableÚCallableÚSequence)Ú	dataclass)Ú	TypeAlias)Ú
AgentDepsTÚ
RunContext)Ú	UserError)ÚAbstractToolsetÚAgentToolset)ÚDynamicToolseté   )ÚAbstractCapabilityÚCapabilityOrdering)ÚWrapperCapabilityr   ÚCapabilityFuncc                  óX   • \ rS rSr% SrS\S'    SS jrSS jrSS jrSS jr	SS	 jr
S
rg)ÚDynamicCapabilityé   a(  A capability that builds another capability dynamically using a function that takes the run context.

The factory is called once per agent run from
[`for_run`][pydantic_ai.capabilities.AbstractCapability.for_run]. The returned
capability's instructions, model settings, native tools, and hooks flow through
normally; its toolset is exposed through a stable dynamic toolset contributed at
agent construction time, which reuses the run's resolved capability instance.

Under durable execution, a stable `id` is required on `DynamicCapability`: it
names the durable units (activities/steps/tasks) that list and call the
contributed tools. The factory itself runs in workflow/flow code, which durable
engines re-execute on replay, recovery, or flow retry, so it must be
deterministic given the run's dependencies; leave I/O to the toolset it
returns, whose use is checkpointed inside the durable units. In-process
engines (DBOS, Prefect) reuse the run's resolved capability inside those
units; Temporal re-runs the factory inside its activities (the activity
boundary can't carry the resolved instance).

Pass a [`CapabilityFunc`][pydantic_ai.capabilities.CapabilityFunc] directly
to `Agent(capabilities=[...])` or `agent.run(capabilities=[...])` and it
will be wrapped in a `DynamicCapability` automatically.

`defer_loading` on the wrapper itself is rejected because `for_run` replaces
the wrapper with the factory's return value. Set it on the returned
capability instead.
For history replay, set a stable `id` on the capability the factory returns
rather than on the wrapper.
zCapabilityFunc[AgentDepsT]Úcapability_funcc                ó€   • U R                   SL a  [        S5      e[        U R                  SU R                  S9U l        g )NTuq   `defer_loading` is not supported on `DynamicCapability` â€” set it on the capability the factory returns instead.F)Útoolset_funcÚper_run_stepÚid)Údefer_loadingr   r   Ú_resolve_toolsetr   Ú_toolset©Úselfs    Ú^/home/mande/repo/quber/.venv/lib/python3.13/site-packages/pydantic_ai/capabilities/_dynamic.pyÚ__post_init__ÚDynamicCapability.__post_init__9   sE   € ð ×Ñ Ò%ÜðHóð ô '°D×4IÑ4IÐX]Ðbf×biÑbiÑjˆ�ó    c                ó   • U R                   $ ©N©r   r   s    r!   Úget_toolsetÚDynamicCapability.get_toolsetE   s   € Ø�}‰}Ðr$   c              ƒ  óÎ  #   • UR                   R                  S5      =(       d    0 nUR                  5        He  n[        U[        5      (       aG  UR
                  U R                  L a.  [        UR                  R                  5       U5      I S h  v•N s  $ X0L d  Me    g    U R                  U5      I S h  v•N nUc  g [        UR                  5       U5      I S h  v•N $  NO N, N7f)NÚcapabilities)Ú__dict__ÚgetÚvaluesÚ
isinstanceÚResolvedDynamicCapabilityÚdynamic_toolsetr   Ú_evaluate_agent_toolsetÚwrappedr(   Ú_resolve_capability)r    ÚctxÚregistryÚ
capabilitys       r!   r   Ú"DynamicCapability._resolve_toolsetH   sÆ   é € ð ?B¿l¹l×>NÑ>NÈ~Ó>^×>dÐbdˆØ"Ÿ/™/Ö+ˆJÜ˜*Ô&?×@Ñ@ÀZ×E_ÑE_Ðcg×cpÑcpÒEpÜ4°Z×5GÑ5G×5SÑ5SÓ5UÐWZÓ[×[Ò[ØÔ!áñ ,ð  ×3Ñ3°CÓ8×8ˆ
ØÑØÜ,¨Z×-CÑ-CÓ-EÀsÓK×KÐKñ \ñ 9ñ Lùs<   ‚BC%ÂCÂC%ÂC%Â4C!Â5%C%ÃC#ÃC%Ã!C%Ã#C%c              ƒ  ó  #   • U R                  U5      n[        R                  " U5      (       a
  UI S h  v•N nUc  g UR                  c   S5       eUR	                  UR                  5      nUR                  U5      I S h  v•N $  NP N7f)Nz,CapabilityFunc requires an agent run context)r   ÚinspectÚisawaitableÚagentÚ	for_agentÚfor_run©r    r5   r7   s      r!   r4   Ú%DynamicCapability._resolve_capability^   s   é € Ø×)Ñ)¨#Ó.ˆ
Ü×Ò˜z×*Ñ*Ø)×)ˆJØÑØØ�y‰yÑ$ÐTÐ&TÓTÐ$Ø×)Ñ)¨#¯)©)Ó4ˆ
Ø×'Ñ'¨Ó,×,Ð,ñ *ñ
 -ùs"   ‚2B	´BµAB	Â BÂB	ÂB	c              ƒ  óx   #   • U R                  U5      I S h  v•N nUc  U $ [        X R                  5       S9$  N 7f)N)r3   r1   )r4   r0   r(   r?   s      r!   r>   ÚDynamicCapability.for_runh   s<   é € Ø×3Ñ3°CÓ8×8ˆ
ØÑØˆKÜ(°×M]ÑM]ÓM_Ñ`Ð`ñ 9ùs   ‚:—8˜!:r'   N)ÚreturnÚNone©rC   úDynamicToolset[AgentDepsT])r5   úRunContext[AgentDepsT]rC   ú"AbstractToolset[AgentDepsT] | None)r5   rG   rC   z%AbstractCapability[AgentDepsT] | None)r5   rG   rC   zAbstractCapability[AgentDepsT])Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__Ú__annotations__r"   r(   r   r4   r>   Ú__static_attributes__© r$   r!   r   r      s.   ‡ ñð: 0Ó/ØUô
kôôLô,-÷ar$   r   c                  ó8   • \ rS rSr% SrS\S'   S	S jrS
S jrSrg)r0   éo   uf  The per-run replacement for a [`DynamicCapability`][pydantic_ai.capabilities.DynamicCapability].

Delegates to the factory's resolved capability, except that the resolved capability's own
toolset contribution is replaced by the `DynamicCapability`'s stable dynamic toolset â€” the
one registered with any durable execution engine at agent construction time.
rF   r1   c                ó   • U R                   $ r&   )r1   r   s    r!   r(   Ú%ResolvedDynamicCapability.get_toolsetz   s   € Ø×#Ñ#Ð#r$   c                ó6   • U R                   R                  5       $ r&   )r3   Úget_orderingr   s    r!   rV   Ú&ResolvedDynamicCapability.get_ordering}   s   € ð �|‰|×(Ñ(Ó*Ð*r$   rP   NrE   )rC   zCapabilityOrdering | None)	rI   rJ   rK   rL   rM   rN   r(   rV   rO   rP   r$   r!   r0   r0   o   s   ‡ ñð 0Ó/ô$÷+r$   r0   c              ƒ  ó    #   • U b  [        U [        5      (       a  U $ U " U5      n[        R                  " U5      (       a
  UI Sh  v•N nU$  N7f)zhNormalize a capability's toolset contribution: evaluate the toolset-*function* arm with the run context.N)r/   r   r:   r;   )Útoolsetr5   Úresolveds      r!   r2   r2   ƒ   sJ   é € ð �œ* W¬o×>Ñ>àˆÙcjÐknÓco€HÜ×Ò˜8×$Ñ$Ø!—>ˆØ€Oñ "ùs   ‚AAÁAÁAc                ó„   • U (       d  / $ U  Vs/ s H%  n[        U[        5      (       a  UO
[        U5      PM'     sn$ s  snf )zfWrap any [`CapabilityFunc`][pydantic_ai.capabilities.CapabilityFunc] entries in a `DynamicCapability`.)r/   r   r   )r+   Úcaps     r!   Úwrap_capability_funcsr]   �   s?   € ö Øˆ	Ù^jÓkÒ^jÐWZ”:˜cÔ#5×6Ñ6‰CÔ<MÈcÓ<RÒRÑ^jÑkÐkùÒks   Ž,=)rY   zAgentToolset[AgentDepsT] | Noner5   rG   rC   rH   )r+   zLSequence[AbstractCapability[AgentDepsT] | CapabilityFunc[AgentDepsT]] | NonerC   z$list[AbstractCapability[AgentDepsT]]) Ú
__future__r   r:   Úcollections.abcr   r   r   Údataclassesr   Útypingr   Úpydantic_ai._run_contextr	   r
   Úpydantic_ai.exceptionsr   Úpydantic_ai.toolsetsr   r   Úpydantic_ai.toolsets._dynamicr   Úabstractr   r   Úwrapperr   r   rN   r   r0   r2   r]   rP   r$   r!   Ú<module>rh      sò   ðÞ "ã ß 9Ñ 9Ý !Ý ç ;Ý ,ß >Ý 8ç <Ý &à$Ø�
ÑÐØ�zÑ" TÑ)¨IÐ6HÈÑ6TÐW[Ñ6[Ñ,\Ñ\ð^ñ€�	ó ð Pð ôTaÐ*¨:Ñ6ó Taó ðTaðn ô+Ð 1°*Ñ =ó +ó ð+ð&
Ø,ð
Ø3Ið
à'ô
ðlØ^ðlà)õlr$   