ó
    ±"³jøF  ã                  ó¨  • S SK Jr  S SKJrJr  S SKJrJrJr  S SK	J
r
  S SKJr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Jr  SSKJr  SSKJrJr  SSKJ r J!r!  SSK"J#r#J$r$  \(       a0  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.  SSK/J0r0  SSK1J2r2  SSK3J4r4  Sr5 Sr6  " S S\5      r7\
" SS9 " S S\\   5      5       r8 " S  S!\\\   5      r9g")#é    )Úannotations)ÚABCÚabstractmethod)Ú	AwaitableÚCallableÚSequence)Ú	dataclass)ÚTYPE_CHECKINGÚAnyÚGenericÚLiteralÚProtocol)ÚSchemaValidator)ÚSelfé   )Ú#normalize_toolset_instruction_parts)Ú
AgentDepsTÚ
RunContext)Úgather)ÚInstructionPartÚToolsetInstructionSource)ÚToolDefinitionÚToolsPrepareFuncé   )ÚInstructionContributionÚmake_contribution©ÚApprovalRequiredToolset©ÚDeferredLoadingToolset©ÚFilteredToolset©ÚIncludeReturnSchemasToolset©ÚPrefixedToolset©ÚPreparedToolset©ÚRenamedToolset©ÚSetMetadataToolsetz<agent>z<output>c                  óX   • \ rS rSrSrSS.       S	S jjrSS.       S
S jjrSrg)ÚSchemaValidatorProté$   zsProtocol for a Pydantic Core `SchemaValidator` or `PluggableSchemaValidator` (which is private but API-compatible).F)Úallow_partialc               ó   • g ©N© ©ÚselfÚinputr0   Úkwargss       ÚZ/home/mande/repo/quber/.venv/lib/python3.13/site-packages/pydantic_ai/toolsets/abstract.pyÚvalidate_jsonÚ!SchemaValidatorProt.validate_json'   s   € ð ó    c               ó   • g r2   r3   r4   s       r8   Úvalidate_pythonÚ#SchemaValidatorProt.validate_python/   s   € àr;   r3   N)r6   zstr | bytes | bytearrayr0   ú/bool | Literal['off', 'on', 'trailing-strings']r7   r   Úreturnr   )r6   r   r0   r?   r7   r   r@   r   )Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r9   r=   Ú__static_attributes__r3   r;   r8   r.   r.   $   si   † Ù}ð JOñ	à&ðð Gð	ð
 ðð 
õð _dñØðØ,[ðØorðà	÷ð r;   r.   T)Úkw_onlyc                  óX   • \ rS rSr% SrS\S'    S\S'    S\S'    S	\S
'    SrS\S'   Srg)ÚToolsetToolé4   a&  Definition of a tool available on a toolset.

This is a wrapper around a plain tool definition that includes information about:

- the toolset that provided it, for use in error messages
- the maximum number of retries to attempt if the tool call fails
- the validator for the tool's arguments
úAbstractToolset[AgentDepsT]Útoolsetr   Útool_defÚintÚmax_retriesz%SchemaValidator | SchemaValidatorProtÚargs_validatorNzCallable[..., Any] | NoneÚargs_validator_funcr3   )rA   rB   rC   rD   rE   Ú__annotations__rQ   rF   r3   r;   r8   rI   rI   4   sB   ‡ ñð )Ó(ØIØÓØ]ØÓØJØ9Ó9ðð 6:ÐÐ2Ó9òr;   rI   c                  ó¼  • \ rS rSrSr\\S!S j5       5       r\S"S j5       r\S"S j5       r	S#S jr
S#S jrS$S jrS%S	 jr    S&S
 jr    S'S jr    S'S jrS(S jrS)S jrS*S jrS+S jr\S,S j5       r\          S-S j5       r      S.S jrS/S jr    S0S jr    S1S jrS2S jrS3S jrS4S jrS 4   S5S jjrS6S7S jjrS8S jr S9S jr!S r"g):ÚAbstractToolsetéV   zðA toolset is a collection of tools that can be used by an agent.

It is responsible for:

- Listing the tools it contains
- Validating the arguments of the tools
- Calling the tools

See [toolset docs](../toolsets.md) for more information.
c                ó   • [        5       e)aÂ  An ID for the toolset that is unique among all toolsets registered with the same agent.

If you're implementing a concrete implementation that users can instantiate more than once, you should let them optionally pass a custom ID to the constructor and return that here.

A toolset needs to have an ID in order to be used in a durable execution environment like Temporal, in which case the ID will be used to identify the toolset's activities within the workflow.

