You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -149,10 +150,11 @@ _(This example is complete, it can be run "as is")_
149
150
To easily chain different modifications, you can also call [`filtered()`][pydantic_ai.toolsets.AbstractToolset.filtered] on any toolset instead of directly constructing a `FilteredToolset`.
@@ -173,11 +175,12 @@ _(This example is complete, it can be run "as is")_
173
175
To easily chain different modifications, you can also call [`prefixed()`][pydantic_ai.toolsets.AbstractToolset.prefixed] on any toolset instead of directly constructing a `PrefixedToolset`.
from function_toolset import datetime_toolset, weather_toolset
177
178
from pydantic_ai import Agent
178
179
from pydantic_ai.models.test import TestModel
179
180
from pydantic_ai.toolsets import CombinedToolset
180
181
182
+
from function_toolset import datetime_toolset, weather_toolset
183
+
181
184
combined_toolset = CombinedToolset(
182
185
[
183
186
weather_toolset.prefixed('weather'),
@@ -210,10 +213,11 @@ _(This example is complete, it can be run "as is")_
210
213
To easily chain different modifications, you can also call [`renamed()`][pydantic_ai.toolsets.AbstractToolset.renamed] on any toolset instead of directly constructing a `RenamedToolset`.
@@ -250,6 +254,7 @@ from dataclasses import replace
250
254
251
255
from pydantic_ai import Agent, RunContext, ToolDefinition
252
256
from pydantic_ai.models.test import TestModel
257
+
253
258
from renamed_toolset import renamed_toolset
254
259
255
260
descriptions = {
@@ -330,10 +335,11 @@ To easily chain different modifications, you can also call [`approval_required()
330
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.
from pydantic_ai.toolsets import ToolsetTool, WrapperToolset
398
403
404
+
from prepared_toolset import prepared_toolset
405
+
399
406
LOG= []
400
407
401
408
classLoggingToolset(WrapperToolset):
@@ -483,11 +490,12 @@ print(repr(result.output))
483
490
Next, let's define a function that represents a hypothetical "run agent" API endpoint that can be called by the frontend and takes a list of messages to send to the model, a list of frontend tool definitions, and optional deferred tool results. This is where `ExternalToolset`, `DeferredToolRequests`, and `DeferredToolResults` come in:
from deferred_toolset_agent import PersonalizedGreeting, agent
487
493
from pydantic_ai import DeferredToolRequests, DeferredToolResults, ToolDefinition
488
494
from pydantic_ai.messages import ModelMessage
489
495
from pydantic_ai.toolsets import ExternalToolset
490
496
497
+
from deferred_toolset_agent import PersonalizedGreeting, agent
498
+
491
499
492
500
defrun_agent(
493
501
messages: list[ModelMessage] = [],
@@ -511,7 +519,6 @@ def run_agent(
511
519
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:
0 commit comments