Skip to content

Python: preserve response update metadata in WorkflowAgent forwarding - #7999

Open
HeZzz (HeZ2z) wants to merge 3 commits into
microsoft:mainfrom
HeZ2z:fix/workflow-agent-metadata-7952
Open

Python: preserve response update metadata in WorkflowAgent forwarding#7999
HeZzz (HeZ2z) wants to merge 3 commits into
microsoft:mainfrom
HeZ2z:fix/workflow-agent-metadata-7952

Conversation

@HeZ2z

Copy link
Copy Markdown

Motivation & Context

WorkflowAgent wraps a workflow and forwards executor emissions through _convert_workflow_event_to_agent_response_updates(). The method documentation promises that output and intermediate events are forwarded as-is, but when reconstructing an AgentResponseUpdate the code only copied contents, role, author_name, IDs, created_at and raw_representation — silently dropping several response metadata fields.

Consumers streaming through WorkflowAgent.run(stream=True) therefore saw None for fields that were present on the executor's original update. This differs from running the same agent directly, breaks AgentResponse.from_updates() reconstruction for those fields, and can make long-running operations unresumable (lost continuation_token).

Description & Review Guide

  • What are the major changes?

    • _convert_workflow_event_to_agent_response_updates() now forwards finish_reason, continuation_token, agent_id, and additional_properties (as a shallow copy, so the forwarded update cannot alias the payload still referenced by the executor) when reconstructing an AgentResponseUpdate.
    • Added a streaming regression test that emits an AgentResponseUpdate with all metadata populated and asserts each field survives the wrapping.
  • What is the impact of these changes?

    • Purely additive: fields that are None continue to behave exactly as before. No breaking change.
  • What do you want reviewers to focus on?

    • Whether the shallow copy of additional_properties matches the project's preferred convention (vs. copy.copy).
    • Whether the other reconstruction branches (AgentResponse, Message, list[Message]) should receive the same treatment in this PR or a follow-up.

Related Issue

Fixes #7952

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.

Forward finish_reason, continuation_token, agent_id and a shallow copy
of additional_properties when WorkflowAgent reconstructs
AgentResponseUpdate objects from workflow events, matching the
documented as-is forwarding contract.

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

Preserves metadata when WorkflowAgent forwards streaming response updates.

Changes:

  • Forwards response metadata, including continuation tokens.
  • Adds streaming regression coverage.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
_workflows/_agent.py Copies metadata into forwarded updates.
test_workflow_agent.py Tests metadata preservation.

💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

Comment thread python/packages/core/agent_framework/_workflows/_agent.py Outdated
Use an explicit None check instead of a truthiness check so an
explicitly empty additional_properties dict is not converted to None,
preserving the forwarding contract.
@HeZ2z
HeZzz (HeZ2z) deployed to github-app-auth September 1, 2026 17:20 — with GitHub Actions Active
@HeZ2z

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

@HeZ2z
HeZzz (HeZ2z) deployed to github-app-auth September 2, 2026 07:08 — with GitHub Actions Active
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

python Usage: [Issues, PRs], Target: Python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python: [Bug]: WorkflowAgent drops response metadata when forwarding AgentResponseUpdate

2 participants