Skip to content

Python: Refactor workflow as agent pending request handling - #6259

Merged
Tao Chen (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
Tao Chen (TaoChenOSU) merged 16 commits into
mainfrom
feature/python-refactor-workflow-as-agent-pending-request-handling

Conversation

@TaoChenOSU

@TaoChenOSUTao Chen (TaoChenOSU) commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

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.

CopilotAI review requested due to automatic review settings June 2, 2026 05:11
@TaoChenOSUTao Chen (TaoChenOSU) added python Usage: [Issues, PRs], Target: Python workflows Usage: [Issues, PRs], Target: Workflows Foundry Hosted Agent labels Jun 2, 2026
@github-actionsgithub-actionsBot changed the title Refactor workflow as agent pending request handlingPython: Refactor workflow as agent pending request handlingJun 2, 2026

CopilotAI 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 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
FileDescription
python/samples/02-agents/tools/function_tool_with_approval.pyDisables the streaming demo invocation in main().
python/packages/foundry_hosting/tests/test_responses.pyAdds end-to-end HTTP tests for hosting WorkflowAgent with tool approvals (streaming and non-streaming).
python/packages/foundry_hosting/agent_framework_foundry_hosting/_responses.pyPlumbs approval storage through input/output conversion so approval responses can be reconstructed.
python/packages/core/tests/workflow/test_workflow_status.pyNew tests for the new Workflow.status property across success/failure/pending-request flows.
python/packages/core/tests/workflow/test_workflow_agent.pyUpdates request-info/tool-approval expectations and adds tests ensuring raw tool-approval content forwards unchanged.
python/packages/core/tests/workflow/test_agent_executor.pyAdds regression tests for “double-emission” of approval payload and request-id matching.
python/packages/core/tests/core/test_skills.pyMinor parentheses cleanup in async awaits.
python/packages/core/agent_framework/_workflows/_workflow.pyImplements run-level status tracking (Workflow.status) and updates during execution.
python/packages/core/agent_framework/_workflows/_agent.pyRefactors WorkflowAgent continuation logic to depend on Workflow.status and adjusts request-info conversion.
python/packages/core/agent_framework/_workflows/_agent_executor.pyAdjusts approval request handling to avoid double-emitting approval payloads and passes explicit request_id.
python/packages/core/agent_framework/_skills.pyMinor formatting of tool descriptions.

Comment threadpython/packages/core/agent_framework/_workflows/_agent.py Outdated

@github-actionsgithub-actionsBot 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.

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
Tao Chen (TaoChenOSU) marked this pull request as ready for review June 2, 2026 06:02
@moonbox3

Evan Mattson (moonbox3) commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

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

TestsSkippedFailuresErrorsTime
766634 💤0 ❌0 🔥2m 12s ⏱️

Comment threadpython/packages/core/agent_framework/_workflows/_agent.py Outdated
Comment threadpython/packages/core/tests/workflow/test_workflow_agent.py
Comment threadpython/packages/core/agent_framework/_workflows/_agent.py Outdated
@moonbox3Evan Mattson (moonbox3) added hosting Usage: [Issues, PRs], Target: all hosting related solutions and removed Foundry Hosted Agent labels Jun 17, 2026
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

hostingUsage: [Issues, PRs], Target: all hosting related solutionspythonUsage: [Issues, PRs], Target: PythonworkflowsUsage: [Issues, PRs], Target: Workflows

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@TaoChenOSU@moonbox3@alliscode