ó
    ±"³j‘  ã                  ó:  • 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rS SK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  SSKJr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&J'r'J(r(J)r)  SSK*J+r+J,r,  \" SS9 " S S\,\   5      5       r- " S S\+\   5      r.g)é    )Úannotations)Ú	AwaitableÚCallableÚSequence)Ú	dataclassÚreplace)ÚAnyÚoverloadN)ÚGenerateJsonSchemaé   )Ú_utils)ÚAgentInstructionsÚnormalize_instructions)Ú
AgentDepsTÚ
RunContext)ÚSystemPromptRunner)Ú
ModelRetryÚ	UserError)ÚInstructionPart)ÚArgsValidatorFuncÚDocstringFormatÚGenerateToolJsonSchemaÚSystemPromptFuncÚToolÚToolDefinitionÚToolFuncContextÚToolFuncEitherÚToolFuncPlainÚ
ToolParamsÚToolPrepareFuncé   )ÚAbstractToolsetÚToolsetToolT)Úkw_onlyc                  óL   • \ rS rSr% SrS\S'   S\S'   SrS\S	'    SrS
\S'   Srg)ÚFunctionToolsetToolé    zWA tool definition for a function toolset tool that keeps track of the function to call.zBCallable[[dict[str, Any], RunContext[AgentDepsT]], Awaitable[Any]]Ú	call_funcÚboolÚis_asyncNúfloat | NoneÚtimeoutú
str | NoneÚoriginal_name© )	Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__Ú__annotations__r,   r.   Ú__static_attributes__r/   ó    ÚZ/home/mande/repo/quber/.venv/lib/python3.13/site-packages/pydantic_ai/toolsets/function.pyr&   r&       s0   ‡ áaàQÓQØƒNØ €Gˆ\Ó ðð !%€M�:Ó$òr7   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'   / 4SSSS\SSSSSSSSS.                           S+S jjjr\S,S j5       r	\
S-S j5       r\
SSSSSSSSSSSSSSSS.                               S.S jj5       r S/SSSSSSSSSSSSSSSS.                                 S0S jjjr\
S1S j5       r\
SSSSSSSSSSSSSSSS.                               S2S jj5       r S/SSSSSSSSSSSSSSSS.                                 S3S  jjjr    S4S! jr                S5                                   S6S" jjrS7S# jrS8S$ jrS9S% jrSS&.       S:S' jjr          S;S( jr          S<S) jrS*rg)=ÚFunctionToolseté2   z‚A toolset that lets Python functions be used as tools.

See [toolset docs](../toolsets.md#function-toolset) for more information.
zdict[str, Tool[Any]]Útoolsú
int | NoneÚmax_retriesr+   r,   r-   Ú_idr   Údocstring_formatr)   Úrequire_parameter_descriptionsútype[GenerateJsonSchema]Úschema_generatorÚ_defer_loadingúbool | NoneÚinclude_return_schemaNÚautoF)r>   r,   r@   rA   rC   ÚstrictÚ
sequentialÚrequires_approvalÚmetadataÚdefer_loadingrF   ÚidÚinstructionsc               óÎ  • X l         X0l        XÐl        X@l        XPl        X`l        Xpl        X€l        X�l        X l	        X°l
        XÀl        [        U5       Vs/ s H3  n[        U[        [        45      (       a  UO[         ["           " U5      PM5     snU l        0 U l        U H<  n[        U[(        5      (       a  U R+                  U5        M+  U R-                  U5        M>     gs  snf )aÀ  Build a new function toolset.

Args:
    tools: The tools to add to the toolset.
    max_retries: The maximum number of retries for each tool during a run.
        If `None`, inherits the agent's default retry count at runtime.
        Applies to all tools, unless overridden when adding a tool.
    timeout: Timeout in seconds for tool execution. If a tool takes longer than this,
        a retry prompt is returned to the model. Individual tools can override this with their own timeout.
        Defaults to None (no timeout).
    docstring_format: Format of tool docstring, see [`DocstringFormat`][pydantic_ai.tools.DocstringFormat].
        Defaults to `'auto'`, such that the format is inferred from the structure of the docstring.
        Applies to all tools, unless overridden when adding a tool.
    require_parameter_descriptions: If True, raise an error if a parameter description is missing. Defaults to False.
        Applies to all tools, unless overridden when adding a tool.
    schema_generator: The JSON schema generator class to use for this tool. Defaults to `GenerateToolJsonSchema`.
        Applies to all tools, unless overridden when adding a tool.
    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.
        Applies to all tools, unless overridden when adding a tool.
    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.
        Applies to all tools, unless overridden when adding a tool.
    metadata: Optional metadata for the tool. This is not sent to the model but can be used for filtering and tool behavior customization.
        Applies to all tools, unless overridden when adding a tool, which will be merged with the toolset's metadata.
    defer_loading: Whether to hide tools from the model until they're revealed by tool search,
        `load_capability`, or another tool's `ToolReturn.tools`.
        See [Tool Search](../tools-advanced.md#tool-search) for more info.
        Applies to all tools, unless overridden when adding a tool.
    include_return_schema: Whether to include return schemas in tool definitions sent to the model.
        If `None`, defaults to `False` unless the
        [`IncludeToolReturnSchemas`][pydantic_ai.capabilities.IncludeToolReturnSchemas] capability is used.
        Applies to all tools, unless overridden when adding a tool.
    id: An optional unique ID for the toolset. 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.
    instructions: Instructions for this toolset that are automatically included in the model request.
        Can be a string, an [`InstructionPart`][pydantic_ai.messages.InstructionPart] declaring the
        part's [`name`][pydantic_ai.messages.InstructionPart.name] and whether it is
        [`dynamic`][pydantic_ai.messages.InstructionPart.dynamic], a function (sync or async, with
        or without `RunContext`), or a sequence of these.
N)r>   r,   r?   r@   rA   rC   rH   rI   rJ   rK   rD   rF   r   Ú
isinstanceÚstrr   r   r   Ú_instructionsr<   r   Úadd_toolÚadd_function)Úselfr<   r>   r,   r@   rA   rC   rH   rI   rJ   rK   rL   rF   rM   rN   ÚinstructionÚtools                    r8   Ú__init__ÚFunctionToolset.__init__B   sÝ   € ðz 'ÔØŒØŒØ 0ÔØ.LÔ+Ø 0ÔØŒØ$ŒØ!2ÔØ ŒØ+ÔØ%:Ô"ô  6°lÔCó	\
ò  D�ô ˜+¬¬_Ð'=×>Ñ>ñ ä#¤JÒ/°Ó<ò=ñ  Dñ	\
ˆÔð ˆŒ
ÛˆDÜ˜$¤×%Ñ%Ø—‘˜dÖ#à×!Ñ! $Ö'ò	 ùò\
s   Á:C"c                ó   • U R                   $ ©N)r?   )rU   s    r8   rM   ÚFunctionToolset.id�   s   € à�x‰xˆr7   c               ó   • g r[   r/   ©rU   Úfuncs     r8   rW   ÚFunctionToolset.tool¡   s   € Øqtr7   )ÚnameÚdescriptionÚretriesÚprepareÚargs_validatorr@   rA   rC   rH   rI   rJ   rK   r,   rL   rF   c              ó   • g r[   r/   ©rU   ra   rb   rc   rd   re   r@   rA   rC   rH   rI   rJ   rK   r,   rL   rF   s                   r8   rW   r`   ¤   s	   € ð( hkr7   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 `@toolset.tool` is obscured.

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

toolset = FunctionToolset()

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

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

agent = Agent('test', toolsets=[toolset], deps_type=int)
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].
        If `None`, the default value is determined by the toolset.
    require_parameter_descriptions: If True, raise an error if a parameter description is missing.
        If `None`, the default value is determined by the toolset.
    schema_generator: The JSON schema generator class to use for this tool.
        If `None`, the default value is determined by the toolset.
    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.
        If `None`, the default value is determined by the toolset.
    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.
        If `None`, the default value is determined by the toolset.
    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.
        If `None`, the default value is determined by the toolset.
    metadata: Optional metadata for the tool. This is not sent to the model but can be used for filtering and tool behavior customization.
        If `None`, the default value is determined by the toolset. If provided, it will be merged with the toolset's metadata.
    timeout: Timeout in seconds for tool execution. If the tool takes longer, a retry prompt is returned to the model.
        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`.
        See [Tool Search](../tools-advanced.md#tool-search) for more info.
        If `None`, the default value is determined by the toolset.
    include_return_schema: Whether to include the return schema in the tool definition sent to the model.
        If `None`, the default value is determined by the toolset.
c                óF   >• TR                  U STTTTTTT	TTTT
TTTTS9  U $ )NT©r_   Ú	takes_ctxra   rb   rc   rd   re   r@   rA   rC   rH   rI   rJ   rK   r,   rL   rF   ©rT   ©Úfunc_re   rL   rb   r@   rF   rK   ra   rd   rA   rJ   rc   rC   rU   rI   rH   r,   s    €€€€€€€€€€€€€€€€r8   Útool_decoratorÚ,FunctionToolset.tool.<locals>.tool_decorator  sR   ø€ ð ×ÑØØØØ'ØØØ-Ø!1Ø/MØ!1ØØ%Ø"3Ø!ØØ+Ø&;ð# ñ ð& ˆLr7   )rn   ú'ToolFuncContext[AgentDepsT, ToolParams]Úreturnrq   r/   ©rU   r_   ra   rb   rc   rd   re   r@   rA   rC   rH   rI   rJ   rK   r,   rL   rF   ro   s   ` ``````````````` r8   rW   r`   º   s:   ÿÿ€ ð|	Ø:ð	à4÷	÷ 	ö 	ð0 "&¡ˆ~ÐG±>À$Ó3GÐGr7   c               ó   • g r[   r/   r^   s     r8   Ú
tool_plainÚFunctionToolset.tool_plain2  s   € Ø[^r7   c              ó   • g r[   r/   rg   s                   r8   ru   rv   5  s	   € ð( LOr7   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      $ )uO  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 `@toolset.tool_plain` is obscured.

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

toolset = FunctionToolset()

@toolset.tool_plain
def foobar(x: int) -> int:
    return x + 1

@toolset.tool_plain(retries=2)
async def spam(y: float) -> float:
    return y * 2.0

agent = Agent('test', toolsets=[toolset])
result = agent.run_sync('foobar')
print(result.output)
#> {"foobar":1,"spam":0.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 toolset's default retries,
        which defaults to the agent's default.
    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].
        If `None`, the default value is determined by the toolset.
    require_parameter_descriptions: If True, raise an error if a parameter description is missing.
        If `None`, the default value is determined by the toolset.
    schema_generator: The JSON schema generator class to use for this tool.
        If `None`, the default value is determined by the toolset.
    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.
        If `None`, the default value is determined by the toolset.
    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.
        If `None`, the default value is determined by the toolset.
    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.
        If `None`, the default value is determined by the toolset.
    metadata: Optional metadata for the tool. This is not sent to the model but can be used for filtering and tool behavior customization.
        If `None`, the default value is determined by the toolset. If provided, it will be merged with the toolset's metadata.
    timeout: Timeout in seconds for tool execution. If the tool takes longer, a retry prompt is returned to the model.
        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`.
        See [Tool Search](../tools-advanced.md#tool-search) for more info.
        If `None`, the default value is determined by the toolset.
    include_return_schema: Whether to include the return schema in the tool definition sent to the model.
        If `None`, the default value is determined by the toolset.
c                óF   >• TR                  U STTTTTTT	TTTT
TTTTS9  U $ )NFrj   rl   rm   s    €€€€€€€€€€€€€€€€r8   ro   Ú2FunctionToolset.tool_plain.<locals>.tool_decoratorª  sR   ø€ ð ×ÑØØØØ'ØØØ-Ø!1Ø/MØ!1ØØ%Ø"3Ø!ØØ+Ø&;ð# ñ ð& ˆLr7   )rn   úToolFuncPlain[ToolParams]rr   r{   r/   rs   s   ` ``````````````` r8   ru   rv   K  s:   ÿÿ€ ð~	Ø,ð	à&÷	÷ 	ö 	ð2 "&¡ˆ~ÐG±>À$Ó3GÐGr7   c               óN   • U R                   R                  [        U5      5        U$ )a_  Decorator to register an instructions function for this toolset.

The function can be sync or async, and can optionally take a
[`RunContext`][pydantic_ai.tools.RunContext] as its first argument.

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

toolset = FunctionToolset[int]()

@toolset.instructions
def my_instructions(ctx: RunContext[int]) -> str:
    return 'Always use the search tool when looking for information.'

@toolset.tool
def search(ctx: RunContext[int], query: str) -> str:
    return f'Results for: {query}'
```

Args:
    func: The instructions function to register.
)rR   Úappendr   r^   s     r8   rN   ÚFunctionToolset.instructionsÅ  s#   € ð8 	×Ñ×!Ñ!Ô"4°TÓ":Ô;Øˆr7   c                óœ  • Uc  U R                   nU	c  U R                  n	U
c  U R                  n
Uc  U R                  nUc  U R                  nUc  U R
                  nUc  U R                  nUc  U R                  n[        [           " U40 SU_SU_SU_SU_SU_SU_SU_SU	_S	U
_S
U_SU_SU_SU_SU_SU_SU_6nU R                  U5        U$ )aü  Add a function as a tool to the toolset.

Can take a sync or async function.

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

Args:
    func: The tool function to register.
    takes_ctx: Whether the function takes a [`RunContext`][pydantic_ai.tools.RunContext] as its first argument. If `None`, this is inferred from the function signature.
    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].
        If `None`, the default value is determined by the toolset.
    require_parameter_descriptions: If True, raise an error if a parameter description is missing.
        If `None`, the default value is determined by the toolset.
    schema_generator: The JSON schema generator class to use for this tool.
        If `None`, the default value is determined by the toolset.
    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.
        If `None`, the default value is determined by the toolset.
    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.
        If `None`, the default value is determined by the toolset.
    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.
        If `None`, the default value is determined by the toolset.
    defer_loading: Whether to hide this tool until it's revealed by tool search, `load_capability`,
        or another tool's `ToolReturn.tools`.
        See [Tool Search](../tools-advanced.md#tool-search) for more info.
        If `None`, the default value is determined by the toolset.
    metadata: Optional metadata for the tool. This is not sent to the model but can be used for filtering and tool behavior customization.
        If `None`, the default value is determined by the toolset. If provided, it will be merged with the toolset's metadata.
    timeout: Timeout in seconds for tool execution. If the tool takes longer, a retry prompt is returned to the model.
        Defaults to None (no timeout).
    include_return_schema: Whether to include the return schema in the tool definition sent to the model.
        If `None`, the default value is determined by the toolset.
rk   ra   rb   r>   rd   re   r@   rA   rC   rH   rI   rJ   rK   r,   rL   rF   )r@   rA   rC   rH   rI   rJ   rD   rF   r   r   rS   )rU   r_   rk   ra   rb   rc   rd   re   r@   rA   rC   rH   rI   rJ   rL   rK   r,   rF   rW   s                      r8   rT   ÚFunctionToolset.add_functionä  sQ  € ðL Ñ#Ø#×4Ñ4ÐØ)Ñ1Ø-1×-PÑ-PÐ*ØÑ#Ø#×4Ñ4ÐØ‰>Ø—[‘[ˆFØÑØŸ™ˆJØÑ$Ø $× 6Ñ 6ÐØÑ Ø ×/Ñ/ˆMØ Ñ(Ø$(×$>Ñ$>Ð!ä”JÒØò
áð
ñ ð
ñ $ð	
ñ
  ð
