Skip to content

Python: restore WorkflowAgent pending request state across AgentSession resume#6122

Draft
Copilot wants to merge 4 commits into
mainfrom
copilot/python-agent-session-request-resume-failure
Draft

Python: restore WorkflowAgent pending request state across AgentSession resume#6122
Copilot wants to merge 4 commits into
mainfrom
copilot/python-agent-session-request-resume-failure

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 27, 2026

Motivation and Context

Magentic workflows that pause on request_info (human plan review) could not be resumed after AgentSession serialization/restore, even when replying with the original request_id. The resumed run lost pending-request correlation and failed instead of continuing execution.

Description

  • Pending request persistence in AgentSession

    • WorkflowAgent now stores pending request_info metadata in session.state["workflow_agent"]["pending_request_info_events"] and rehydrates it on subsequent runs.
  • Resume path now supports restore+response in one call

    • When pending requests exist, WorkflowAgent forwards checkpoint_id and checkpoint_storage together with responses into workflow.run(...), so checkpoint restore and request fulfillment happen on the same execution path.
  • Pending-response input handling

    • While resolving pending requests, the agent uses current input messages (approval/function responses) rather than full history payloads, preventing non-response content from being misinterpreted during resume.
  • Regression coverage

    • Added a focused workflow-agent test for:
      • emit request_info
      • serialize/deserialize AgentSession
      • restore from checkpoint
      • resume with same request_id
      • verify completion path advances
# restored session + same request_id + checkpoint restore
result = await restored_agent.run(
    response_message,
    session=restored_session,
    checkpoint_id=checkpoint_with_request.checkpoint_id,
    checkpoint_storage=checkpoint_storage,
)

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.

Copilot AI self-assigned this May 27, 2026
Copilot AI review requested due to automatic review settings May 27, 2026 18:29
Copilot AI review requested due to automatic review settings May 27, 2026 18:29
Copilot AI linked an issue May 27, 2026 that may be closed by this pull request
Copilot AI requested review from Copilot and removed request for Copilot May 27, 2026 18:37
Copilot AI requested review from Copilot and removed request for Copilot May 27, 2026 18:38
Copilot AI changed the title [WIP] Fix AgentSession pending request resume failure in Python Python: restore WorkflowAgent pending request state across AgentSession resume May 27, 2026
Copilot AI requested a review from TaoChenOSU May 27, 2026 18:39
)
# combine the messages
session_messages: list[Message] = session_context.get_messages(include_input=True)
workflow_input_messages = input_messages if self.pending_requests else session_messages
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 why is this needed?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good catch — it wasn’t required for functionality. I reverted that simplification and restored the previous explicit form in commit aee043d.

Copilot AI requested review from Copilot and removed request for Copilot May 27, 2026 21:30
Copilot AI requested a review from TaoChenOSU May 27, 2026 21:31
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.

Python: AgentSession Pending Request Resume Failure

2 participants