Python: filter non-assistant messages from workflow agent responses - #8729
Open
Manohar Paturi (ManoharPaturi) wants to merge 2 commits into
Open
Manohar Paturi (ManoharPaturi) wants to merge 2 commits into
Manohar Paturi (ManoharPaturi) wants to merge 2 commits into
Conversation
When running workflows converted to an agent via workflow.as_agent(), WorkflowAgent._convert_workflow_events_to_agent_response and _convert_workflow_event_to_agent_response_updates forwarded messages without checking their role. When underlying executors or orchestrations such as GroupChat yield conversation history containing user inputs, system instructions, or tool outputs, these non-assistant messages were re-emitted as caller-facing agent responses and streaming chunks. This change filters out non-assistant messages across AgentResponse, list[Message], Message, and AgentResponseUpdate workflow outputs so that WorkflowAgent exclusively returns assistant output. If an event contains only non-assistant messages, it is safely excluded from agent output without altering internal workflow execution. Signed-off-by: Manohar Paturi <186662190+ManoharPaturi@users.noreply.github.com>
Manohar Paturi (ManoharPaturi)
deployed
to
github-app-auth
September 24, 2026 15:32 — with
GitHub Actions
Active
Manohar Paturi (ManoharPaturi)
deployed
to
github-app-auth
September 24, 2026 15:32 — with
GitHub Actions
Active
Signed-off-by: Manohar Paturi <186662190+ManoharPaturi@users.noreply.github.com>
Manohar Paturi (ManoharPaturi)
deployed
to
github-app-auth
September 25, 2026 13:07 — with
GitHub Actions
Active
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation & Context
When converting a workflow to an agent using workflow.as_agent(), WorkflowAgent wraps workflow execution inside the agent contract. In multi-agent orchestrations such as GroupChat or workflows where executors yield conversation history, the emitted output often contains user questions, system instructions, or tool results alongside assistant responses.
Previously, WorkflowAgent._convert_workflow_events_to_agent_response and _convert_workflow_event_to_agent_response_updates forwarded messages from AgentResponse, list[Message], and Message payloads without inspecting message roles. This caused user prompts to be re-emitted as part of the agent response, compounding across conversation turns in streaming and non-streaming modes.
Filtering to assistant-only messages ensures that callers invoking the workflow as an agent receive solely the generated assistant output.
Description & Review Guide
Major changes:
In python/packages/core/agent_framework/_workflows/_agent.py, updated _convert_workflow_events_to_agent_response so that only assistant-role messages from AgentResponse, list[Message], and Message payloads are added to the returned AgentResponse. Also updated _convert_workflow_event_to_agent_response_updates to drop non-assistant messages and updates during streaming conversion.
Impact of changes:
WorkflowAgent now returns strictly assistant output. If a workflow output event consists only of non-assistant messages, it is cleanly omitted without crashing or appending dangling raw representations. Internal workflow messaging and inter-executor communication remain completely unchanged.
Review focus:
Please verify the role filtering logic across the AgentResponse, list[Message], and Message branches in _convert_workflow_events_to_agent_response and _convert_workflow_event_to_agent_response_updates, as well as the unit tests covering multi-turn conversation non-compounding and streaming behavior.
Related Issue
Fixes #4261
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.