ñ ð
ñ *ð
ñ .ð
ñ ,Jð
ñ .ð
ñ ð
ñ "ð
ñ 0ð
ñ ð
ñ ð
ñ  (ð!
ñ" #8ð#
ˆð& 	�‰�dÔØˆr7   c                óX  • UR                   U R                  ;   a  [        SUR                   < 35      eUR                  c  U R                  b  U R                  Ul        U R                  b'  U R                  UR                  =(       d    0 -  Ul        XR                  UR                   '   g)z=Add a tool to the toolset.

Args:
    tool: The tool to add.
z(Tool name conflicts with existing tool: N)ra   r<   r   r>   rK   )rU   rW   s     r8   rS   ÚFunctionToolset.add_toolQ  sƒ   € ð �9‰9˜Ÿ
™
Ó"ÜÐFÀtÇyÁyÁmÐTÓUÐUØ×ÑÑ#¨×(8Ñ(8Ñ(DØ#×/Ñ/ˆDÔØ�=‰=Ñ$Ø ŸM™M¨T¯]©]×-@¸bÑAˆDŒMØ $�
‰
�4—9‘9Òr7   c              ƒ  óô  #   • U R                   (       d  g / nU R                    HÄ  n[        U[        5      (       a  UR                  U5        M+  [        U[        5      (       a2  UR                  5       (       a  UR                  [        USS95        Mp  Mr  UR                  U5      I S h  v•N nU(       d  M”  UR                  5       (       d  M«  UR                  [        USS95        MÆ     U=(       d    S $  NL7f)NF)ÚcontentÚdynamicT)rR   rP   r   r}   rQ   ÚstripÚrun)rU   ÚctxÚpartsrV   Úresults        r8   Úget_instructionsÚ FunctionToolset.get_instructions_  s»   é € Ø×!×!ØØ')ˆØ×-Ô-ˆKÜ˜+¤×7Ñ7ð —‘˜[Ö)Ü˜K¬×-Ñ-Ø×$Ñ$×&Ñ&Ø—L‘L¤¸ÈeÑ!TÖUñ 'ð  +Ÿ™¨sÓ3×3�ß�6˜fŸl™lŸn›nØ—L‘L¤¸ÈÑ!NÖOñ .ð �}˜Ðñ 4ùs   ‚B'C8Â)C6Â*	C8Â7C8Ã)C8c           	   ƒ  óð  #   • 0 nU R                   R                  5        HÏ  u  p4UR                  b  UR                  OU R                  nUc  UR                  n[        UUUR                  R                  US5      US9nUR                  U5      I S h  v•N nU(       d  M�  UR                  nX‚;   a)  Xƒ:w  a  [        SU< SU< S35      e[        SU< S35      eU R                  XGXS5      X('   MÑ     U$  Na7f)Nr   )Ú	tool_nameÚretryr>   zRenaming tool z to z conflicts with existing tool.z2Tool name conflicts with previously renamed tool: Ú.)
r<   Úitemsr>   r   rc   ÚgetÚprepare_tool_defra   r   Ú	_tool_for)	rU   rˆ   r<   r.   rW   r>   Úrun_contextÚtool_defÚnew_names	            r8   Ú	get_toolsÚFunctionToolset.get_toolsr  sú   é € Ø46ˆØ#'§:¡:×#3Ñ#3Ö#5ÑˆMØ.2×.>Ñ.>Ñ.J˜$×*Ò*ÐPT×P`ÑP`ˆKØÑ"Ø!Ÿo™o�Ü!ØØ'Ø—k‘k—o‘o m°QÓ7Ø'ñ	ˆKð "×2Ñ2°;Ó?×?ˆHÞÙà—}‘}ˆHØÓ ØÓ,Ü# n°]Ñ4EÀTÈ(ÉÐUsÐ$tÓuÐuä#Ð&XÐYaÑXdÐdeÐ$fÓgÐgà"Ÿn™n¨T¸[ÓXˆE‹Oñ+ $6ð, ˆñ @ùs   ‚BC6ÂC4ÂA"C6)r.   c               óØ   • Ub  UOUR                   nU R                  U   nUR                  b  UR                  OU R                  nU R                  XAUb  XS5      $ UR                  U5      $ )a  Build the tool to call for a tool definition that was already prepared elsewhere.

Used by [durable execution](../durable_execution/overview.md) to rebuild the tool inside the
durable unit (e.g. a Temporal activity) from the tool definition that
[`get_tools()`][pydantic_ai.toolsets.AbstractToolset.get_tools] produced outside it, instead
of running the tool's `prepare` function a second time against a different run context.

Args:
    tool_def: The prepared tool definition to build the tool from.
    ctx: The run context used to resolve the tool's retry budget.
    original_name: The name this toolset holds the tool under, from the built tool's
        `original_name`. Defaults to `tool_def.name`, which is only the same when no
        `prepare` function renamed the tool. This is specific to `FunctionToolset` because
        per-tool preparation runs inside its own `get_tools()` and can change the exposed name
        without changing the key in `tools`.

Raises:
    KeyError: If the toolset holds no tool under that name.
)ra   r<   r>   r”   )rU   r–   rˆ   r.   rW   r>   s         r8   Útool_for_tool_defÚ!FunctionToolset.tool_for_tool_defŒ  so   € ð, *7Ñ)B™ÈÏÉˆØ�z‰z˜-Ñ(ˆØ*.×*:Ñ*:Ñ*F�d×&Ò&ÈD×L\ÑL\ˆØ�~‰~Ø¨;Ñ+B˜Kó
ð 	
ØHKÏÉÐYfó
ð 	
r7   c                óÄ   • [        U UUUR                  R                  UR                  UR                  R                  UR                  R
                  UR                  US9	$ )N)	Útoolsetr–   r>   re   Úargs_validator_funcr(   r*   r,   r.   )r&   Úfunction_schemaÚ	validatorre   Úcallr*   r,   )rU   rW   r–   r>   r.   s        r8   r”   ÚFunctionToolset._tool_for©  s\   € ô #ØØØ#Ø×/Ñ/×9Ñ9Ø $× 3Ñ 3Ø×*Ñ*×/Ñ/Ø×)Ñ)×2Ñ2Ø×$Ñ$Ø'ñ

ð 
	
r7   c              ƒ  ó.  #   • [        U[        5      (       d   eUR                  R                  b  UR                  R                  OU R                  nUbY   [        R
                  " U5         [        R                  " 5          UR                  X#5      I S h  v•N sS S S 5        sS S S 5        $ UR                  X#5      I S h  v•N $  N/! , (       d  f       O= fS S S 5        g ! , (       d  f       g = f! [         a    [        SU S35      S ef = f NO7f)NzTimed out after z	 seconds.)rP   r&   r–   r,   ÚanyioÚ
fail_afterr   Úabandon_threads_on_cancelr(   ÚTimeoutErrorr   )rU   ra   Ú	tool_argsrˆ   rW   r,   s         r8   Ú	call_toolÚFunctionToolset.call_tool¸  sá   é € ô ˜$Ô 3×4Ñ4Ð4Ð4ð ,0¯=©=×+@Ñ+@Ñ+L�$—-‘-×'Ò'ÐRV×R^ÑR^ˆØÑðRÜ×%Ò% gÕ.´×0PÒ0PÕ0RØ!%§¡°	Ó!?×?÷ 1SÐ0R×.Ñ.ð
 Ÿ™¨	Ó7×7Ð7ñ	 @÷ 1SÕ0Rú×.×.Ö.ûäó RÜ Ð#3°G°9¸IÐ!FÓGÈTÐQðRúñ 8ùs„   ‚ADÁC5 Á-C$ÂC
