Skip to content

.NET: [BREAKING] Graduate ToolApprovalAgent and add ToolAutoApprovalRuleContext#7107

Open
westey-m wants to merge 2 commits into
microsoft:mainfrom
westey-m:dotnet-gradudate-toolapprovalagent
Open

.NET: [BREAKING] Graduate ToolApprovalAgent and add ToolAutoApprovalRuleContext#7107
westey-m wants to merge 2 commits into
microsoft:mainfrom
westey-m:dotnet-gradudate-toolapprovalagent

Conversation

@westey-m

Copy link
Copy Markdown
Contributor

Motivation & Context

The Harness agent (HarnessAgent) is being prepared for release, but it depends on the
tool-approval feature which was still marked experimental. This PR graduates
ToolApprovalAgent and its related public types out of experimental status so they can ship
as part of the supported surface.

It also makes the auto-approval extension point future-proof. Auto-approval rules previously
received only a FunctionCallContent, which cannot gain additional inputs without breaking
every rule. Wrapping the input in a context object lets us add fields over time without
further breaking changes.

Part of the harness dependency graduation tracked by #6964.

Description & Review Guide

  • What are the major changes?

    • Removed the [Experimental] attribute (and now-unused usings) from the ToolApproval
      public types: ToolApprovalAgent, ToolApprovalAgentOptions,
      ToolApprovalAgentBuilderExtensions, ToolApprovalRule,
      AlwaysApproveToolApprovalResponseContent, ToolApprovalRequestContentExtensions,
      ToolApprovalState.
    • Added a new public ToolAutoApprovalRuleContext that wraps the FunctionCallContent
      together with the surrounding run context (Agent, Session, RequestMessages,
      RunOptions), mirroring AgentRunContext.
    • Changed the auto-approval rule delegate from
      Func<FunctionCallContent, ValueTask<bool>> to
      Func<ToolAutoApprovalRuleContext, ValueTask<bool>> on
      ToolApprovalAgentOptions.AutoApprovalRules and the built-in rules
      (ToolApprovalAgent.AllToolsAutoApprovalRule, and the ReadOnly/AllTools rules on
      FileAccessProvider and AgentSkillsProvider).
    • Threaded the run context (session, run options, request messages) through the
      ToolApprovalAgent run/streaming/queue-drain paths so it can be supplied to rules.
  • What is the impact of these changes?

    • Breaking: the auto-approval rule delegate signature changed and the previously
      experimental types are now GA. Custom rules that used the FunctionCallContent parameter
      must now read context.FunctionCallContent.
    • The new context type allows additional fields to be added later without further breaking
      changes.
  • What do you want reviewers to focus on?

    • The context plumbing in ToolApprovalAgent — that Agent/Session/RequestMessages/
      RunOptions are correctly populated on every code path (non-streaming, streaming, and the
      queued-request drain).

Related Issue

Related to #6964

Contribution Checklist

  • The code builds clean without any errors or warnings
  • All unit tests pass, and I have added new tests where possible
  • The PR follows the Contribution Guidelines
  • This PR is linked to an issue and there is no other open PR for this issue (see Related Issue above).
  • This is not a breaking change. If it is a breaking change, add the breaking change label (or add "[BREAKING]" to the title prefix, before or after any language prefix) — a workflow keeps the label and title prefix in sync automatically.

Copilot AI review requested due to automatic review settings July 14, 2026 10:30
@westey-m westey-m marked this pull request as ready for review July 14, 2026 10:30
@giles17 giles17 added .NET Usage: [Issues, PRs], Target: .Net breaking change Usage: [PRs], Target: all PRs that introduce changes that are not backward compatible labels Jul 14, 2026

@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: 91% | Result: All clear

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


Automated review by westey-m's agents

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

Graduates the .NET ToolApprovalAgent surface from experimental to GA and introduces a new ToolAutoApprovalRuleContext so tool auto-approval rules can evolve without further breaking delegate signature changes.

Changes:

  • Removes [Experimental] from tool-approval public surface types and cleans up now-unused usings.
  • Introduces ToolAutoApprovalRuleContext and updates auto-approval rules from Func<FunctionCallContent, ValueTask<bool>> to Func<ToolAutoApprovalRuleContext, ValueTask<bool>>.
  • Threads run context (session, request messages, run options) through ToolApprovalAgent so rules can access it; updates tests/samples accordingly.

Reviewed changes

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

Show a summary per file
File Description
dotnet/tests/Microsoft.Agents.AI.UnitTests/Harness/ToolApproval/ToolApprovalAgentTests.cs Updates tests for new auto-approval rule delegate signature.
dotnet/tests/Microsoft.Agents.AI.UnitTests/Harness/FileAccess/FileAccessProviderTests.cs Updates file-access auto-approval rule tests to use the new context parameter.
dotnet/tests/Microsoft.Agents.AI.UnitTests/AgentSkills/AgentSkillsProviderTests.cs Updates skills-provider auto-approval rule tests to use the new context parameter.
dotnet/tests/Microsoft.Agents.AI.Harness.UnitTests/HarnessAgentTests.cs Updates harness agent test to use context.FunctionCallContent in auto-approval rules.
dotnet/src/Microsoft.Agents.AI/Skills/AgentSkillsProvider.cs Updates built-in skills auto-approval rules to accept ToolAutoApprovalRuleContext.
dotnet/src/Microsoft.Agents.AI/Harness/ToolApproval/ToolAutoApprovalRuleContext.cs Adds the new public context wrapper type for auto-approval rules.
dotnet/src/Microsoft.Agents.AI/Harness/ToolApproval/ToolApprovalState.cs Removes experimental annotation/usings from persisted state type.
dotnet/src/Microsoft.Agents.AI/Harness/ToolApproval/ToolApprovalRule.cs Removes experimental annotation/usings from standing rule model type.
dotnet/src/Microsoft.Agents.AI/Harness/ToolApproval/ToolApprovalRequestContentExtensions.cs Removes experimental annotation/usings from the extension surface.
dotnet/src/Microsoft.Agents.AI/Harness/ToolApproval/ToolApprovalAgentOptions.cs Changes AutoApprovalRules type to accept the new context object and updates docs.
dotnet/src/Microsoft.Agents.AI/Harness/ToolApproval/ToolApprovalAgentBuilderExtensions.cs Removes experimental annotation/usings from builder extensions.
dotnet/src/Microsoft.Agents.AI/Harness/ToolApproval/ToolApprovalAgent.cs Threads run context through run/streaming/queue-drain paths and applies rules via the new context.
dotnet/src/Microsoft.Agents.AI/Harness/ToolApproval/AlwaysApproveToolApprovalResponseContent.cs Removes experimental annotation/usings from approval response content type.
dotnet/src/Microsoft.Agents.AI/Harness/FileAccess/FileAccessProvider.cs Updates built-in file-access auto-approval rules to accept ToolAutoApprovalRuleContext.
dotnet/samples/02-agents/Harness/Harness_Step05_Loop/Program.cs Updates sample auto-approval rule to use context.FunctionCallContent.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking change Usage: [PRs], Target: all PRs that introduce changes that are not backward compatible .NET Usage: [Issues, PRs], Target: .Net

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants