Python: preserve response update metadata in WorkflowAgent forwarding - #7999
Python: preserve response update metadata in WorkflowAgent forwarding#7999HeZzz (HeZ2z) wants to merge 7 commits into
Conversation
There was a problem hiding this comment.
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.
|
@microsoft-github-policy-service agree |
|
HeZzz (@HeZ2z) please fix the failing CI/CD checks |
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.
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.
…test Fix type checker failures by constructing continuation_token as an opaque dict per the ContinuationToken TypedDict instead of a bare string, and resolve lint/typing nits in the new tests.
ce711ed to
eaa0131
Compare
|
Hi Evan Mattson (@moonbox3), I’ve merged the latest main and verified the previously failing typing/lint issues are resolved. The focused workflow tests and Ruff checks pass locally. Could you please re-review when convenient? It also looks like the full Python CI checks have not been triggered for the latest commit. |
|
HeZzz (@HeZ2z) please fix the failing code quality checks. |
Head branch was pushed to by a user without write access
Motivation & Context
WorkflowAgentwraps a workflow and forwards executor emissions through_convert_workflow_event_to_agent_response_updates(). The method documentation promises thatoutputandintermediateevents are forwarded as-is, but when reconstructing anAgentResponseUpdatethe code only copiedcontents,role,author_name, IDs,created_atandraw_representation— silently dropping several response metadata fields.Consumers streaming through
WorkflowAgent.run(stream=True)therefore sawNonefor fields that were present on the executor's original update. This differs from running the same agent directly, breaksAgentResponse.from_updates()reconstruction for those fields, and can make long-running operations unresumable (lostcontinuation_token).Description & Review Guide
What are the major changes?
_convert_workflow_event_to_agent_response_updates()now forwardsfinish_reason,continuation_token,agent_id, andadditional_properties(as a shallow copy, so the forwarded update cannot alias the payload still referenced by the executor) when reconstructing anAgentResponseUpdate.AgentResponseUpdatewith all metadata populated and asserts each field survives the wrapping.What is the impact of these changes?
Nonecontinue to behave exactly as before. No breaking change.What do you want reviewers to focus on?
additional_propertiesmatches the project's preferred convention (vs.copy.copy).AgentResponse,Message,list[Message]) should receive the same treatment in this PR or a follow-up.Related Issue
Fixes #7952
Contribution Checklist
breaking changelabel (or add "[BREAKING]" to the title prefix, before or after any language prefix) — a workflow keeps the label and title prefix in sync automatically.