Skip to content

.NET: Allow storage of auto-approved functions - #4950

Merged
westey-m merged 5 commits into
microsoft:mainfrom
westey-m:auto-approved-function-removal
Jun 5, 2026
Merged

.NET: Allow storage of auto-approved functions#4950
westey-m merged 5 commits into
microsoft:mainfrom
westey-m:auto-approved-function-removal

Conversation

@westey-m

@westey-m westey-m commented Mar 27, 2026

Copy link
Copy Markdown
Contributor

Motivation and Context

When we have functions that require approval, and those that do not, and a mixture of the two need to be executed at the same time, we ask for approval for both, since we have no-where to store the results.
With the availability of ambient agent/session state, we can now use Agent specific ChatClient middleware to store the ones that don't require approval in the session, to avoid sending them to the user.

#4909
#6264

Description

  • Add a ChatClient decorator to store approved functions, so we don't ask the user to approve something that doesn't require approval

Contribution Checklist

  • The code builds clean without any errors or warnings
  • The PR follows the Contribution Guidelines
  • All unit tests pass, and I have added new tests where possible
  • Is this a breaking change? If yes, add "[BREAKING]" prefix to the title of the PR.

Copilot AI review requested due to automatic review settings March 27, 2026 13:39
@markwallace-microsoft markwallace-microsoft added the .NET Usage: [Issues, PRs], Target: .Net label Mar 27, 2026
@github-actions github-actions Bot changed the title Allow storage of auto-approved functions .NET: Allow storage of auto-approved functions Mar 27, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new chat-client middleware layer to support mixed tool-approval scenarios by hiding “auto-approvable” approval requests from the user while preserving them in session state for automatic approval on the next turn.

Changes:

  • Introduces AutoApprovedFunctionRemovingChatClient to filter/store auto-approvable ToolApprovalRequestContent and re-inject them as approved on the next request.
  • Wires the decorator into the default ChatClientAgent pipeline behind a new ChatClientAgentOptions.StoreAutoApprovedFunctionCalls flag (and adds a builder extension for custom stacks).
  • Adds unit tests covering non-streaming and streaming filtering/storage/injection behavior.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
dotnet/src/Microsoft.Agents.AI/ChatClient/AutoApprovedFunctionRemovingChatClient.cs New decorator that stores auto-approvable approval requests in session and re-injects them as approved responses.
dotnet/src/Microsoft.Agents.AI/ChatClient/ChatClientExtensions.cs Injects the new decorator into the default middleware pipeline when the new option is enabled.
dotnet/src/Microsoft.Agents.AI/ChatClient/ChatClientBuilderExtensions.cs Adds UseAutoApprovedFunctionRemoval() for custom chat client stacks.
dotnet/src/Microsoft.Agents.AI/ChatClient/ChatClientAgentOptions.cs Adds StoreAutoApprovedFunctionCalls option and clones it.
dotnet/tests/Microsoft.Agents.AI.UnitTests/ChatClient/AutoApprovedFunctionRemovingChatClientTests.cs New unit tests validating filtering, storage, and injection behavior.

Comment thread dotnet/src/Microsoft.Agents.AI/ChatClient/ChatClientAgentOptions.cs Outdated
@westey-m
westey-m added this pull request to the merge queue Jun 4, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jun 4, 2026
@westey-m
westey-m added this pull request to the merge queue Jun 4, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jun 4, 2026
@westey-m
westey-m added this pull request to the merge queue Jun 4, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jun 4, 2026
@westey-m
westey-m added this pull request to the merge queue Jun 4, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jun 4, 2026
@westey-m
westey-m added this pull request to the merge queue Jun 5, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jun 5, 2026
@westey-m
westey-m added this pull request to the merge queue Jun 5, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jun 5, 2026
@westey-m
westey-m merged commit ab8ba8f into microsoft:main Jun 5, 2026
26 checks passed
github-actions Bot added a commit to microsoft/agent-framework-go that referenced this pull request Jun 8, 2026
When toolautocall converts all FunctionCallContents to ToolApprovalRequestContent
(because any tool requires approval), the toolapproval middleware now automatically
approves requests for tools that are not marked as approval-required via
tool.ApprovalRequiredTool.

This mirrors the behavior of .NET's NonApprovalRequiredFunctionBypassingChatClient
(microsoft/agent-framework#4950): callers only see approval requests for tools that
genuinely require human sign-off. Non-approval-required requests are silently
collected and forwarded to the inner agent on the next round.

The new isNotApprovalRequired helper is conservative: it returns false (requiring
approval) when the tool cannot be found in opts, so the change is backward-compatible
with callers that do not register tools via agent.WithTool.

drainAutoApprovable also applies the same check so queued non-approval-required
requests (enqueued in a prior turn when the tool was not yet registered) are drained
automatically without user intervention.

Add two tests covering:
- Mixed approval batch: only approval-required deploy is surfaced; non-approval-required list is auto-approved.
- Queued drain: a previously queued list request is drained on the next turn once list is registered as non-approval-required.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
qmuntal added a commit to microsoft/agent-framework-go that referenced this pull request Jun 8, 2026
…es (#256)

When toolautocall converts all FunctionCallContents to ToolApprovalRequestContent
(because any tool requires approval), the toolapproval middleware now automatically
approves requests for tools that are not marked as approval-required via
tool.ApprovalRequiredTool.

This mirrors the behavior of .NET's NonApprovalRequiredFunctionBypassingChatClient
(microsoft/agent-framework#4950): callers only see approval requests for tools that
genuinely require human sign-off. Non-approval-required requests are silently
collected and forwarded to the inner agent on the next round.

The new isNotApprovalRequired helper is conservative: it returns false (requiring
approval) when the tool cannot be found in opts, so the change is backward-compatible
with callers that do not register tools via agent.WithTool.

drainAutoApprovable also applies the same check so queued non-approval-required
requests (enqueued in a prior turn when the tool was not yet registered) are drained
automatically without user intervention.

Add two tests covering:
- Mixed approval batch: only approval-required deploy is surfaced; non-approval-required list is auto-approved.
- Queued drain: a previously queued list request is drained on the next turn once list is registered as non-approval-required.

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

.NET Usage: [Issues, PRs], Target: .Net

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants