Skip to content

feat(ai): add toolNeedsApproval option#14480

Merged
lgrammel merged 23 commits intomainfrom
lg/vzNX0dT
Apr 16, 2026
Merged

feat(ai): add toolNeedsApproval option#14480
lgrammel merged 23 commits intomainfrom
lg/vzNX0dT

Conversation

@lgrammel
Copy link
Copy Markdown
Collaborator

@lgrammel lgrammel commented Apr 15, 2026

Background

You may want to enable or disable tool approvals for specific tools, irrespective of the tool approval setting on the tool itself. This is particularly relevant for 3rd party tools where you cannot control the needsApproval setting without wrapping the tool.

Summary

Introduce toolNeedsApproval option on generateText, streamText, and ToolLoopAgent. The toolNeedsApproval option takes precedence over the needsApproval property that might be defined on a specific tool.

Example

const result = await generateText({
  // ...
  tools: { weather },
  toolNeedsApproval: {
    weather: true, // or an approval function
  },
});

const agent = new ToolLoopAgent({
  // ...
  tools: { weather: weatherTool },
  toolNeedsApproval: { weather: true },
});

Limitations

Provider-executed tools will get executed provider-side without considering the tool approval setting.

Manual Verification

  • run / test examples/ai-functions/src/generate-text/openai/tool-approval-user-defined.ts
  • run / test examples/ai-functions/src/stream-text/openai/tool-approval-user-defined.ts
  • run / test examples/ai-functions/src/agent/openai/generate-tool-approval.ts

Future Work

  • introduce isProviderExecuted flag on tools and exclude from approval list
  • support a single catch all function for toolNeedApproval

@tigent tigent Bot added ai/core core functions like generateText, streamText, etc. Provider utils, and provider spec. feature New feature or request labels Apr 15, 2026
…alNeeded and remove obsolete is-approval-needed.ts file.
…Needed and delete unused is-approval-needed.ts file.
…configuration into streamText and createExecuteToolsTransformation functions, and update related tests for improved clarity and functionality.
…n to ToolNeedsApprovalConfiguration across multiple files and remove obsolete tool-approval-configuration.ts and related test file.
…tency and clarity, updating related logic and tests accordingly.
…pe definitions, enhance tests for approval handling in generate and stream methods, and clarify approval logic in comments.
@lgrammel lgrammel changed the title Lg/vz nx0d t feat(ai): add toolNeedsApproval option Apr 15, 2026
@lgrammel lgrammel marked this pull request as ready for review April 15, 2026 14:06
@lgrammel lgrammel merged commit 2a9c144 into main Apr 16, 2026
18 checks passed
@lgrammel lgrammel deleted the lg/vzNX0dT branch April 16, 2026 08:36
lgrammel added a commit that referenced this pull request Apr 20, 2026
## Background

Specifying `needsApproval` does not make sense for provider-executed
tools which run automatically on the provider side (see #14480 ). In
order to filter out provider-executed tools, we need to first
distinguish provider-defined from provider-executed tools.

A provider tool can be:
- provider-defined: the provider specifies input (and sometimes output)
schemas, but the execution function is used defined. The tool is
executed by the AI SDK.
- provider-executed: the provider specifies input and output schemas.
There is no user-defined execution function. The tool is executed by the
provider as part of their response.

## Summary

* introduce `isProviderExecuted` flag on provider tools
* split `ProviderToolFactory` and related factory functions into
`ProviderDefinedToolFactory` and `ProviderExecutedToolFactory``
* update provider tools

## Future Work

* exclude provider-executed tools from `toolNeedsApproval` function

## Related Issues

Separates provider-executed from provider-defined tools to enable fixing
the limitation from #14480
lgrammel added a commit that referenced this pull request Apr 20, 2026
# Background

We want to enhance the tool approval function to allow for automatic
accept or reject without user interaction. The name `toolApproval` is
shorter and much better aligned with that desired API.

## Summary

* rename `toolNeedsApproval` to `toolApproval`
* rename `ToolNeedsApprovalConfiguration` to `ToolApprovalConfiguration`

## Future Work

* change tool approval function outputs to "not-applicable", "approved",
"rejected", "user-approval"

## Related Issues

Builds on #14480
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai/core core functions like generateText, streamText, etc. Provider utils, and provider spec. feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants