Skip to content

Commit 45cdc2c

Browse files
committed
Fix failing docs build
1 parent 5216c6e commit 45cdc2c

File tree

8 files changed

+26
-26
lines changed

8 files changed

+26
-26
lines changed

docs/output.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ In the default Tool Output mode, the output JSON schema of each output type (or
272272

273273
If you'd like to change the name of the output tool, pass a custom description to aid the model, or turn on or off strict mode, you can wrap the type(s) in the [`ToolOutput`][pydantic_ai.output.ToolOutput] marker class and provide the appropriate arguments. Note that by default, the description is taken from the docstring specified on a Pydantic model or output function, so specifying it using the marker class is typically not necessary.
274274

275-
To dynamically modify or filter the available output tools during an agent run, you can define an agent-wide `prepare_output_tools` function that will be called ahead of each step of a run. This function should be of type [`ToolsPrepareFunc`][pydantic_ai.tools.ToolsPrepareFunc], which takes the [`RunContext`][pydantic_ai.tools.RunContext] and a list of [`ToolDefinition`][pydantic_ai.tools.ToolDefinition], and returns a new list of tool definitions (or `None` to disable all tools for that step). This is analogous to the [`prepare_tools` function](tools.md#prepare-tools) for non-output tools.
275+
To dynamically modify or filter the available output tools during an agent run, you can define an agent-wide `prepare_output_tools` function that will be called ahead of each step of a run. This function should be of type [`ToolsPrepareFunc`][pydantic_ai.tools.ToolsPrepareFunc], which takes the [`RunContext`][pydantic_ai.tools.RunContext] and a list of [`ToolDefinition`][pydantic_ai.tools.ToolDefinition], and returns a new list of tool definitions (or `None` to disable all tools for that step). This is analogous to the [`prepare_tools` function](tools-advanced.md#prepare-tools) for non-output tools.
276276

277277
```python {title="tool_output.py"}
278278
from pydantic import BaseModel

docs/tools.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ There are a number of ways to register tools with an agent:
1212
- via the [`@agent.tool_plain`][pydantic_ai.Agent.tool_plain] decorator — for tools that do not need access to the agent [context][pydantic_ai.tools.RunContext]
1313
- via the [`tools`][pydantic_ai.Agent.__init__] keyword argument to `Agent` which can take either plain functions, or instances of [`Tool`][pydantic_ai.tools.Tool]
1414

15-
For more advanced use cases, the [toolsets](toolsets.md) feature lets you manage collections of tools (built by you or provided by an [MCP server](mcp/client.md) or other [third party](#third-party-tools)) and register them with an agent in one go via the [`toolsets`][pydantic_ai.Agent.__init__] keyword argument to `Agent`. Internally, all `tools` and `toolsets` are gathered into a single [combined toolset](toolsets.md#combining-toolsets) that's made available to the model.
15+
For more advanced use cases, the [toolsets](toolsets.md) feature lets you manage collections of tools (built by you or provided by an [MCP server](mcp/client.md) or other [third party](third-party-tools.md#third-party-tools)) and register them with an agent in one go via the [`toolsets`][pydantic_ai.Agent.__init__] keyword argument to `Agent`. Internally, all `tools` and `toolsets` are gathered into a single [combined toolset](toolsets.md#combining-toolsets) that's made available to the model.
1616

1717
!!! info "Function tools vs. RAG"
1818
Function tools are basically the "R" of RAG (Retrieval-Augmented Generation) — they augment what the model can do by letting it request extra information.
@@ -231,7 +231,7 @@ print(dice_result['b'].output)
231231
```
232232

233233
1. The simplest way to register tools via the `Agent` constructor is to pass a list of functions, the function signature is inspected to determine if the tool takes [`RunContext`][pydantic_ai.tools.RunContext].
234-
2. `agent_a` and `agent_b` are identical — but we can use [`Tool`][pydantic_ai.tools.Tool] to reuse tool definitions and give more fine-grained control over how tools are defined, e.g. setting their name or description, or using a custom [`prepare`](#tool-prepare) method.
234+
2. `agent_a` and `agent_b` are identical — but we can use [`Tool`][pydantic_ai.tools.Tool] to reuse tool definitions and give more fine-grained control over how tools are defined, e.g. setting their name or description, or using a custom [`prepare`](tools-advanced.md#tool-prepare) method.
235235

236236
_(This example is complete, it can be run "as is")_
237237

docs/toolsets.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ _(This example is complete, it can be run "as is")_
243243

244244
[`PreparedToolset`][pydantic_ai.toolsets.PreparedToolset] lets you modify the entire list of available tools ahead of each step of the agent run using a user-defined function that takes the agent [run context][pydantic_ai.tools.RunContext] and a list of [`ToolDefinition`s][pydantic_ai.tools.ToolDefinition] and returns a list of modified `ToolDefinition`s.
245245

246-
This is the toolset-specific equivalent of the [`prepare_tools`](tools.md#prepare-tools) argument to `Agent` that prepares all tool definitions registered on an agent across toolsets.
246+
This is the toolset-specific equivalent of the [`prepare_tools`](tools-advanced.md#prepare-tools) argument to `Agent` that prepares all tool definitions registered on an agent across toolsets.
247247

248248
Note that it is not possible to add or rename tools using `PreparedToolset`. Instead, you can use [`FunctionToolset.add_function()`](#function-toolset) or [`RenamedToolset`](#renaming-tools).
249249

@@ -328,11 +328,11 @@ print(test_model.last_model_request_parameters.function_tools)
328328

329329
### Requiring Tool Approval
330330

331-
[`ApprovalRequiredToolset`][pydantic_ai.toolsets.ApprovalRequiredToolset] wraps a toolset and lets you dynamically [require approval](tools.md#human-in-the-loop-tool-approval) for a given tool call based on a user-defined function that is passed the agent [run context][pydantic_ai.tools.RunContext], the tool's [`ToolDefinition`][pydantic_ai.tools.ToolDefinition], and the validated tool call arguments. If no function is provided, all tool calls will require approval.
331+
[`ApprovalRequiredToolset`][pydantic_ai.toolsets.ApprovalRequiredToolset] wraps a toolset and lets you dynamically [require approval](deferred-tools.md#human-in-the-loop-tool-approval) for a given tool call based on a user-defined function that is passed the agent [run context][pydantic_ai.tools.RunContext], the tool's [`ToolDefinition`][pydantic_ai.tools.ToolDefinition], and the validated tool call arguments. If no function is provided, all tool calls will require approval.
332332

333333
To easily chain different modifications, you can also call [`approval_required()`][pydantic_ai.toolsets.AbstractToolset.approval_required] on any toolset instead of directly constructing a `ApprovalRequiredToolset`.
334334

335-
See the [Human-in-the-Loop Tool Approval](tools.md#human-in-the-loop-tool-approval) documentation for more information on how to handle agent runs that call tools that require approval and how to pass in the results.
335+
See the [Human-in-the-Loop Tool Approval](deferred-tools.md#human-in-the-loop-tool-approval) documentation for more information on how to handle agent runs that call tools that require approval and how to pass in the results.
336336

337337
```python {title="approval_required_toolset.py" requires="function_toolset.py,combined_toolset.py,renamed_toolset.py,prepared_toolset.py"}
338338
from pydantic_ai import Agent, DeferredToolRequests, DeferredToolResults
@@ -446,13 +446,13 @@ _(This example is complete, it can be run "as is")_
446446

447447
## External Toolset
448448

449-
If your agent needs to be able to call [external tools](tools.md#external-tool-execution) that are provided and executed by an upstream service or frontend, you can build an [`ExternalToolset`][pydantic_ai.toolsets.ExternalToolset] from a list of [`ToolDefinition`s][pydantic_ai.tools.ToolDefinition] containing the tool names, arguments JSON schemas, and descriptions.
449+
If your agent needs to be able to call [external tools](deferred-tools.md#external-tool-execution) that are provided and executed by an upstream service or frontend, you can build an [`ExternalToolset`][pydantic_ai.toolsets.ExternalToolset] from a list of [`ToolDefinition`s][pydantic_ai.tools.ToolDefinition] containing the tool names, arguments JSON schemas, and descriptions.
450450

451-
When the model calls an external tool, the call is considered to be ["deferred"](tools.md#deferred-tools), and the agent run will end with a [`DeferredToolRequests`][pydantic_ai.output.DeferredToolRequests] output object with a `calls` list holding [`ToolCallPart`s][pydantic_ai.messages.ToolCallPart] containing the tool name, validated arguments, and a unique tool call ID, which are expected to be passed to the upstream service or frontend that will produce the results.
451+
When the model calls an external tool, the call is considered to be ["deferred"](deferred-tools.md#deferred-tools), and the agent run will end with a [`DeferredToolRequests`][pydantic_ai.output.DeferredToolRequests] output object with a `calls` list holding [`ToolCallPart`s][pydantic_ai.messages.ToolCallPart] containing the tool name, validated arguments, and a unique tool call ID, which are expected to be passed to the upstream service or frontend that will produce the results.
452452

453-
When the tool call results are received from the upstream service or frontend, you can build a [`DeferredToolResults`][pydantic_ai.tools.DeferredToolResults] object with a `calls` dictionary that maps each tool call ID to an arbitrary value to be returned to the model, a [`ToolReturn`](tools.md#advanced-tool-returns) object, or a [`ModelRetry`][pydantic_ai.exceptions.ModelRetry] exception in case the tool call failed and the model should [try again](tools.md#tool-retries). This `DeferredToolResults` object can then be provided to one of the agent run methods as `deferred_tool_results`, alongside the original run's [message history](message-history.md).
453+
When the tool call results are received from the upstream service or frontend, you can build a [`DeferredToolResults`][pydantic_ai.tools.DeferredToolResults] object with a `calls` dictionary that maps each tool call ID to an arbitrary value to be returned to the model, a [`ToolReturn`](tools-advanced.md#advanced-tool-returns) object, or a [`ModelRetry`][pydantic_ai.exceptions.ModelRetry] exception in case the tool call failed and the model should [try again](tools-advanced.md#tool-retries). This `DeferredToolResults` object can then be provided to one of the agent run methods as `deferred_tool_results`, alongside the original run's [message history](message-history.md).
454454

455-
Note that you need to add `DeferredToolRequests` to the `Agent`'s or `agent.run()`'s [`output_type`](output.md#structured-output) so that the possible types of the agent run output are correctly inferred. For more information, see the [Deferred Tools](tools.md#deferred-tools) documentation.
455+
Note that you need to add `DeferredToolRequests` to the `Agent`'s or `agent.run()`'s [`output_type`](output.md#structured-output) so that the possible types of the agent run output are correctly inferred. For more information, see the [Deferred Tools](deferred-tools.md#deferred-tools) documentation.
456456

457457
To demonstrate, let us first define a simple agent _without_ deferred tools:
458458

@@ -512,8 +512,8 @@ def run_agent(
512512
return result.output, result.new_messages()
513513
```
514514

515-
1. As mentioned in the [Deferred Tools](tools.md#deferred-tools) documentation, these `toolsets` are additional to those provided to the `Agent` constructor
516-
2. As mentioned in the [Deferred Tools](tools.md#deferred-tools) documentation, this `output_type` overrides the one provided to the `Agent` constructor, so we have to make sure to not lose it
515+
1. As mentioned in the [Deferred Tools](deferred-tools.md#deferred-tools) documentation, these `toolsets` are additional to those provided to the `Agent` constructor
516+
2. As mentioned in the [Deferred Tools](deferred-tools.md#deferred-tools) documentation, this `output_type` overrides the one provided to the `Agent` constructor, so we have to make sure to not lose it
517517
3. We don't include an `user_prompt` keyword argument as we expect the frontend to provide it via `messages`
518518

519519
Now, imagine that the code below is implemented on the frontend, and `run_agent` stands in for an API call to the backend that runs the agent. This is where we actually execute the deferred tool calls and start a new run with the new result included:

mkdocs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ nav:
3838
- tools.md
3939
- tools-advanced.md
4040
- toolsets.md
41+
- deferred-tools.md
4142
- builtin-tools.md
4243
- common-tools.md
4344
- third-party-tools.md
44-
- deferred-tools.md
4545
- Advanced Features:
4646
- input.md
4747
- thinking.md

pydantic_ai_slim/pydantic_ai/agent/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1066,7 +1066,7 @@ async def spam(ctx: RunContext[str], y: float) -> float:
10661066
strict: Whether to enforce JSON schema compliance (only affects OpenAI).
10671067
See [`ToolDefinition`][pydantic_ai.tools.ToolDefinition] for more info.
10681068
requires_approval: Whether this tool requires human-in-the-loop approval. Defaults to False.
1069-
See the [tools documentation](../tools.md#human-in-the-loop-tool-approval) for more info.
1069+
See the [tools documentation](../deferred-tools.md#human-in-the-loop-tool-approval) for more info.
10701070
"""
10711071

10721072
def tool_decorator(
@@ -1165,7 +1165,7 @@ async def spam(ctx: RunContext[str]) -> float:
11651165
strict: Whether to enforce JSON schema compliance (only affects OpenAI).
11661166
See [`ToolDefinition`][pydantic_ai.tools.ToolDefinition] for more info.
11671167
requires_approval: Whether this tool requires human-in-the-loop approval. Defaults to False.
1168-
See the [tools documentation](../tools.md#human-in-the-loop-tool-approval) for more info.
1168+
See the [tools documentation](../deferred-tools.md#human-in-the-loop-tool-approval) for more info.
11691169
"""
11701170

11711171
def tool_decorator(func_: ToolFuncPlain[ToolParams]) -> ToolFuncPlain[ToolParams]:

pydantic_ai_slim/pydantic_ai/exceptions.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def __get_pydantic_core_schema__(cls, _: Any, __: Any) -> core_schema.CoreSchema
6565
class CallDeferred(Exception):
6666
"""Exception to raise when a tool call should be deferred.
6767
68-
See [tools docs](../tools.md#deferred-tools) for more information.
68+
See [tools docs](../deferred-tools.md#deferred-tools) for more information.
6969
"""
7070

7171
pass
@@ -74,7 +74,7 @@ class CallDeferred(Exception):
7474
class ApprovalRequired(Exception):
7575
"""Exception to raise when a tool call requires human-in-the-loop approval.
7676
77-
See [tools docs](../tools.md#human-in-the-loop-tool-approval) for more information.
77+
See [tools docs](../deferred-tools.md#human-in-the-loop-tool-approval) for more information.
7878
"""
7979

8080
pass

pydantic_ai_slim/pydantic_ai/tools.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
ToolPrepareFunc: TypeAlias = Callable[[RunContext[AgentDepsT], 'ToolDefinition'], Awaitable['ToolDefinition | None']]
7171
"""Definition of a function that can prepare a tool definition at call time.
7272
73-
See [tool docs](../tools.md#tool-prepare) for more information.
73+
See [tool docs](../tools-advanced.md#tool-prepare) for more information.
7474
7575
Example — here `only_if_42` is valid as a `ToolPrepareFunc`:
7676
@@ -140,7 +140,7 @@ class DeferredToolRequests:
140140
141141
Results can be passed to the next agent run using a [`DeferredToolResults`][pydantic_ai.tools.DeferredToolResults] object with the same tool call IDs.
142142
143-
See [deferred tools docs](../tools.md#deferred-tools) for more information.
143+
See [deferred tools docs](../deferred-tools.md#deferred-tools) for more information.
144144
"""
145145

146146
calls: list[ToolCallPart] = field(default_factory=list)
@@ -204,7 +204,7 @@ class DeferredToolResults:
204204
205205
The tool call IDs need to match those from the [`DeferredToolRequests`][pydantic_ai.output.DeferredToolRequests] output object from the previous run.
206206
207-
See [deferred tools docs](../tools.md#deferred-tools) for more information.
207+
See [deferred tools docs](../deferred-tools.md#deferred-tools) for more information.
208208
"""
209209

210210
calls: dict[str, DeferredToolCallResult | Any] = field(default_factory=dict)
@@ -328,7 +328,7 @@ async def prep_my_tool(
328328
strict: Whether to enforce JSON schema compliance (only affects OpenAI).
329329
See [`ToolDefinition`][pydantic_ai.tools.ToolDefinition] for more info.
330330
requires_approval: Whether this tool requires human-in-the-loop approval. Defaults to False.
331-
See the [tools documentation](../tools.md#human-in-the-loop-tool-approval) for more info.
331+
See the [tools documentation](../deferred-tools.md#human-in-the-loop-tool-approval) for more info.
332332
function_schema: The function schema to use for the tool. If not provided, it will be generated.
333333
"""
334334
self.function = function
@@ -472,16 +472,16 @@ class ToolDefinition:
472472
- `'function'`: a tool that will be executed by Pydantic AI during an agent run and has its result returned to the model
473473
- `'output'`: a tool that passes through an output value that ends the run
474474
- `'external'`: a tool whose result will be produced outside of the Pydantic AI agent run in which it was called, because it depends on an upstream service (or user) or could take longer to generate than it's reasonable to keep the agent process running.
475-
See the [tools documentation](../tools.md#deferred-tools) for more info.
475+
See the [tools documentation](../deferred-tools.md#deferred-tools) for more info.
476476
- `'unapproved'`: a tool that requires human-in-the-loop approval.
477-
See the [tools documentation](../tools.md#human-in-the-loop-tool-approval) for more info.
477+
See the [tools documentation](../deferred-tools.md#human-in-the-loop-tool-approval) for more info.
478478
"""
479479

480480
@property
481481
def defer(self) -> bool:
482482
"""Whether calls to this tool will be deferred.
483483
484-
See the [tools documentation](../tools.md#deferred-tools) for more info.
484+
See the [tools documentation](../deferred-tools.md#deferred-tools) for more info.
485485
"""
486486
return self.kind in ('external', 'unapproved')
487487

pydantic_ai_slim/pydantic_ai/toolsets/function.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ async def spam(ctx: RunContext[str], y: float) -> float:
162162
strict: Whether to enforce JSON schema compliance (only affects OpenAI).
163163
See [`ToolDefinition`][pydantic_ai.tools.ToolDefinition] for more info.
164164
requires_approval: Whether this tool requires human-in-the-loop approval. Defaults to False.
165-
See the [tools documentation](../tools.md#human-in-the-loop-tool-approval) for more info.
165+
See the [tools documentation](../deferred-tools.md#human-in-the-loop-tool-approval) for more info.
166166
"""
167167

168168
def tool_decorator(
@@ -223,7 +223,7 @@ def add_function(
223223
strict: Whether to enforce JSON schema compliance (only affects OpenAI).
224224
See [`ToolDefinition`][pydantic_ai.tools.ToolDefinition] for more info.
225225
requires_approval: Whether this tool requires human-in-the-loop approval. Defaults to False.
226-
See the [tools documentation](../tools.md#human-in-the-loop-tool-approval) for more info.
226+
See the [tools documentation](../deferred-tools.md#human-in-the-loop-tool-approval) for more info.
227227
"""
228228
if docstring_format is None:
229229
docstring_format = self.docstring_format

0 commit comments

Comments
 (0)