Skip to content

[dotnet-port] Port auto-approval rules (heuristics) to toolapproval middleware - #254

Merged
qmuntal merged 6 commits into
mainfrom
dotnet-port/toolapproval-auto-approval-funcs-6f3fbaff71786421
Jun 8, 2026
Merged

[dotnet-port] Port auto-approval rules (heuristics) to toolapproval middleware#254
qmuntal merged 6 commits into
mainfrom
dotnet-port/toolapproval-auto-approval-funcs-6f3fbaff71786421

Conversation

@qmuntal

@qmuntal qmuntal commented Jun 8, 2026

Copy link
Copy Markdown
Member

Port microsoft/agent-framework#6335: add heuristic auto-approval rules to ToolApprovalAgent. AutoApprovalRules in Config lets callers provide callbacks that are evaluated after standing rules but before surfacing an approval request to the user. The first rule returning approved=true auto-approves the call without interrupting the caller; if a rule returns an error, the run fails with that error.

  • Add AutoApprovalRules []func(context.Context, *message.FunctionCallContent) (bool, error) 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 matchesAutoApprovalRules helper (first-match-wins semantics, nil entries skipped, error propagation)
  • Apply auto-approval rules in drainAutoApprovable (queued requests) and in the outbound classification loop (new requests from inner agent)
  • Propagate auto-approval rule errors from both queued-drain and classification paths
  • Update tests and docs to reflect AutoApprovalRules naming and context-aware callback signature with error return

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>
Copilot AI review requested due to automatic review settings June 8, 2026 07:30
@qmuntal
qmuntal requested a review from a team as a code owner June 8, 2026 07:30

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

This PR ports heuristic auto-approval support into the Go agent/harness/toolapproval middleware, allowing callers to provide custom predicate functions (AutoApprovalFuncs) that can auto-approve tool calls after standing rules but before surfacing approval requests to the caller.

Changes:

  • Adds Config.AutoApprovalFuncs []func(*message.FunctionCallContent) bool and threads Config through the middleware run loop.
  • Applies heuristic auto-approval both when draining queued requests and when classifying newly emitted approval requests.
  • Updates docs and adds tests for basic matching/non-matching and ordering semantics.
Show a summary per file
File Description
docs/dotnet-go-sdk-feature-comparison.md Updates the feature matrix to mention auto-approval heuristics for tool approval.
agent/harness/toolapproval/toolapproval.go Introduces AutoApprovalFuncs config and applies it in queued draining + outbound request classification.
agent/harness/toolapproval/toolapproval_test.go Adds tests covering auto-approval func behavior and ordering; includes a test naming/coverage gap around standing-rule precedence.

Copilot's findings

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

  • Files reviewed: 3/3 changed files
  • Comments generated: 4

Comment thread docs/dotnet-go-sdk-feature-comparison.md Outdated
Comment thread agent/harness/toolapproval/toolapproval.go Outdated
Comment thread agent/harness/toolapproval/toolapproval_test.go Outdated
Comment thread agent/harness/toolapproval/toolapproval_test.go Outdated
@github-actions

This comment has been minimized.

@qmuntal

qmuntal commented Jun 8, 2026

Copy link
Copy Markdown
Member Author

@copilot fix #254 (comment)

Copilot AI commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

@copilot fix #254 (comment)

Implemented in 0817fc9.

  • Clarified toolapproval.Config.AutoApprovalFuncs docs to state callbacks are synchronous and should be fast/non-blocking.
  • Updated the SDK comparison table to use toolapproval.Config{...} and explicitly note Go uses AutoApprovalFuncs while .NET uses AutoApprovalRules.

@qmuntal

qmuntal commented Jun 8, 2026

Copy link
Copy Markdown
Member Author

@copilot rename AutoApprovalFuncs to AutoApprovalRules and make the callback accept a context.Context. Undo 0817fc9.

Copilot AI commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

@copilot rename AutoApprovalFuncs to AutoApprovalRules and make the callback accept a context.Context. Undo 0817fc9...

Implemented in fd446e7 (API change) and d63a91d (follow-up terminology cleanup).

  • Renamed toolapproval.Config.AutoApprovalFuncs to AutoApprovalRules.
  • Updated callback signature to func(context.Context, *message.FunctionCallContent) bool and threaded context.Context through auto-approval evaluation paths.
  • Undid commit 0817fc9 changes and updated docs/tests to reflect the new API.

@qmuntal
qmuntal enabled auto-merge (squash) June 8, 2026 08:17
Copilot AI changed the title [dotnet-port] Port auto-approval funcs (heuristics) to toolapproval middleware [dotnet-port] Port auto-approval rules (heuristics) to toolapproval middleware Jun 8, 2026
@github-actions

This comment has been minimized.

@qmuntal

qmuntal commented Jun 8, 2026

Copy link
Copy Markdown
Member Author

@copilot AutoApprovalRules callbacks return signature should also have an error.

Copilot AI commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

@copilot AutoApprovalRules callbacks return signature should also have an error.

Implemented in 79eb87b.

AutoApprovalRules callbacks now use func(context.Context, *message.FunctionCallContent) (bool, error). Middleware now propagates callback errors (including queued-request draining and outbound classification), and tests were updated to the new signature with coverage for the error path.

@github-actions

github-actions Bot commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

Cross-Repo Parity Review

This PR ports AutoApprovalRules from the upstream .NET ToolApprovalAgentOptions (dotnet/src/Microsoft.Agents.AI/Harness/ToolApproval/ToolApprovalAgentOptions.cs) faithfully. ✅

API shape comparison

Aspect .NET Go (this PR)
Rule signature Func<FunctionCallContent, ValueTask<bool>> func(context.Context, *message.FunctionCallContent) (bool, error)
Cancellation None (no CancellationToken) context.Context (idiomatic Go)
Error propagation Exception bubbling Explicit error return (idiomatic Go)
Nil/null rules Not guarded Nil entries skipped (defensive Go pattern)
Evaluation order After standing rules, first-match-wins Same ✅
Queued-request drain Applies rules to queued requests Same ✅
Error fails run Exception unwinds run err != nil yields error and returns ✅

Verdict

The Go implementation is semantically aligned with the upstream .NET implementation. The differences (context.Context added, error return instead of exception) are idiomatic language adaptations rather than behavioral divergences. No cross-repo parity concerns.

Generated by Go API Consistency Review Agent for issue #254 · ● 6M ·

@qmuntal
qmuntal merged commit 97b0447 into main Jun 8, 2026
16 checks passed
@qmuntal
qmuntal deleted the dotnet-port/toolapproval-auto-approval-funcs-6f3fbaff71786421 branch June 8, 2026 10:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[dotnet-port] Port auto-approval funcs (heuristics) to toolapproval middleware

4 participants