Skip to content

Python: Execute every approved tool in a parallel AG-UI HITL batch - #7692

Closed
Ahmed Hassan (AAH20) wants to merge 4 commits into
microsoft:mainfrom
AAH20:fix/ag-ui-parallel-gated-approval
Closed

Python: Execute every approved tool in a parallel AG-UI HITL batch#7692
Ahmed Hassan (AAH20) wants to merge 4 commits into
microsoft:mainfrom
AAH20:fix/ag-ui-parallel-gated-approval

Conversation

@AAH20

Copy link
Copy Markdown

Motivation & Context

AG-UI HITL resume currently executes only the first approved tool in a parallel always_require batch. CopilotKit and other AG-UI clients synthesize one user message per interrupt, so the second (and later) approval-control messages look like a new user turn. History sanitization then injects a synthetic "Tool execution skipped - user provided follow-up message" result for leftover gated siblings, and ID-less dedup can collapse distinct approval-control messages that hash the same str(Content).

This fixes the silently dropped calls so a complete resume for a parallel gated batch executes every accepted tool once. Rejected siblings still do not execute. Real follow-up user text still skips leftover pending calls. Queued one-at-a-time ToolApprovalMiddleware behavior and never-require mixed-batch siblings are unchanged.

Description & Review Guide

  • What are the major changes?
    • _sanitize_tool_history no longer treats consecutive approval-control user messages as follow-up that abandons leftover gated call_ids.
    • _deduplicate_messages keys ID-less approval-control messages by (approval_id, call_id) instead of hashing str(Content).
    • Spec matrix, package protocol notes, unit tests, and an AG-UI endpoint regression cover the parallel gated batch.
  • What is the impact of these changes?
    • A complete AG-UI resume with two (or more) accepted interrupts from one assistant tool batch now executes every approved local tool and persists both terminal results.
    • Mixed accept/reject consecutive approval-controls reach _resolve_approval_responses without skip injection.
    • Follow-up user text after a partial approval still injects skip for leftover siblings.
  • What do you want reviewers to focus on?
    • The sanitizer exception is limited to approval-control-only user messages (no follow-up text). Automated triage originally pointed at _local_approval_content_ids_to_remove; calling _resolve_approval_responses directly with unsanitized responses already executes both calls, so this change stays in adapters rather than the occurrence matcher.
    • Confirm queued ToolApprovalMiddleware one-at-a-time surfacing and never-require sibling release still pass.

There is no other open PR for this issue.

This area is marked as function-calling-loop core-team ownership in python/AGENTS.md. The spec matrix row and extra AG-UI validation commands required by that document are included in the change.

Related Issue

Fixes #7569

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.

If this parallel HITL drop is showing up in a live agent deployment, A2Z SOC’s Instant Audit ($499) and consultation are available for production agent-action gating reviews.

Made with Cursor

AG-UI resume synthesizes one user message per interrupt, and the sanitizer treated leftover always_require siblings as abandoned follow-up.

Co-authored-by: Cursor <cursoragent@cursor.com>

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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@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 Aug 17, 2026
@github-actions

github-actions Bot commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

Python Test Coverage

Python Test Coverage Report •
FileStmtsMissCoverMissing
packages/ag-ui/agent_framework_ag_ui
   _message_adapters.py6565292%93–94, 101, 107, 233–234, 243–245, 248, 251–255, 257–262, 265, 274–276, 279–282, 318, 490, 611–613, 670, 673, 675, 678, 681, 697, 714, 736, 836, 852–853, 924, 946, 1016, 1051–1052, 1120, 1163
TOTAL46853436490% 

Python Unit Test Overview

Tests Skipped Failures Errors Time
9473 36 💤 0 ❌ 0 🔥 2m 11s ⏱️

@moonbox3 Evan Mattson (moonbox3) 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.

Thanks for working on this. Please also have a look at the failing CI/CD checks.

Comment thread python/packages/ag-ui/agent_framework_ag_ui/_message_adapters.py Outdated
@moonbox3

Copy link
Copy Markdown
Contributor

Looks like CI/CD is okay now after a merge from main.

Ahmed Hassan (AAH20) and others added 2 commits August 18, 2026 09:02
Dedup identity now includes the decision and canonical payload so a later reject or argument edit is not collapsed before occurrence-aware matching.

Co-authored-by: Cursor <cursoragent@cursor.com>
@moonbox3

Copy link
Copy Markdown
Contributor

/review

@moonbox3

Copy link
Copy Markdown
Contributor

Ahmed Hassan (@AAH20) there's no need to update the 004-python-function-call-loop.md doc. We can revert the change, please.

@moonbox3

Copy link
Copy Markdown
Contributor

Please re-open when ready to address the feedback / remaining file conflict.

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

Development

Successfully merging this pull request may close these issues.

Python: [Bug]: AG-UI approval resume executes only the first of several approved calls in one batch — the rest are silently dropped

3 participants