Apply `FunctionToolset(requires_approval=True)` to `Tool` instances passed to the toolset

Merged
DS
1mo ago
+70-1

This pull request was posted by Claude Code using claude-opus-5-5 on behalf of David.

FunctionToolset(requires_approval=True) applied requires_approval to tools added as functions, but not to Tool instances passed to the constructor or to add_tool(), although its docstring says it applies to all tools. Those tools ran without a deferred approval request. add_tool() now applies the toolset's requires_approval=True to the tool, as it already applies max_retries and metadata.

[!WARNING]
Compatibility impact: Existing code that gives Tool instances to a FunctionToolset(requires_approval=True) and relies on them running without approval now gets an approval request in DeferredToolRequests for each call. This includes a Tool built with requires_approval=False, and the same Tool instance used in another toolset: the value is set on the instance, as add_tool() already does for max_retries and metadata.

Why this can ship in a minor release: It's a bug fix. The requires_approval docstring says it applies to all tools in the toolset; skipping Tool instances was undocumented behavior.

Migration: Handle the approval request as described in Human-in-the-Loop Tool Approval, or remove requires_approval from the toolset and set it on each tool that needs it.

New public surface

None.

User-visible behavior

toolset = FunctionToolset([Tool(my_tool)], requires_approval=True)
agent = Agent(model, toolsets=[toolset], output_type=[str, DeferredToolRequests])
result = agent.run_sync('Run the tool')
# before: my_tool runs, result.output is the model's text
# after:  my_tool doesn't run, result.output == DeferredToolRequests(approvals=[ToolCallPart('my_tool', ...)])

A function added with add_function(..., requires_approval=False) or @toolset.tool(requires_approval=False) still opts out, and still goes through add_tool(), so a subclass that overrides add_tool() sees every tool.

Verification

What changes for existing users

Tool instances in a FunctionToolset(requires_approval=True) now need approval, like the toolset's functions already did.

PR decisions

2026-11-03 · add_function() keeps going through add_tool()

  • Decision: add_tool() sets requires_approval=True when the toolset's is True. add_function() and the decorators still call self.add_tool(), then write back their resolved requires_approval, so an explicit False holds.
  • Why: routing add_function() through a private method instead would hide its tools from a subclass that overrides add_tool(); widening Tool.requires_approval to bool | None would change a public attribute type.
  • Session: 4152248f-72b2-47ea-acf7-2c8034a2fd1f

2026-11-03 · Tool.requires_approval stays bool

  • Decision: a Tool built with requires_approval=False and given to a requires_approval=True toolset now requires approval.
  • Why: a bool attribute can't tell the default from an explicit False; per-tool opt-out stays with add_function() and the decorators.
  • Session: 4152248f-72b2-47ea-acf7-2c8034a2fd1f

2026-11-03 · Set the value on the passed Tool

  • Decision: add_tool() writes requires_approval onto the Tool it's given, as it already does for max_retries and metadata.
  • Why: keeps the Tool that add_function() returns identical to the one in toolset.tools.
  • Session: 4152248f-72b2-47ea-acf7-2c8034a2fd1f

2026-11-03 · Keep resolving requires_approval in add_tool(), not at listing time

  • Decision: keep writing the value onto the Tool, instead of resolving it in get_tools() from a set of opted-out names.
  • Why: the ACP adapter reads Tool.requires_approval from toolset.tools, so listing-time resolution would leave it reporting these tools as not needing approval.
  • Source: https://github.com/pydantic/pydantic-ai/pull/12378#discussion_r4460768226
  • Session: 4152248f-72b2-47ea-acf7-2c8034a2fd1f

Checklist

  • No breaking changes in accordance with the version policy.
  • Any permitted compatibility impact has a label, warning, migration and release note, and an exact API-check waiver if the gate reports it.
  • PR title is fit for the release changelog.