.NET: Allow storage of auto-approved functions#4950
Merged
Conversation
Contributor
There was a problem hiding this comment.
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
AutoApprovedFunctionRemovingChatClientto filter/store auto-approvableToolApprovalRequestContentand re-inject them as approved on the next request. - Wires the decorator into the default
ChatClientAgentpipeline behind a newChatClientAgentOptions.StoreAutoApprovedFunctionCallsflag (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. |
SergeyMenshykh
approved these changes
Mar 27, 2026
SergeyMenshykh
approved these changes
Jun 4, 2026
peibekwe
approved these changes
Jun 4, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
Contribution Checklist