Skip to content

.NET: [BREAKING] Add auto-approval rules (heuristics) to ToolApprovalAgent#6335

Merged
westey-m merged 5 commits into
microsoft:mainfrom
westey-m:harness-heuristic-tool-approval
Jun 5, 2026
Merged

.NET: [BREAKING] Add auto-approval rules (heuristics) to ToolApprovalAgent#6335
westey-m merged 5 commits into
microsoft:mainfrom
westey-m:harness-heuristic-tool-approval

Conversation

@westey-m
Copy link
Copy Markdown
Contributor

@westey-m westey-m commented Jun 4, 2026

Summary

Adds configurable auto-approval rules to ToolApprovalAgent, allowing users to supply heuristic functions that can automatically approve function calls without user interaction.

Closes #6083

Changes

New: ToolApprovalAgentOptions class

  • JsonSerializerOptions? — moved from the constructor parameter
  • IEnumerable<Func<FunctionCallContent, ValueTask<bool>>>? AutoApprovalRules — heuristic functions for auto-approving tool calls

Updated: ToolApprovalAgent

  • Constructor now accepts ToolApprovalAgentOptions? instead of JsonSerializerOptions?
  • Auto-approval rules are evaluated after standing rules (from prior user approvals) but before prompting the user
  • Rules are evaluated in order; first true result auto-approves the call
  • Async support via ValueTask<bool> return type

Updated: UseToolApproval extension

  • Now accepts ToolApprovalAgentOptions? instead of JsonSerializerOptions?

Updated: HarnessAgent

  • Added ToolApprovalAgentOptions? property to HarnessAgentOptions
  • Passed through to UseToolApproval() for easy configuration

Evaluation Order

For each ToolApprovalRequestContent:

  1. Standing rules (existing "don't ask again" behavior) → auto-approve
  2. AutoApprovalRules heuristics in order → first true auto-approves
  3. Nothing matches → return to user for manual approval

Tests

  • 5 new tests for auto-approval rules (rule approves, rule doesn't match, multiple rules first-match-wins, standing rules take precedence, streaming path)
  • 1 new HarnessAgent test for options pass-through
  • All existing tests updated for new API signature

Copilot AI review requested due to automatic review settings June 4, 2026 14:56
@moonbox3 moonbox3 added the .NET label Jun 4, 2026
@github-actions github-actions Bot changed the title Add auto-approval rules (heuristics) to ToolApprovalAgent .NET: Add auto-approval rules (heuristics) to ToolApprovalAgent Jun 4, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds configurable auto-approval heuristics to the .NET ToolApprovalAgent pipeline, enabling tool calls to be auto-approved (after standing “don’t ask again” rules, before prompting the user), and threads these options through UseToolApproval() and HarnessAgent.

Changes:

  • Introduces ToolApprovalAgentOptions to configure both JsonSerializerOptions and ordered AutoApprovalRules.
  • Updates ToolApprovalAgent to evaluate heuristic rules in both non-streaming and streaming flows.
  • Plumbs ToolApprovalAgentOptions through UseToolApproval() and HarnessAgentOptions.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
dotnet/src/Microsoft.Agents.AI/Harness/ToolApproval/ToolApprovalAgentOptions.cs Adds new options type including AutoApprovalRules.
dotnet/src/Microsoft.Agents.AI/Harness/ToolApproval/ToolApprovalAgent.cs Implements heuristic evaluation (standing rules → heuristics → prompt) in both run paths.
dotnet/src/Microsoft.Agents.AI/Harness/ToolApproval/ToolApprovalAgentBuilderExtensions.cs Switches UseToolApproval to accept ToolApprovalAgentOptions.
dotnet/src/Microsoft.Agents.AI.Harness/HarnessAgentOptions.cs Adds ToolApprovalAgentOptions pass-through property.
dotnet/src/Microsoft.Agents.AI.Harness/HarnessAgent.cs Passes ToolApprovalAgentOptions into UseToolApproval().
dotnet/tests/Microsoft.Agents.AI.UnitTests/Harness/ToolApproval/ToolApprovalAgentTests.cs Updates constructor test + adds heuristic coverage for run and streaming paths.
dotnet/tests/Microsoft.Agents.AI.UnitTests/Harness/ToolApproval/ToolApprovalAgentBuilderExtensionsTests.cs Updates extension tests for new options parameter.
dotnet/tests/Microsoft.Agents.AI.Harness.UnitTests/HarnessAgentTests.cs Adds a new test intended to validate options pass-through.

Comment thread dotnet/src/Microsoft.Agents.AI/Harness/ToolApproval/ToolApprovalAgent.cs Outdated
Comment thread dotnet/tests/Microsoft.Agents.AI.Harness.UnitTests/HarnessAgentTests.cs Outdated
Copy link
Copy Markdown

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

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

Automated Code Review

Reviewers: 4 | Confidence: 82% | Result: All clear

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


Automated review by westey-m's agents

@westey-m westey-m changed the title .NET: Add auto-approval rules (heuristics) to ToolApprovalAgent .NET: [BREAKING] Add auto-approval rules (heuristics) to ToolApprovalAgent Jun 4, 2026
Comment thread dotnet/src/Microsoft.Agents.AI/Harness/ToolApproval/ToolApprovalAgent.cs Outdated
westey-m and others added 2 commits June 5, 2026 10:25
Co-authored-by: SergeyMenshykh <68852919+SergeyMenshykh@users.noreply.github.com>
@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
@westey-m westey-m removed this pull request from the merge queue due to a manual request 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 6bd2cfe into microsoft:main Jun 5, 2026
27 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.

Allow configuring the approval agent with heuristics

5 participants