Skip to content

[dotnet-port-api] Bound tool-approval auto-approval loop #813

Description

@github-actions

Summary

Port the recent .NET tool-approval safety cap into Go by adding toolapproval.DefaultMaxAutoApprovalIterations and toolapproval.Config.MaxAutoApprovalIterations, then bounding the middleware's auto-approved reentry loop. When the cap is reached, the middleware now takes one final inner turn without auto-approving again so the caller sees the remaining approval request(s) instead of an unbounded chain of fresh model calls.

This change was selected from upstream commit 74a144085a5fd05921b473001528f3ae0725b76a because it is a small exported-API parity update with targeted regression coverage. The PR also updates the feature-comparison document to reflect the new bounded auto-approval reentry support.

Ported .NET PRs

Breaking Changes

No. Existing auto-approval behavior is preserved until the new safety cap is reached; after that point the middleware now surfaces the remaining approval request(s) to the caller instead of continuing an unbounded reentry loop.

Tests and Examples

  • go test ./agent/harness/toolapproval
  • Added regression tests for capped auto-approval reinvocation, final-turn passthrough of raw approval requests, and negative config validation.
  • No example changes were needed because the upstream .NET port did not require sample updates.

Notes

Generated by .NET to Go API Porting Agent · gpt54 · 366.5 AIC · ⌖ 13.4 AIC · ⊞ 24.1K ·


Note

This was originally intended as a pull request, but GitHub Actions is not permitted to create or approve pull requests in this repository.
The changes have been pushed to branch copilot/dotnet-port-api-toolapproval-cap-20260807-63d6566740432722.

Click here to create the pull request

To fix the permissions issue, go to SettingsActionsGeneral and enable Allow GitHub Actions to create and approve pull requests. See also: gh-aw FAQ

Show patch preview (258 of 258 lines)
From b0b90f4b1f85a8a87f5d83e78349f24ace52263d Mon Sep 17 00:00:00 2001
From: "github-actions[bot]" <github-actions[bot]@users.noreply.github.com>
Date: Fri, 7 Aug 2026 06:08:58 +0000
Subject: [PATCH] [dotnet-port-api] Bound tool-approval auto-approval loop

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
---
 agent/harness/toolapproval/toolapproval.go    |  48 +++++++-
 .../harness/toolapproval/toolapproval_test.go | 113 ++++++++++++++++++
 docs/dotnet-go-sdk-feature-comparison.md      |   2 +-
 3 files changed, 160 insertions(+), 3 deletions(-)

diff --git a/agent/harness/toolapproval/toolapproval.go b/agent/harness/toolapproval/toolapproval.go
index d07482b69..4d53ac836 100644
--- a/agent/harness/toolapproval/toolapproval.go
+++ b/agent/harness/toolapproval/toolapproval.go
@@ -26,7 +26,14 @@ import (
 	"github.com/microsoft/agent-framework-go/tool"
 )
 
-const stateKey = "toolApprovalState"
+const (
+	stateKey = "toolApprovalState"
+
+	// DefaultMaxAutoApprovalIterations is the default safety cap for how many
+	// times a single run may re-invoke the wrapped agent because every surfaced
+	// approval request was auto-approved.
+	DefaultMaxAutoApprovalIterations = 40
+)
 
 // Rule is a standing approval rule. If Arguments is nil, all invocations of
 // the named tool are auto-approved. Otherwise only invocations with an exact
@@ -79,6 +86,7 @@ func saveState(opts []agent.Option, s state) {
 // New creates a tool-approval middleware that wraps agent runs with
 // human-in-the-loop approval management.
 func New(cfg Config) agent.Middleware {
+	cfg.MaxAutoApprovalIterations = normalizeMaxAutoApprovalIterations(cfg.MaxAutoApprovalIterations)
 	return agent.MiddlewareFunc(func(next agent.RunFunc, ctx context.Context, messages []*message.Message, opts ...agent.Option) iter.Seq2[*agent.ResponseUpdate, error] {
 		return run(cfg, next, ctx, messages, opts...)
 	})
@@ -94,6 +102,14 @@ type Config struct {
 	// to be auto-approved without prompting the 
... (truncated)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions