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
Copy file name to clipboardExpand all lines: docs/builtin-tools.md
+45Lines changed: 45 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -20,6 +20,51 @@ These tools are passed to the agent via the `builtin_tools` parameter and are ex
20
20
21
21
If a provider supports a built-in tool that is not currently supported by Pydantic AI, please file an issue.
22
22
23
+
## Dynamic Configuration
24
+
25
+
Sometimes you need to configure a built-in tool dynamically based on the [run context](api/tools.md#pydantic_ai.tools.RunContext) (e.g., user dependencies). You can achieve this by passing a function to `builtin_tools` that takes [`RunContext`][pydantic_ai.tools.RunContext] as an argument and returns an [`AbstractBuiltinTool`][pydantic_ai.builtin_tools.AbstractBuiltinTool] or `None`.
26
+
27
+
This is particularly useful for tools like [`WebSearchTool`][pydantic_ai.builtin_tools.WebSearchTool] where you might want to set the user's location based on the current request.
28
+
29
+
```python {title="dynamic_builtin_tool.py"}
30
+
from dataclasses import dataclass
31
+
from pydantic_ai import Agent, RunContext, WebSearchTool, WebSearchUserLocation
0 commit comments