@@ -45,31 +45,49 @@ def __init__(
4545 tools : Sequence [Tool [AgentDepsT ] | ToolFuncEither [AgentDepsT , ...]] = [],
4646 * ,
4747 max_retries : int = 1 ,
48- id : str | None = None ,
4948 docstring_format : DocstringFormat = 'auto' ,
5049 require_parameter_descriptions : bool = False ,
5150 schema_generator : type [GenerateJsonSchema ] = GenerateToolJsonSchema ,
51+ strict : bool | None = None ,
52+ sequential : bool = False ,
53+ requires_approval : bool = False ,
54+ metadata : dict [str , Any ] | None = None ,
55+ id : str | None = None ,
5256 ):
5357 """Build a new function toolset.
5458
5559 Args:
5660 tools: The tools to add to the toolset.
5761 max_retries: The maximum number of retries for each tool during a run.
58- 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,
59- in which case the ID will be used to identify the toolset's activities within the workflow.
62+ Applies to all tools, unless overridden when adding a tool.
6063 docstring_format: Format of tool docstring, see [`DocstringFormat`][pydantic_ai.tools.DocstringFormat].
6164 Defaults to `'auto'`, such that the format is inferred from the structure of the docstring.
6265 Applies to all tools, unless overridden when adding a tool.
6366 require_parameter_descriptions: If True, raise an error if a parameter description is missing. Defaults to False.
6467 Applies to all tools, unless overridden when adding a tool.
6568 schema_generator: The JSON schema generator class to use for this tool. Defaults to `GenerateToolJsonSchema`.
6669 Applies to all tools, unless overridden when adding a tool.
70+ strict: Whether to enforce JSON schema compliance (only affects OpenAI).
71+ See [`ToolDefinition`][pydantic_ai.tools.ToolDefinition] for more info.
72+ sequential: Whether the function requires a sequential/serial execution environment. Defaults to False.
73+ Applies to all tools, unless overridden when adding a tool.
74+ requires_approval: Whether this tool requires human-in-the-loop approval. Defaults to False.
75+ See the [tools documentation](../deferred-tools.md#human-in-the-loop-tool-approval) for more info.
76+ Applies to all tools, unless overridden when adding a tool.
77+ metadata: Optional metadata for the tool. This is not sent to the model but can be used for filtering and tool behavior customization.
78+ Applies to all tools, unless overridden when adding a tool, which will be merged with the toolset's metadata.
79+ 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,
80+ in which case the ID will be used to identify the toolset's activities within the workflow.
6781 """
6882 self .max_retries = max_retries
6983 self ._id = id
7084 self .docstring_format = docstring_format
7185 self .require_parameter_descriptions = require_parameter_descriptions
7286 self .schema_generator = schema_generator
87+ self .strict = strict
88+ self .sequential = sequential
89+ self .requires_approval = requires_approval
90+ self .metadata = metadata
7391
7492 self .tools = {}
7593 for tool in tools :
@@ -97,8 +115,8 @@ def tool(
97115 require_parameter_descriptions : bool | None = None ,
98116 schema_generator : type [GenerateJsonSchema ] | None = None ,
99117 strict : bool | None = None ,
100- sequential : bool = False ,
101- requires_approval : bool = False ,
118+ sequential : bool | None = None ,
119+ requires_approval : bool | None = None ,
102120 metadata : dict [str , Any ] | None = None ,
103121 ) -> Callable [[ToolFuncEither [AgentDepsT , ToolParams ]], ToolFuncEither [AgentDepsT , ToolParams ]]: ...
104122
@@ -114,8 +132,8 @@ def tool(
114132 require_parameter_descriptions : bool | None = None ,
115133 schema_generator : type [GenerateJsonSchema ] | None = None ,
116134 strict : bool | None = None ,
117- sequential : bool = False ,
118- requires_approval : bool = False ,
135+ sequential : bool | None = None ,
136+ requires_approval : bool | None = None ,
119137 metadata : dict [str , Any ] | None = None ,
120138 ) -> Any :
121139 """Decorator to register a tool function which takes [`RunContext`][pydantic_ai.tools.RunContext] as its first argument.
@@ -165,10 +183,14 @@ async def spam(ctx: RunContext[str], y: float) -> float:
165183 If `None`, the default value is determined by the toolset.
166184 strict: Whether to enforce JSON schema compliance (only affects OpenAI).
167185 See [`ToolDefinition`][pydantic_ai.tools.ToolDefinition] for more info.
186+ If `None`, the default value is determined by the toolset.
168187 sequential: Whether the function requires a sequential/serial execution environment. Defaults to False.
188+ If `None`, the default value is determined by the toolset.
169189 requires_approval: Whether this tool requires human-in-the-loop approval. Defaults to False.
170190 See the [tools documentation](../deferred-tools.md#human-in-the-loop-tool-approval) for more info.
191+ If `None`, the default value is determined by the toolset.
171192 metadata: Optional metadata for the tool. This is not sent to the model but can be used for filtering and tool behavior customization.
193+ If `None`, the default value is determined by the toolset. If provided, it will be merged with the toolset's metadata.
172194 """
173195
174196 def tool_decorator (
@@ -204,8 +226,8 @@ def add_function(
204226 require_parameter_descriptions : bool | None = None ,
205227 schema_generator : type [GenerateJsonSchema ] | None = None ,
206228 strict : bool | None = None ,
207- sequential : bool = False ,
208- requires_approval : bool = False ,
229+ sequential : bool | None = None ,
230+ requires_approval : bool | None = None ,
209231 metadata : dict [str , Any ] | None = None ,
210232 ) -> None :
211233 """Add a function as a tool to the toolset.
@@ -232,17 +254,27 @@ def add_function(
232254 If `None`, the default value is determined by the toolset.
233255 strict: Whether to enforce JSON schema compliance (only affects OpenAI).
234256 See [`ToolDefinition`][pydantic_ai.tools.ToolDefinition] for more info.
257+ If `None`, the default value is determined by the toolset.
235258 sequential: Whether the function requires a sequential/serial execution environment. Defaults to False.
259+ If `None`, the default value is determined by the toolset.
236260 requires_approval: Whether this tool requires human-in-the-loop approval. Defaults to False.
237261 See the [tools documentation](../deferred-tools.md#human-in-the-loop-tool-approval) for more info.
262+ If `None`, the default value is determined by the toolset.
238263 metadata: Optional metadata for the tool. This is not sent to the model but can be used for filtering and tool behavior customization.
264+ If `None`, the default value is determined by the toolset. If provided, it will be merged with the toolset's metadata.
239265 """
240266 if docstring_format is None :
241267 docstring_format = self .docstring_format
242268 if require_parameter_descriptions is None :
243269 require_parameter_descriptions = self .require_parameter_descriptions
244270 if schema_generator is None :
245271 schema_generator = self .schema_generator
272+ if strict is None :
273+ strict = self .strict
274+ if sequential is None :
275+ sequential = self .sequential
276+ if requires_approval is None :
277+ requires_approval = self .requires_approval
246278
247279 tool = Tool [AgentDepsT ](
248280 func ,
@@ -270,6 +302,8 @@ def add_tool(self, tool: Tool[AgentDepsT]) -> None:
270302 raise UserError (f'Tool name conflicts with existing tool: { tool .name !r} ' )
271303 if tool .max_retries is None :
272304 tool .max_retries = self .max_retries
305+ if self .metadata is not None :
306+ tool .metadata = self .metadata | (tool .metadata or {})
273307 self .tools [tool .name ] = tool
274308
275309 async def get_tools (self , ctx : RunContext [AgentDepsT ]) -> dict [str , ToolsetTool [AgentDepsT ]]:
0 commit comments