-
Notifications
You must be signed in to change notification settings - Fork 1.1k
[BREAKING] Python: Fix workflow as agent streaming output #3649
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BREAKING] Python: Fix workflow as agent streaming output #3649
Conversation
There was a problem hiding this comment.
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 implements breaking changes to fix workflow-as-agent streaming output (closes #3126). The changes consolidate output event handling by removing AgentRunEvent and AgentRunUpdateEvent in favor of WorkflowOutputEvent, introduce output executor filtering via with_output_from, and fix workflow-as-agent to properly stream agent responses.
Changes:
- Removes
AgentRunEventandAgentRunUpdateEventclasses, consolidating onWorkflowOutputEventfor all executor outputs - Adds
with_output_frombuilder method to filter which executors emit workflow outputs, with validation - Changes
WorkflowAgentto run workflows in non-streaming mode when invoked viarun()(previously always streamed)
Reviewed changes
Copilot reviewed 66 out of 68 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
_events.py |
Removes deprecated event classes |
_agent_executor.py |
Removes output_response parameter, always yields outputs via WorkflowOutputEvent |
_workflow.py |
Adds output executor filtering support |
_workflow_builder.py |
Adds with_output_from method, removes deprecated add_agent |
_agent.py |
Implements proper streaming/non-streaming mode handling for workflow-as-agent |
_validation.py |
Adds output executor validation |
| Builder files | Add with_intermediate_outputs to control output filtering |
| Sample files | Updated to handle new event patterns |
| Test files | Comprehensive updates for new behavior |
Motivation and Context
Closes #3126
Description
AgentRunEventandAgentRunUpdateEvent. Replace withWorkflowOutputEvent.AgentExecutorwill always emitWorkflowOutputEventcarrying eitherAgentReponseorAgentResponseUpdatewhen they become available. Theoutput_responseflag is removed.with_output_fromto allow developers to configure which executors in the workflow can surfaceWorkflowOutputEvents.WorkflowAgentfor using workflow as an agent now runs the workflow in non-streaming mode if it's invoked viarun. Previously, the underlying workflow would run in streaming mode regardless of if it's invoked viarunorrun_stream.With the changes above, the workflow as an agent will have the following pattern:
WorkflowOutputEvents.WorkflowOutputEvents are considered as the outputs of a workflow.WorkflowOutputEvents will be converted toAgentResponseorAgentResponseUpdate.WorkflowOutputEvents. It's implemented as a simple filter.WorkflowOutputEvent:a.
AgentResponseUpdatewill be directly yielded without modification.b.
AgentResponsewill be converted to anAgentResponseUpdateby extracting contents from messages, dropping message IDs. The original response is preserved inraw_representation.c.
ChatMessagewill be converted to anAgentResponseUpdateby extracting contents. The original message is preserved inraw_representation.d. A list of
ChatMessagewill be converted to multipleAgentResponseUpdate, one per message.c. Any other data type will be converted to
Contentof typetextand put into anAgentResponseUpdate.WorkflowOutputEvent:a.
AgentResponseUpdatewill result in an exception.b.
AgentResponsewill be directly returned without modification.c. A single
ChatMessageor a list ofChatMessages will be returned in anAgentResponse. The original messages are preserved inraw_representation.d. Any other data type will be converted to
Contentof typetextand placed in aChatMessage.RequestInfoEvents stay unchanged in this PR.Note:
WorkflowOutputEvents don't signal the end state of a workflow. A workflow run can emit any number ofWorkflowOutputEvents (including zero). Any data the workflow generates should be considered outputs of the workflow.Contribution Checklist