Skip to content

.NET: Scope argument-based standing approvals correctly in ToolApprovalAgent#6487

Open
rogerbarreto wants to merge 1 commit into
microsoft:mainfrom
rogerbarreto:issues/6486-net-toolapproval-arg-scoping
Open

.NET: Scope argument-based standing approvals correctly in ToolApprovalAgent#6487
rogerbarreto wants to merge 1 commit into
microsoft:mainfrom
rogerbarreto:issues/6486-net-toolapproval-arg-scoping

Conversation

@rogerbarreto

Copy link
Copy Markdown
Member

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 of null when the approved call has no arguments, so it matches only future no-argument calls. null stays reserved exclusively for tool-level approvals, keeping the two scopes distinct. Aligns .NET behavior with the existing Python harness.

Changes

  • ToolApprovalAgent.SerializeArguments returns a non-null (empty) dictionary for empty/null args.
  • Clarified XML docs on ToolApprovalRule.Arguments semantics.
  • Regression tests: no-argument standing-approval flow, MatchesRule argument scoping, empty-args rule serialization.

Validation

  • Build: 0 warnings / 0 errors.
  • Tests: 1652 (net10.0) + 1542 (net472) pass.
  • dotnet format clean on changed projects.

…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>
Copilot AI review requested due to automatic review settings June 11, 2026 20:41
@moonbox3 moonbox3 added the .NET label Jun 11, 2026
@rogerbarreto rogerbarreto self-assigned this Jun 11, 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

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.SerializeArguments to 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.Arguments XML documentation to explicitly define null vs 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.

@github-actions github-actions Bot 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.

Automated Code Review

Reviewers: 5 | Confidence: 94% | Result: All clear

Reviewed: Correctness, Security Reliability, Test Coverage, Failure Modes, Design Approach


Automated review by rogerbarreto's agents

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.

Python: .NET: Harden argument scoping for standing approval rules in ToolApprovalAgent

5 participants