ÂCÂC
Â	C$Â%	C5 Â.DÃDÃDÃC
Ã

C	ÃC$ÃC5 Ã#DÃ$
C2Ã.C5 Ã1DÃ2C5 Ã5DÄD)rD   r?   rR   r@   rF   r>   rK   rA   rJ   rC   rI   rH   r,   r<   )r<   z<Sequence[Tool[AgentDepsT] | ToolFuncEither[AgentDepsT, ...]]r>   r=   r,   r+   r@   r   rA   r)   rC   rB   rH   rE   rI   r)   rJ   r)   rK   údict[str, Any] | NonerL   r)   rF   rE   rM   r-   rN   zAgentInstructions[AgentDepsT])rr   r-   )r_   rq   rr   rq   ) ra   r-   rb   r-   rc   r=   rd   ú"ToolPrepareFunc[AgentDepsT] | Nonere   ú0ArgsValidatorFunc[AgentDepsT, ToolParams] | Noner@   úDocstringFormat | NonerA   rE   rC   útype[GenerateJsonSchema] | NonerH   rE   rI   rE   rJ   rE   rK   r¬   r,   r+   rL   rE   rF   rE   rr   z\Callable[[ToolFuncContext[AgentDepsT, ToolParams]], ToolFuncContext[AgentDepsT, ToolParams]]r[   )"r_   z.ToolFuncContext[AgentDepsT, ToolParams] | Nonera   r-   rb   r-   rc   r=   rd   r­   re   r®   r@   r¯   rA   rE   rC   r°   rH   rE   rI   rE   rJ   rE   rK   r¬   r,   r+   rL   rE   rF   rE   rr   r	   )r_   r{   rr   r{   ) ra   r-   rb   r-   rc   r=   rd   r­   re   r®   r@   r¯   rA   rE   rC   r°   rH   rE   rI   rE   rJ   rE   rK   r¬   r,   r+   rL   rE   rF   rE   rr   z@Callable[[ToolFuncPlain[ToolParams]], ToolFuncPlain[ToolParams]])"r_   z ToolFuncPlain[ToolParams] | Nonera   r-   rb   r-   rc   r=   rd   r­   re   r®   r@   r¯   rA   rE   rC   r°   rH   rE   rI   rE   rJ   rE   rK   r¬   r,   r+   rL   rE   rF   rE   rr   r	   )r_   úSystemPromptFunc[AgentDepsT]rr   r±   )NNNNNNNNNNNNNNNN)$r_   z&ToolFuncEither[AgentDepsT, ToolParams]rk   rE   ra   r-   rb   r-   rc   r=   rd   r­   re   r®   r@   r¯   rA   rE   rC   r°   rH   rE   rI   rE   rJ   rE   rL   rE   rK   r¬   r,   r+   rF   rE   rr   úTool[AgentDepsT])rW   r²   rr   ÚNone)rˆ   úRunContext[AgentDepsT]rr   zlist[InstructionPart] | None)rˆ   r´   rr   z"dict[str, ToolsetTool[AgentDepsT]])r–   r   rˆ   r´   r.   r-   rr   úFunctionToolsetTool[AgentDepsT])
rW   r²   r–   r   r>   Úintr.   rQ   rr   rµ   )
ra   rQ   r©   zdict[str, Any]rˆ   r´   rW   zToolsetTool[AgentDepsT]rr   r	   )r0   r1   r2   r3   r4   r5   r   rX   ÚpropertyrM   r
   rW   ru   rN   rT   rS   r‹   r˜   r›   r”   rª   r6   r/   r7   r8   r:   r:   2   sú  ‡ ñð
  ÓØÓØÓØ	ƒOØ%Ó%Ø$(Ó(Ø.Ó.ØÓØ&Ó&ð OQðY(ð #'Ø $Ø,2Ø/4Ø5KØ"Ø Ø"'Ø*.Ø#Ø-1ØØ6:ñ!Y(àKðY(ð  ð	Y(ð
 ðY(ð *ðY(ð )-ðY(ð 3ðY(ð ðY(ð ðY(ð  ðY(ð (ðY(ð ðY(ð  +ðY(ð ðY(ð  4ö!Y(ðv óó ðð Ûtó Øtàð
  Ø"&Ø"Ø6:ØKOØ37Ø6:Ø<@Ø"Ø"&Ø)-Ø*.Ø $Ø%)Ø-1ñ%kð ð	kð
  ðkð ðkð 4ðkð Iðkð 1ðkð )4ðkð :ðkð ðkð  ðkð 'ðkð (ðkð  ð!kð" #ð#kð$  +ð%kð& 
fô'kó ðkð. @DðvHð
  Ø"&Ø"Ø6:ØKOØ37Ø6:Ø<@Ø"Ø"&Ø)-Ø*.Ø $Ø%)Ø-1ñ'vHà<ðvHð
 ðvHð  ðvHð ðvHð 4ðvHð IðvHð 1ðvHð )4ðvHð :ðvHð ðvHð  ðvHð 'ðvHð  (ð!vHð" ð#vHð$ #ð%vHð&  +ð'vHð( 
ö)vHðp Û^ó Ø^àð
  Ø"&Ø"Ø6:ØKOØ37Ø6:Ø<@Ø"Ø"&Ø)-Ø*.Ø $Ø%)Ø-1ñ%Oð ð	Oð
  ðOð ðOð 4ðOð IðOð 1ðOð )4ðOð :ðOð ðOð  ðOð 'ðOð (ðOð  ð!Oð" #ð#Oð$  +ð%Oð& 
Jô'Oó ðOð. 26ðxHð
  Ø"&Ø"Ø6:ØKOØ37Ø6:Ø<@Ø"Ø"&Ø)-Ø*.Ø $Ø%)Ø-1ñ'xHà.ðxHð
 ðxHð  ðxHð ðxHð 4ðxHð IðxHð 1ðxHð )4ðxHð :ðxHð ðxHð  ðxHð 'ðxHð  (ð!xHð" ð#xHð$ #ð%xHð&  +ð'xHð( 
ö)xHðtà*ðð 
&ô	ðD "&ØØ"&Ø"Ø6:ØKOØ37Ø6:Ø<@Ø"Ø"&Ø)-Ø%)Ø*.Ø $Ø-1ð%kà4ðkð ðkð ð	kð
  ðkð ðkð 4ðkð Iðkð 1ðkð )4ðkð :ðkð ðkð  ðkð 'ðkð #ðkð  (ð!kð" ð#kð$  +ð%kð& 
õ'kôZ%ôô&ð6 eiñ
Ø&ð
Ø0Fð
ØWað
à	(õ
ð:
Ø$ð
Ø0>ð
ØMPð
Øadð
à	(ô
ð8Øð8Ø$2ð8Ø9Oð8ØWnð8à	÷8r7   r:   )/Ú
__future__r   Úcollections.abcr   r   r   Údataclassesr   r   Útypingr	   r
   r¥   Úpydantic.json_schemar   Ú r   rR   r   r   Ú_run_contextr   r   Ú_system_promptr   Ú
exceptionsr   r   Úmessagesr   r<   r   r   r   r   r   r   r   r   r   r   r    Úabstractr"   r#   r&   r:   r/   r7   r8   Ú<module>rÃ      s}   ðÝ "ç 9Ñ 9ß *ß  ã Ý 3å ß Eß 1Ý /ß .Ý &÷÷ ÷ ñ ÷ 3ñ �4Ñô˜+ jÑ1ó ó ðô"U
8�o jÑ1õ U
8r7   