IDs wrapped in angle brackets (`'<agent>'` for an agent's own function toolset, `'<output>'` for
its output tools) name a role the framework fills on the user's behalf rather than a registered
toolset. Don't return one from your own toolset.
©ÚNotImplementedError©r5   s    r8   ÚidÚAbstractToolset.idb   s   € ô "Ó#Ð#r;   c                óz   • U R                   R                  nU R                  (       a  USU R                  < 3-  nU$ )z2The name of the toolset for use in error messages.Ú )Ú	__class__rA   rZ   )r5   Úlabels     r8   r_   ÚAbstractToolset.labelq   s3   € ð —‘×'Ñ'ˆØ�7�7Ø�q˜Ÿ™™�_Ñ$ˆEØˆr;   c                ó   • g)zUA hint for how to avoid name conflicts with other toolsets for use in error messages.zSRename the tool or wrap the toolset in a `PrefixedToolset` to avoid name conflicts.r3   rY   s    r8   Útool_name_conflict_hintÚ'AbstractToolset.tool_name_conflict_hinty   s   € ð er;   c              ƒ  ó   #   • U $ 7f)zÌReturn the toolset to use for this agent run.

Called once per run, before `__aenter__`. Override this to return a fresh instance
for per-run state isolation. Default: return `self` (shared across runs).
r3   ©r5   Úctxs     r8   Úfor_runÚAbstractToolset.for_run~   s   é € ð ˆùó   ‚c              ƒ  ó   #   • U $ 7f)aW  Return the toolset to use for this run step.

Called at the start of each run step. Override this to return a modified
instance for per-step state transitions. If returning a new instance,
you are responsible for managing any lifecycle transitions (exiting old
inner toolsets, entering new ones). Default: return `self` (no per-step changes).
r3   re   s     r8   Úfor_run_stepÚAbstractToolset.for_run_step†   s   é € ð ˆùri   c              ƒ  ó   #   • U $ 7f)zkEnter the toolset context.

This is where you can set up network connections in a concrete implementation.
r3   rY   s    r8   Ú
__aenter__ÚAbstractToolset.__aenter__�   s   é € ð
 ˆùri   c              ‡  ó   #   • g7f)zmExit the toolset context.

This is where you can tear down network connections in a concrete implementation.
Nr3   )r5   Úargss     r8   Ú	__aexit__ÚAbstractToolset.__aexit__—   s
   é € ð
 ùó   ‚c              ƒ  ó   #   • g7f)ap  Return instructions for how to use this toolset's tools.

Override this method to provide instructions that help the agent understand
how to use the tools in this toolset effectively.

Simple implementations can return a plain `str`; advanced implementations can return
[`InstructionPart`][pydantic_ai.messages.InstructionPart] objects to indicate whether
each instruction part is static or dynamic for caching purposes.

Args:
    ctx: The run context for this agent run.

Returns:
    Instruction string, `InstructionPart`, list of either, or `None`.
    Plain `str` values are treated as dynamic instructions by default.
Nr3   re   s     r8   Úget_instructionsÚ AbstractToolset.get_instructionsž   s
   é € ð& ùrt   c              ƒ  óæ  #   • U R                  5       (       d  U R                  U5      I Sh  v•N $ U R                  U5      I Sh  v•N nU R                  5       n/ n[	        U5       H€  nUR
                  bN  [        UR
                  R                  [        5      (       a%  UR                  UR
                  R                  5      OSnUR                  [        Ub  UOU U5      5        M‚     U$  NÀ N©7f)a  Collect contributions once, preserving the toolset that authored every relayed part.

A toolset that only passes its children along is walked; anything that speaks for itself is
asked once. That covers a leaf and a container whose subclass took `get_instructions` over
with the same path, because the difference between them is only what they own: a returned
key owned below is relayed unchanged and stays attributed to its owner, and everything else
is the caller's own text, resolved against the caller's own key.
N)Ú_authors_own_instructionsÚ(_collect_child_instruction_contributionsrv   Ú_instruction_sources_by_keyr   rZ   Ú
isinstanceÚsourcer   ÚgetÚappendr   )r5   rf   ÚresultÚsources_by_keyÚcontributionsÚpartÚowners          r8   Ú"_collect_instruction_contributionsÚ2AbstractToolset._collect_instruction_contributions³   sÓ   é € ð ×-Ñ-×/Ñ/Ø×FÑFÀsÓK×KÐKà×,Ñ,¨SÓ1×1ˆØ×9Ñ9Ó;ˆØCEˆÜ7¸Ö?ˆDð —7‘7Ñ&¬:°d·g±g·n±nÔF^×+_Ñ+_ð ×"Ñ" 4§7¡7§>¡>Ô2àð ð
 × Ñ Ô!2¸EÑ<M±5ÐSWÐY]Ó!^Ö_ñ @ð Ðñ Lá1ùs"   ‚*C1¬C-­C1ÁC/ÁB(C1Ã/C1c              ƒ  ó¦   ^#   • [        U4S jU R                  5        5       6 I Sh  v•N nU VVs/ s H  o3  H  oDPM     M     snn$  N!s  snnf 7f)zSGather child contributions without re-entering a container's public override check.c              3  óD   >#   • U  H  oR                  T5      v •  M     g 7fr2   )r…   )Ú.0Úchildrf   s     €r8   Ú	<genexpr>ÚKAbstractToolset._collect_child_instruction_contributions.<locals>.<genexpr>Õ   s   øé € ÐfÒIeÀ×6Ñ6°s×;Ð;ÒIeùs   ƒ N)r   Ú_instruction_children)r5   rf   Úchild_contributionsr‚   Úcontributions    `   r8   rz   Ú8AbstractToolset._collect_child_instruction_contributionsÐ   sX   øé € ô %+ÜfÈ×IcÑIcÔIeÓfð%
÷ 
Ðñ 3FÔhÒ2E ÓZgÈ,’ÑZg‘Ñ2EÒhÐhñ
ùó iùs    ƒ$A§A	¨	A±AÁAÁAc                ó   • g)zCThe toolsets whose instruction contributions this one passes along.r3   r3   rY   s    r8   r�   Ú%AbstractToolset._instruction_childrenÙ   s   € àr;   c                ó   • g)aa  Whether `get_instructions` speaks for this toolset rather than aggregating its children.

True here because a toolset with nothing below it can only be speaking for itself. A
container overrides this to answer for the case that actually varies: whether a subclass has
taken the method over, or it is still the inherited implementation that just relays.
Tr3   rY   s    r8   ry   Ú)AbstractToolset._authors_own_instructionsÝ   s   € ð r;   c                óh   • U R                   b  SU R                   ;   a  g[        U R                   5      $ )zURead this toolset's source without validating an id that contributes no instructions.NÚ:)rZ   r   rY   s    r8   Ú_instruction_sourceÚ#AbstractToolset._instruction_sourceæ   s'   € à�7‰7‰?˜c T§W¡W›nØÜ'¨¯©Ó0Ð0r;   c                óø   • 0 nU R                  5        H;  nUR                  5       R                  5        H  u  p4UR                  X45        M     M=     U R	                  5       =n(       a  UR                  X@5        U$ )a]  Map every source key at or below this toolset to the toolset that owns it.

Children are inserted first and the container is inserted last without overwriting them, so
a child remains the owner when a malformed tree repeats its key at a container boundary.
The duplicate contribution check reports the ambiguity if both sources actually contribute.
)r�   r{   ÚitemsÚ
setdefaultr—   )r5   ÚsourcesrŠ   Ú	source_idr}   s        r8   r{   Ú+AbstractToolset._instruction_sources_by_keyì   su   € ð PRˆØ×/Ñ/Ö1ˆEØ%*×%FÑ%FÓ%H×%NÑ%NÖ%PÑ!�	Ø×"Ñ" 9Ö5ó &Qñ 2ð ×-Ñ-Ó/Ð/ˆ6Õ/Ø×Ñ˜vÔ,Øˆr;   c              ƒ  ó   #   • [        5       e7f)z-The tools that are available in this toolset.rW   re   s     r8   Ú	get_toolsÚAbstractToolset.get_toolsû   s   é € ô "Ó#Ð#ùó   ‚c              ƒ  ó   #   • [        5       e7f)a  Call a tool with the given arguments.

Args:
    name: The name of the tool to call.
    tool_args: The arguments to pass to the tool.
    ctx: The run context.
    tool: The tool definition returned by [`get_tools`][pydantic_ai.toolsets.AbstractToolset.get_tools] that was called.
rW   )r5   ÚnameÚ	tool_argsrf   Útools        r8   Ú	call_toolÚAbstractToolset.call_tool   s   é € ô "Ó#Ð#ùr¢   c              ƒ  óZ   #   • U R                  U5      I Sh  v•N UR                     $  N7f)uº  Return the tool to call for a tool definition this toolset already produced.

Used by [durable execution](../durable_execution/overview.md) to rebuild the tool inside a
durable unit from the definition a discovery unit already recorded, instead of listing the
toolset's tools a second time. The default lists them, which is always correct; a toolset
that can build the tool from the definition alone â€” like
[`MCPToolset`][pydantic_ai.mcp.MCPToolset], whose listing is a network round trip â€” should
override this to skip the listing.

Args:
    tool_def: The tool definition to build the tool from.
    ctx: The run context.

Raises:
    KeyError: If this toolset holds no tool under that name.
N)r    r¤   )r5   rM   rf   s      r8   Úget_tool_for_tool_defÚ%AbstractToolset.get_tool_for_tool_def  s%   é € ð& —n‘n SÓ)×)¨8¯=©=Ñ9Ð9Ñ)ùs   ‚+—)˜+c                ó   • U" U 5        g)zmRun a visitor function on all "leaf" toolsets (i.e. those that implement their own tool listing and calling).Nr3   ©r5   Úvisitors     r8   ÚapplyÚAbstractToolset.apply#  s	   € á��r;   c                ó   • U" U 5      $ )z¯Run a visitor function on all "leaf" toolsets (i.e. those that implement their own tool listing and calling) and replace them in the hierarchy with the result of the function.r3   r­   s     r8   Úvisit_and_replaceÚ!AbstractToolset.visit_and_replace'  s   € ñ �t‹}Ðr;   c                ó   • SSK Jn  U" X5      $ )zÐReturns a new toolset that filters this toolset's tools using a filter function that takes the agent context and the tool definition.

See [toolset docs](../toolsets.md#filtering-tools) for more information.
r   r!   )Úfilteredr"   )r5   Úfilter_funcr"   s      r8   rµ   ÚAbstractToolset.filtered-  s   € õ 	.á˜tÓ1Ð1r;   c                ó   • SSK Jn  U" X5      $ )z–Returns a new toolset that prefixes the names of this toolset's tools.

See [toolset docs](../toolsets.md#prefixing-tool-names) for more information.
r   r%   )Úprefixedr&   )r5   Úprefixr&   s      r8   r¹   ÚAbstractToolset.prefixed8  s   € õ
 	.á˜tÓ,Ð,r;   c                ó   • SSK Jn  U" X5      $ )zçReturns a new toolset that prepares this toolset's tools using a prepare function that takes the agent context and the original tool definitions.

See [toolset docs](../toolsets.md#preparing-tool-definitions) for more information.
r   r'   )Úpreparedr(   )r5   Úprepare_funcr(   s      r8   r½   ÚAbstractToolset.preparedA  s   € õ
 	.á˜tÓ2Ð2r;   c                ó   • SSK Jn  U" X5      $ )z¹Returns a new toolset that renames this toolset's tools using a dictionary mapping new names to original names.

See [toolset docs](../toolsets.md#renaming-tools) for more information.
r   r)   )Úrenamedr*   )r5   Úname_mapr*   s      r8   rÁ   ÚAbstractToolset.renamedJ  s   € õ
 	,á˜dÓ-Ð-r;   c                ó   • g)NTr3   )rf   rM   r¥   s      r8   Ú<lambda>ÚAbstractToolset.<lambda>V  s   € ¨Tr;   c                ó   • SSK Jn  U" X5      $ )z¨Returns a new toolset that requires (some) calls to tools it contains to be approved.

See [toolset docs](../toolsets.md#requiring-tool-approval) for more information.
r   r   )Úapproval_requiredr   )r5   Úapproval_required_funcr   s      r8   rÈ   Ú!AbstractToolset.approval_requiredS  s   € õ 	?á& tÓDÐDr;   Nc                ó:   • SSK Jn  U" Xb  [        U5      S9$ SS9$ )a‰  Returns a new toolset that marks tools for deferred loading, hiding them until revealed.

Tool search, `load_capability` and another tool's `ToolReturn.tools` all reveal.

See [toolset docs](../toolsets.md#deferred-loading) for more information.

Args:
    tool_names: Optional sequence of tool names to mark for deferred loading.
        If `None`, all tools are marked for deferred loading.
r   r   N)Ú
tool_names)Údeferred_loadingr    Ú	frozenset)r5   rÌ   r    s      r8   Údefer_loadingÚAbstractToolset.defer_loadinga  s%   € õ 	=á% dÑPf´yÀÓ7LÑqÐqÐlpÑqÐqr;   c                ó   • SSK Jn  U" U 5      $ )ar  Returns a new toolset that sets `include_return_schema=True` on all tools.

This causes the model to receive return type information for the tools
in this toolset. For models that natively support return schemas (e.g.
Google Gemini), the schema is passed as a structured field. For other
models, it is injected into the tool description as JSON text.

This is the toolset-level equivalent of the
[`IncludeToolReturnSchemas`][pydantic_ai.capabilities.IncludeToolReturnSchemas]
capability, which can be used to enable return schemas across all
toolsets or a subset matched by a
[`ToolSelector`][pydantic_ai.tools.ToolSelector].
r   r#   )Úinclude_return_schemasr$   )r5   r$   s     r8   rÒ   Ú&AbstractToolset.include_return_schemasp  s   € õ 	Há*¨4Ó0Ð0r;   c                ó   • SSK Jn  U" X5      $ )zDReturns a new toolset that merges the given metadata onto all tools.r   r+   )Úset_metadatar,   )r5   Úmetadatar,   s      r8   Úwith_metadataÚAbstractToolset.with_metadata‚  s   € å4á! $Ó1Ð1r;   r3   )r@   z
str | None)r@   Ústr)rf   úRunContext[AgentDepsT]r@   rK   )r@   r   )rq   r   r@   zbool | None)rf   rÚ   r@   z>str | InstructionPart | Sequence[str | InstructionPart] | None)rf   rÚ   r@   z)list[InstructionContribution[AgentDepsT]])r@   z%Sequence[AbstractToolset[AgentDepsT]])r@   Úbool)r@   zToolsetInstructionSource | None)r@   z;dict[ToolsetInstructionSource, AbstractToolset[AgentDepsT]])rf   rÚ   r@   z"dict[str, ToolsetTool[AgentDepsT]])
r¤   rÙ   r¥   zdict[str, Any]rf   rÚ   r¦   úToolsetTool[AgentDepsT]r@   r   )rM   r   rf   rÚ   r@   rÜ   )r®   z-Callable[[AbstractToolset[AgentDepsT]], None]r@   ÚNone)r®   zDCallable[[AbstractToolset[AgentDepsT]], AbstractToolset[AgentDepsT]]r@   rK   )r¶   zJCallable[[RunContext[AgentDepsT], ToolDefinition], bool | Awaitable[bool]]r@   zFilteredToolset[AgentDepsT])rº   rÙ   r@   zPrefixedToolset[AgentDepsT])r¾   zToolsPrepareFunc[AgentDepsT]r@   zPreparedToolset[AgentDepsT])rÂ   zdict[str, str]r@   zRenamedToolset[AgentDepsT])rÉ   zHCallable[[RunContext[AgentDepsT], ToolDefinition, dict[str, Any]], bool]r@   z#ApprovalRequiredToolset[AgentDepsT]r2   )rÌ   zSequence[str] | Noner@   z"DeferredLoadingToolset[AgentDepsT])r@   z'IncludeReturnSchemasToolset[AgentDepsT])rÖ   r   r@   zSetMetadataToolset[AgentDepsT])#rA   rB   rC   rD   rE   Úpropertyr   rZ   r_   rb   rg   rk   rn   rr   rv   r…   rz   r�   ry   r—   r{   r    r§   rª   r¯   r²   rµ   r¹   r½   rÁ   rÈ   rÏ   rÒ   r×   rF   r3   r;   r8   rT   rT   V   s‘  † ñ	ð Øó$ó ó ð$ð óó ðð óeó ðeôôôôðØ)ðà	Gôð*Ø)ðà	2ôð:iØ)ðià	2ôiôôô1ôð ó$ó ð$ð ð$Øð$Ø$2ð$Ø9Oð$ØWnð$à	ó$ó ð$ð:Ø&ð:Ø-Cð:à	 ô:ô*ðØ[ðà	$ôð	2Øeð	2à	$ô	2ô-ô3ô.ñ 2ðEà hðEð
 
-õEörô1÷$2r;   rT   N):Ú
__future__r   Úabcr   r   Úcollections.abcr   r   r   Údataclassesr	   Útypingr
   r   r   r   r   Úpydantic_corer   Útyping_extensionsr   Ú_instructionsr   Ú_run_contextr   r   Ú_utilsr   Úmessagesr   r   Útoolsr   r   Ú_instruction_collectionr   r   rÈ   r   rÍ   r    rµ   r"   rÒ   r$   r¹   r&   r½   r(   rÁ   r*   rÕ   r,   ÚAGENT_TOOLSET_IDÚOUTPUT_TOOLSET_IDr.   rI   rT   r3   r;   r8   Ú<module>rî      s¨   ðÝ "ç #ß 9Ñ 9Ý !ß AÕ Aå )Ý "å ?ß 1Ý ß @ß 4ß OæÝ:Ý8Ý)ÝCÝ)Ý)Ý'Ý0ð Ð Ø tàÐ Ø nô˜(ô ñ  �4Ñô�'˜*Ñ%ó ó ðôBp2�c˜7 :Ñ.õ p2r;   