.NET: Scope argument-based standing approvals correctly in ToolApprovalAgent#6487
Open
rogerbarreto wants to merge 1 commit into
Open
.NET: Scope argument-based standing approvals correctly in ToolApprovalAgent#6487rogerbarreto wants to merge 1 commit into
rogerbarreto wants to merge 1 commit into
Conversation
…alAgent (microsoft#6486) Ensure an argument-scoped standing approval (the "always approve with exact arguments" path) records an empty argument set rather than null when the approved call has no arguments, so it matches only future no-argument calls. null remains reserved exclusively for tool-level approvals, keeping the two scopes distinct. This aligns the .NET behavior with the existing Python harness. Adds regression tests covering the no-argument standing-approval flow, the MatchesRule argument-scoping semantics, and empty-arguments rule serialization. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a scoping bug in the .NET tool-approval harness where an “always approve with exact arguments” standing approval for a no-argument tool call was being stored with null arguments, unintentionally widening it to a tool-level approval. The change ensures no-argument argument-scoped approvals are persisted as an empty argument set ({}), preserving the intended narrow scope and aligning behavior with the existing Python harness.
Changes:
- Update
ToolApprovalAgent.SerializeArgumentsto always return a non-null dictionary (empty when the call has no arguments) so argument-scoped rules never serialize as tool-level rules. - Clarify
ToolApprovalRule.ArgumentsXML documentation to explicitly definenullvs empty-dictionary semantics. - Add regression tests covering empty-args rule serialization round-trips and empty-args matching/auto-approval behavior.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| dotnet/src/Microsoft.Agents.AI/Harness/ToolApproval/ToolApprovalAgent.cs | Ensures argument serialization for standing approvals returns {} (not null) for no-arg calls, preserving argument-scoped rule semantics. |
| dotnet/src/Microsoft.Agents.AI/Harness/ToolApproval/ToolApprovalRule.cs | Documents the intended distinction: null = tool-level; empty dict = no-argument exact-match scope. |
| dotnet/tests/Microsoft.Agents.AI.UnitTests/Harness/ToolApproval/ToolApprovalAgentTests.cs | Adds regression tests verifying empty-args exact-approval does not auto-approve later argument-bearing calls, but does auto-approve later no-arg calls. |
| dotnet/tests/Microsoft.Agents.AI.UnitTests/Harness/ToolApproval/ToolApprovalRuleTests.cs | Adds a round-trip serialization test proving empty-args rules persist as non-null empty dictionaries. |
westey-m
approved these changes
Jun 12, 2026
SergeyMenshykh
approved these changes
Jun 12, 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.
Fixes #6486
Scopes argument-based standing approvals correctly in
ToolApprovalAgent. An argument-scoped standing approval (the "always approve with exact arguments" path) now records an empty argument set instead ofnullwhen the approved call has no arguments, so it matches only future no-argument calls.nullstays reserved exclusively for tool-level approvals, keeping the two scopes distinct. Aligns .NET behavior with the existing Python harness.Changes
ToolApprovalAgent.SerializeArgumentsreturns a non-null (empty) dictionary for empty/null args.ToolApprovalRule.Argumentssemantics.MatchesRuleargument scoping, empty-args rule serialization.Validation
dotnet formatclean on changed projects.