-
Notifications
You must be signed in to change notification settings - Fork 2.1k
.NET: [BREAKING] Add auto-approval rules (heuristics) to ToolApprovalAgent #6335
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
westey-m
merged 5 commits into
microsoft:main
from
westey-m:harness-heuristic-tool-approval
Jun 5, 2026
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
b8ac819
Add support for approving tools via heuristic rules
westey-m 619e447
Address PR comments
westey-m 2869eef
Address PR comments
westey-m 2823554
Apply suggestion from @SergeyMenshykh
westey-m bec17b5
Merge branch 'main' into harness-heuristic-tool-approval
westey-m File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
45 changes: 45 additions & 0 deletions
45
dotnet/src/Microsoft.Agents.AI/Harness/ToolApproval/ToolApprovalAgentOptions.cs
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| // Copyright (c) Microsoft. All rights reserved. | ||
|
|
||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Diagnostics.CodeAnalysis; | ||
| using System.Text.Json; | ||
| using System.Threading.Tasks; | ||
| using Microsoft.Extensions.AI; | ||
| using Microsoft.Shared.DiagnosticIds; | ||
|
|
||
| namespace Microsoft.Agents.AI; | ||
|
|
||
| /// <summary> | ||
| /// Options for configuring the <see cref="ToolApprovalAgent"/> middleware. | ||
| /// </summary> | ||
| [Experimental(DiagnosticIds.Experiments.AgentsAIExperiments)] | ||
| public class ToolApprovalAgentOptions | ||
| { | ||
| /// <summary> | ||
| /// Gets or sets the <see cref="System.Text.Json.JsonSerializerOptions"/> used for serializing argument values | ||
| /// when storing rules and for persisting state. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// When <see langword="null"/>, <see cref="AgentJsonUtilities.DefaultOptions"/> is used. | ||
| /// </remarks> | ||
| public JsonSerializerOptions? JsonSerializerOptions { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets a collection of heuristic functions that can automatically approve function calls | ||
| /// that would otherwise require user approval. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// <para> | ||
| /// Each function receives a <see cref="FunctionCallContent"/> representing the tool call that requires approval | ||
| /// and returns a <see cref="ValueTask{Boolean}"/> that resolves to <see langword="true"/> to auto-approve | ||
| /// the call, or <see langword="false"/> to continue evaluating the next rule. | ||
| /// </para> | ||
| /// <para> | ||
| /// Auto-approval rules are evaluated after standing rules (derived from prior user approvals) but before | ||
| /// prompting the user. Rules are evaluated in order; the first rule returning <see langword="true"/> | ||
| /// causes the function call to be auto-approved. | ||
| /// </para> | ||
| /// </remarks> | ||
| public IEnumerable<Func<FunctionCallContent, ValueTask<bool>>>? AutoApprovalRules { get; set; } | ||
| } |
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.