Skip to content

Python: Defer provider-injected approvals to in-run execution - #7410

Merged
eavanvalkenburg merged 2 commits into
microsoft:mainfrom
eavanvalkenburg:python-agui-provider-approval-deferral
Jul 30, 2026
Merged

Python: Defer provider-injected approvals to in-run execution#7410
eavanvalkenburg merged 2 commits into
microsoft:mainfrom
eavanvalkenburg:python-agui-provider-approval-deferral

Conversation

@eavanvalkenburg

Copy link
Copy Markdown
Member

Motivation & Context

AG-UI resolves approval responses before context providers run. A tool injected during before_run is therefore
missing from the transport's static tool map and an approved call can be rejected or fail before the tool exists.

Description & Review Guide

  • What are the major changes?
    • Execute only approved tools already present in the static tool map.
    • Leave provider-injected approvals for the in-run ToolApprovalMiddleware.
    • Preserve the complete grouped result contract from the core function loop.
    • Cover pause, approve, resume, side-effect execution, and exactly one result event.
  • What is the impact of these changes?
    • Provider-injected approved tools execute after before_run registers them.
    • Approved calls are not converted to rejection/failure results by the transport.
    • The side effect and AG-UI result are emitted exactly once.
  • What do you want reviewers to focus on?
    • Static-versus-provider tool ownership.
    • Exactly-once execution and result emission on resume.

Related Issue

Fixes #7043

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.

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

Copilot-Session: 1ee1d250-d1e2-4c6f-8c36-aae0d94fe7a1
Copilot AI review requested due to automatic review settings July 29, 2026 20:11
@agent-framework-automation agent-framework-automation Bot added documentation Usage: [Issues, PRs], Target: documentation in the code base and learn docs python Usage: [Issues, PRs], Target: Python labels Jul 29, 2026
@eavanvalkenburg
eavanvalkenburg marked this pull request as ready for review July 29, 2026 20:12
@github-actions

github-actions Bot commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Python Test Coverage

Python Test Coverage Report •
FileStmtsMissCoverMissing
packages/ag-ui/agent_framework_ag_ui
   _agent_run.py111511889%184–191, 238–239, 246, 355, 359, 361, 378, 405–406, 519, 533, 537, 541, 544, 549, 554, 563, 566, 573–579, 612, 624, 635, 638, 673, 727–731, 796, 811, 814, 816, 842, 868–870, 928, 930, 932, 935–939, 953, 961–966, 975–976, 1025–1028, 1039, 1047, 1079, 1094, 1108, 1120, 1150, 1154, 1157, 1159, 1199–1201, 1265, 1271–1272, 1277, 1281–1282, 1450, 1458, 1475, 1479, 1524, 1583, 1613–1614, 1736, 1882, 1942, 1959, 1979–1980, 1987, 2095, 2123, 2131, 2133, 2136, 2142, 2197, 2200, 2210–2211, 2218, 2264
TOTAL45857447690% 

Python Unit Test Overview

Tests Skipped Failures Errors Time
9466 34 💤 0 ❌ 0 🔥 2m 39s ⏱️

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 fixes an AG-UI transport ordering bug where approval responses were being resolved (and approved tool calls executed) before agent.run() starts, meaning tools injected by ContextProvider.before_run were missing from the static tool map and could be incorrectly turned into transport-level failures. The change defers provider-injected approvals to in-run ToolApprovalMiddleware execution while still executing approvals for statically-known tools.

Changes:

  • Update AG-UI approval resolution to execute only approved tool calls that exist in the static tool map, leaving provider-injected approvals in the message stream for in-run middleware handling.
  • Add a full pause → approve → resume regression test to ensure a provider-injected, approval-gated tool executes exactly once and emits exactly one TOOL_CALL_RESULT.
  • Update AG-UI package notes and the function-calling-loop spec to document the provider-injected approval deferral behavior.

Reviewed changes

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

File Description
python/packages/ag-ui/agent_framework_ag_ui/_agent_run.py Partitions approved responses into statically-executable vs deferred; only executes the former during transport approval resolution.
python/packages/ag-ui/tests/ag_ui/test_endpoint.py Adds regression coverage for provider-injected approval deferral and in-run execution on resume.
python/packages/ag-ui/AGENTS.md Documents that approvals for tools injected during before_run are deferred to in-run approval middleware.
docs/specs/004-python-function-calling-loop.md Updates the spec’s coverage matrix and checklist to include provider-injected approval deferral/execution semantics.

Comment thread python/packages/ag-ui/tests/ag_ui/test_endpoint.py Outdated
Comment thread python/packages/ag-ui/tests/ag_ui/test_endpoint.py Outdated
Drop the forged-approval test that was stripped by pending-approval validation; the real pause-approve-resume regression remains the authoritative provider-injected coverage.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 1ee1d250-d1e2-4c6f-8c36-aae0d94fe7a1
@eavanvalkenburg
eavanvalkenburg added this pull request to the merge queue Jul 30, 2026
Merged via the queue into microsoft:main with commit e18a645 Jul 30, 2026
38 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Usage: [Issues, PRs], Target: documentation in the code base and learn docs python Usage: [Issues, PRs], Target: Python

Projects

None yet

4 participants