Skip to content

Python: Refactor workflow as agent pending request handling#6259

Merged
TaoChenOSU merged 16 commits into
mainfrom
feature/python-refactor-workflow-as-agent-pending-request-handling
Jun 5, 2026
Merged

Python: Refactor workflow as agent pending request handling#6259
TaoChenOSU merged 16 commits into
mainfrom
feature/python-refactor-workflow-as-agent-pending-request-handling

Conversation

@TaoChenOSU
Copy link
Copy Markdown
Contributor

@TaoChenOSU TaoChenOSU commented Jun 2, 2026

Motivation and Context

Function approval was not handled correctly when the approval comes from an agent within a workflow that is used as an agent.

Addresses #5654

Description

  1. Add support for handling function approval requests coming from an agent within a workflow that is used as agent and hosted.
  2. function_approval_request will now pass through while other request events will be serialized to function_call contents.
  3. Simplify the function approval flow for workflow as agent.
  4. Add tests.

Old data flow:

1. An approval request emitted from an agent in a workflow
2. AgentExecutor captures the request and emits it as a request info event
3. WorkflowAgent captures the request info event, serializes it in a function call content argument and wraps it in an approval request
5. Client captures the request, approval or denies, and sends the response to the workflow as an agent
6. WorkflowAgent gets the response, unwraps it, and deserializes the argument string to get the response
7. WorkflowAgent then sends the response to the underlying workflow

New data flow:

1. An approval request emitted from an agent in a workflow
2. AgentExecutor captures the request and emits it as a request info event
3. WorkflowAgent captures the request info event and unwraps the approval request
4. Client captures the request, approval or denies, and sends the response to the workflow as an agent
5. WorkflowAgent then sends the response to the underlying workflow

Contribution Checklist

  • The code builds clean without any errors or warnings
  • The PR follows the Contribution Guidelines
  • All unit tests pass, and I have added new tests where possible
  • Is this a breaking change? If yes, add "[BREAKING]" prefix to the title of the PR.

@TaoChenOSU TaoChenOSU self-assigned this Jun 2, 2026
Copilot AI review requested due to automatic review settings June 2, 2026 05:11
@TaoChenOSU TaoChenOSU added python workflows Related to Workflows in agent-framework Foundry Hosted Agent Issues related to foundry hosted agents labels Jun 2, 2026
@github-actions github-actions Bot changed the title Refactor workflow as agent pending request handling Python: Refactor workflow as agent pending request handling Jun 2, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 refactors Python workflow-as-agent “pending request” handling so tool-approval flows (FunctionApprovalRequest/Response) round-trip correctly across WorkflowAgent, AgentExecutor, and the Foundry ResponsesHostServer HTTP pipeline. It also introduces a Workflow.status property to expose run-level state transitions.

Changes:

  • Add Workflow.status (mirrors emitted status events) and new tests covering status transitions, including pending-request scenarios.
  • Update WorkflowAgent/AgentExecutor to route tool-approval requests via request_info using the underlying approval request id (so pending request IDs match what the caller echoes back).
  • Update Foundry hosting response conversion to persist approval requests and rehydrate them when converting mcp_approval_response items; add end-to-end hosting tests for workflow agents with approvals.

Reviewed changes

Copilot reviewed 9 out of 10 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
python/samples/02-agents/tools/function_tool_with_approval.py Disables the streaming demo invocation in main().
python/packages/foundry_hosting/tests/test_responses.py Adds end-to-end HTTP tests for hosting WorkflowAgent with tool approvals (streaming and non-streaming).
python/packages/foundry_hosting/agent_framework_foundry_hosting/_responses.py Plumbs approval storage through input/output conversion so approval responses can be reconstructed.
python/packages/core/tests/workflow/test_workflow_status.py New tests for the new Workflow.status property across success/failure/pending-request flows.
python/packages/core/tests/workflow/test_workflow_agent.py Updates request-info/tool-approval expectations and adds tests ensuring raw tool-approval content forwards unchanged.
python/packages/core/tests/workflow/test_agent_executor.py Adds regression tests for “double-emission” of approval payload and request-id matching.
python/packages/core/tests/core/test_skills.py Minor parentheses cleanup in async awaits.
python/packages/core/agent_framework/_workflows/_workflow.py Implements run-level status tracking (Workflow.status) and updates during execution.
python/packages/core/agent_framework/_workflows/_agent.py Refactors WorkflowAgent continuation logic to depend on Workflow.status and adjusts request-info conversion.
python/packages/core/agent_framework/_workflows/_agent_executor.py Adjusts approval request handling to avoid double-emitting approval payloads and passes explicit request_id.
python/packages/core/agent_framework/_skills.py Minor formatting of tool descriptions.

Comment thread python/packages/core/agent_framework/_workflows/_agent_executor.py
Comment thread python/packages/core/agent_framework/_workflows/_agent_executor.py
Comment thread python/packages/core/agent_framework/_workflows/_agent_executor.py
Comment thread python/packages/core/agent_framework/_workflows/_agent_executor.py
Comment thread python/packages/core/agent_framework/_workflows/_agent.py Outdated
Copy link
Copy Markdown

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated Code Review

Reviewers: 4 | Confidence: 62% | Result: All clear

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


Automated review by TaoChenOSU's agents

@TaoChenOSU TaoChenOSU marked this pull request as ready for review June 2, 2026 06:02
@moonbox3
Copy link
Copy Markdown
Contributor

moonbox3 commented Jun 2, 2026

Python Test Coverage

Python Test Coverage Report •
FileStmtsMissCoverMissing
packages/core/agent_framework/_workflows
   _agent.py3243190%69, 73, 114–115, 264, 277, 344, 355, 357, 413, 479, 549, 627, 657, 685, 733, 742, 803, 810, 816–817, 828, 860, 867, 888, 897, 901, 903–905, 912
   _agent_executor.py2081791%166, 190, 231, 255, 275–276, 356–358, 360, 370–371, 494, 521–522, 594, 600
   _workflow.py3472493%59, 61, 66, 90, 95, 156, 192, 416–418, 420–421, 445, 479, 648, 859, 880, 928, 940, 946, 951, 971–973
packages/foundry_hosting/agent_framework_foundry_hosting
   _responses.py7708588%186–189, 254, 314–315, 329, 332–333, 381–382, 392, 429, 484, 498, 549, 552–556, 575, 578, 584, 586, 645, 1017, 1030, 1499–1501, 1503, 1550–1551, 1553–1554, 1556–1557, 1559–1560, 1565, 1574, 1577–1579, 1581, 1595, 1608, 1653–1654, 1656, 1661–1665, 1667, 1674–1675, 1677–1678, 1684, 1686–1690, 1697, 1703, 1725, 1731, 1737, 1739, 1741–1744, 1752, 1754, 1805–1807, 1817–1818
TOTAL38285439788% 

Python Unit Test Overview

Tests Skipped Failures Errors Time
7666 34 💤 0 ❌ 0 🔥 2m 12s ⏱️

Comment thread python/packages/core/agent_framework/_workflows/_agent.py Outdated
Comment thread python/packages/core/agent_framework/_workflows/_agent_executor.py
Comment thread python/packages/core/agent_framework/_workflows/_agent_executor.py
Comment thread python/packages/core/tests/workflow/test_workflow_agent.py
Comment thread python/packages/core/agent_framework/_workflows/_agent.py Outdated
@TaoChenOSU TaoChenOSU enabled auto-merge June 4, 2026 23:25
Comment thread python/samples/02-agents/tools/function_tool_with_approval.py Outdated
@TaoChenOSU TaoChenOSU added this pull request to the merge queue Jun 5, 2026
Merged via the queue into main with commit 9cafd7e Jun 5, 2026
37 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Foundry Hosted Agent Issues related to foundry hosted agents python workflows Related to Workflows in agent-framework

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants