Skip to content

Python: WorkflowAgent created via .as_agent() does not emit outputs when using ctx.yield_output #2813

@VanQuy24

Description

@VanQuy24

High-level description

When building a workflow based on multiple executors and then converting it into an agent using .as_agent(), calls to ctx.yield_output() inside an executor do not produce any output.
The same workflow, when executed directly (without .as_agent()), correctly yields output messages.

Expected behavior

ctx.yield_output() inside a workflow executor should emit output messages even when the workflow is wrapped using .as_agent().
The Workflow Agent should behave consistently with the direct workflow execution: each yield_output call should surface as an agent message/output event.

Actual behavior

When the workflow is executed through the agent returned by .as_agent(), the yield_output calls produce no visible output.
There is no error — the output simply does not appear.
Only the final aggregated result of the workflow is returned, and intermediate yielded messages are ignored.

Minimal reproduction

from typing import List
from agent_framework import WorkflowBuilder, executor, WorkflowContext, ChatMessage

@executor
async def my_executor(text: str | List[ChatMessage], ctx: WorkflowContext):
    await ctx.yield_output(f"processing: {text}")


async def main():
    workflow = (
        WorkflowBuilder()
        .set_start_executor(my_executor)
        .build()
    )

    print("Running workflow...")
    result = await workflow.run("hello from workflow")
    print("Workflow result:", result)

    print("\nRunning as agent...")
    agent = workflow.as_agent("wf-agent")
    result = await agent.run("hello from agent")
    print("WorkflowAgent result:", result)

    print("END")


if __name__ == "__main__":
    import asyncio
    asyncio.run(main())


# Expected:
# Running workflow...
# Workflow result: [ExecutorInvokedEvent(executor_id=my_executor, data=None), WorkflowOutputEvent(data=processing: hello from workflow, source_executor_id=my_executor), ExecutorCompletedEvent(executor_id=my_executor, data=None)]

# Running as agent...
# WorkflowAgent result: [ExecutorInvokedEvent(executor_id=my_executor, data=None), WorkflowOutputEvent(data=processing: hello from workflow, source_executor_id=my_executor), ExecutorCompletedEvent(executor_id=my_executor, data=None)]
# END


# Actual:
# Running workflow...
# Workflow result: [ExecutorInvokedEvent(executor_id=my_executor, data=None), WorkflowOutputEvent(data=processing: hello from workflow, source_executor_id=my_executor), ExecutorCompletedEvent(executor_id=my_executor, data=None)]

# Running as agent...

# END

Environment

  • Agent Framework version: 1.0.0b251114
  • Runtime: Python 3.10.19
  • OS: Windows 10 / Linux / macOS
  • Execution: Local development environment

Metadata

Metadata

Assignees

Labels

pythonworkflowsRelated to Workflows in agent-framework

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions