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

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

Copy link
Copy Markdown
Contributor

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 Usage: [Issues, PRs], Target: .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

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 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

@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: 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
github-actions Bot added a commit to microsoft/agent-framework-go that referenced this pull request Jun 6, 2026
Port microsoft/agent-framework#6335: add heuristic auto-approval rules to
ToolApprovalAgent. AutoApprovalFuncs in Config lets callers provide predicate
functions that are evaluated after standing rules but before surfacing an
approval request to the user. The first function returning true auto-approves
the call without interrupting the caller.

- Add AutoApprovalFuncs []func(*message.FunctionCallContent) bool to Config
- Change New to capture cfg via closure instead of ignoring it
- Change run to accept Config and thread it through to drainAutoApprovable
- Add matchesAutoApprovalFuncs helper (first-match-wins semantics)
- Apply auto-approval funcs in drainAutoApprovable (queued requests) and in
  the outbound classification loop (new requests from inner agent)
- Add 5 tests covering: matching, non-matching, first-match-wins, queued
  request drain, and standing-rule precedence

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
qmuntal added a commit to microsoft/agent-framework-go that referenced this pull request Jun 8, 2026
…iddleware (#254)

* feat(toolapproval): add auto-approval funcs (heuristics) to Config

Port microsoft/agent-framework#6335: add heuristic auto-approval rules to
ToolApprovalAgent. AutoApprovalFuncs in Config lets callers provide predicate
functions that are evaluated after standing rules but before surfacing an
approval request to the user. The first function returning true auto-approves
the call without interrupting the caller.

- Add AutoApprovalFuncs []func(*message.FunctionCallContent) bool to Config
- Change New to capture cfg via closure instead of ignoring it
- Change run to accept Config and thread it through to drainAutoApprovable
- Add matchesAutoApprovalFuncs helper (first-match-wins semantics)
- Apply auto-approval funcs in drainAutoApprovable (queued requests) and in
  the outbound classification loop (new requests from inner agent)
- Add 5 tests covering: matching, non-matching, first-match-wins, queued
  request drain, and standing-rule precedence

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* docs(toolapproval): clarify auto-approval callback expectations and naming parity note

* refactor(toolapproval): rename auto approval rules and pass context

* docs(toolapproval): align config comment terminology with AutoApprovalRules

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

.NET Usage: [Issues, PRs], Target: .Net

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow configuring the approval agent with heuristics

5 participants