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/capabilities.md
+113Lines changed: 113 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -27,6 +27,8 @@ Pydantic AI ships with several capabilities that cover common needs:
27
27
|[`PrefixTools`][pydantic_ai.capabilities.PrefixTools]| Wraps a capability and prefixes its tool names | Yes |
28
28
|[`BuiltinTool`][pydantic_ai.capabilities.BuiltinTool]| Registers a [builtin tool](builtin-tools.md) with the agent | Yes |
29
29
|[`Toolset`][pydantic_ai.capabilities.Toolset]| Wraps an [`AbstractToolset`][pydantic_ai.toolsets.AbstractToolset]| — |
30
+
|[`IncludeToolReturnSchemas`][pydantic_ai.capabilities.IncludeToolReturnSchemas]| Includes return type schemas in tool definitions sent to the model | Yes |
[`IncludeToolReturnSchemas`][pydantic_ai.capabilities.IncludeToolReturnSchemas] includes return type schemas in tool definitions sent to the model. For models that natively support return schemas (e.g. Google Gemini), the schema is passed as a structured field in the API request. For other models, it is injected into the tool description as JSON text.
result = agent.run_sync('What is the temperature in Paris?')
243
+
params = test_model.last_model_request_parameters
244
+
assert params isnotNone
245
+
td = params.function_tools[0]
246
+
assert td.include_return_schema isTrue
247
+
```
248
+
249
+
_(This example is complete, it can be run "as is")_
250
+
251
+
Use the `tools` parameter to select which tools should include return schemas. It accepts a list of tool names, a metadata dict for matching, or a callable predicate:
temp_tool =next(t for t in params.function_tools if t.name =='get_temperature')
282
+
greet_tool =next(t for t in params.function_tools if t.name =='get_greeting')
283
+
assert temp_tool.include_return_schema isTrue
284
+
assert greet_tool.include_return_schema isNone
285
+
```
286
+
287
+
_(This example is complete, it can be run "as is")_
288
+
289
+
The same effect can be achieved at the toolset level using [`.include_return_schemas()`][pydantic_ai.toolsets.AbstractToolset.include_return_schemas] — see [toolset composition](toolsets.md#including-return-schemas).
290
+
291
+
### SetToolMetadata
292
+
293
+
[`SetToolMetadata`][pydantic_ai.capabilities.SetToolMetadata] merges metadata key-value pairs onto selected tools. This is useful for tagging tools with configuration that other capabilities or custom logic can inspect:
_(This example is complete, it can be run "as is")_
330
+
331
+
The same effect can be achieved at the toolset level using [`.with_metadata()`][pydantic_ai.toolsets.AbstractToolset.with_metadata] — see [toolset composition](toolsets.md#setting-tool-metadata).
332
+
220
333
## Building custom capabilities
221
334
222
335
To build your own capability, subclass [`AbstractCapability`][pydantic_ai.capabilities.AbstractCapability] and override the methods you need. There are two categories: **configuration methods** that are called at agent construction (except [`get_wrapper_toolset`][pydantic_ai.capabilities.AbstractCapability.get_wrapper_toolset] which is called per-run), and **lifecycle hooks** that fire during each run.
[`IncludeReturnSchemasToolset`][pydantic_ai.toolsets.IncludeReturnSchemasToolset] wraps a toolset and sets `include_return_schema=True` on all its tools, causing the model to receive return type information. For models that natively support return schemas (e.g. Google Gemini), the schema is passed as a structured API field. For other models, it is injected into the tool description as JSON text.
532
+
533
+
To easily chain different modifications, you can also call [`.include_return_schemas()`][pydantic_ai.toolsets.AbstractToolset.include_return_schemas] on any toolset instead of directly constructing an `IncludeReturnSchemasToolset`.
_(This example is complete, it can be run "as is")_
556
+
557
+
This is the toolset-level equivalent of the [`IncludeToolReturnSchemas`][pydantic_ai.capabilities.IncludeToolReturnSchemas] capability, which applies across all toolsets or a selected subset.
558
+
559
+
### Setting Tool Metadata
560
+
561
+
[`SetMetadataToolset`][pydantic_ai.toolsets.SetMetadataToolset] wraps a toolset and merges metadata key-value pairs onto all its tools. This is useful for tagging tools with configuration that other capabilities or custom logic can inspect.
562
+
563
+
To easily chain different modifications, you can also call [`.with_metadata()`][pydantic_ai.toolsets.AbstractToolset.with_metadata] on any toolset instead of directly constructing a `SetMetadataToolset`.
_(This example is complete, it can be run "as is")_
587
+
588
+
This is the toolset-level equivalent of the [`SetToolMetadata`][pydantic_ai.capabilities.SetToolMetadata] capability, which applies across all toolsets or a selected subset.
589
+
529
590
### Changing Tool Execution
530
591
531
592
[`WrapperToolset`][pydantic_ai.toolsets.WrapperToolset] wraps another toolset and delegates all responsibility to it.
0 commit comments