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
@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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants