Skip to content

Python: How to get workflow outputs from workflow agent? #2957

@moonbox3

Description

@moonbox3

Discussed in #2943

Originally posted by cecheta December 18, 2025
I've been playing around with workflows. When running a workflow directly, it is easy to get the outputs, for example using .get_outputs(). But I don't know how to do it if you convert the workflow into an agent.

For example, using this workflow:

import asyncio

from agent_framework import (
    AgentExecutorRequest,
    ChatAgent,
    ChatMessage,
    WorkflowBuilder,
    WorkflowContext,
    executor,
)
from agent_framework.azure import AzureOpenAIChatClient
from azure.identity import AzureCliCredential


@executor
async def start(messages: list[ChatMessage], ctx: WorkflowContext[AgentExecutorRequest, str]) -> None:
    await ctx.yield_output("Start...")

    # Send the prompt to the next executor.
    await ctx.send_message(
        AgentExecutorRequest(
            messages=messages,
            should_respond=True,
        )
    )


def create_writer_agent() -> ChatAgent:
    """Factory function to create a writer agent."""
    chat_client = AzureOpenAIChatClient(credential=AzureCliCredential())
    return chat_client.create_agent(
        instructions=(
            "You are an excellent content writer. You create new content and edit contents based on the feedback."
        ),
        name="writer",
    )


def create_reviewer_agent() -> ChatAgent:
    """Factory function to create a reviewer agent."""
    chat_client = AzureOpenAIChatClient(credential=AzureCliCredential())
    return chat_client.create_agent(
        instructions=(
            "You are an excellent content reviewer."
            "Provide actionable feedback to the writer about the provided content."
            "Provide the feedback in the most concise manner possible."
        ),
        name="reviewer",
    )


async def main():
    # Build the workflow using the fluent builder.
    # Set the start node and connect an edge from writer to reviewer.
    workflow = (
        WorkflowBuilder()
        .register_executor(lambda: start, "start")
        .register_agent(create_writer_agent, "writer")
        .register_agent(create_reviewer_agent, "reviewer", output_response=True)
        .set_start_executor("start")
        .add_edge("start", "writer")
        .add_edge("writer", "reviewer")
        .build()
    )

I can get the outputs when running the workflow directly:

    prompt = "Create a slogan for a new electric SUV that is affordable and fun to drive."

    res = await workflow.run([ChatMessage(role="user", text=prompt)])
    for output in res.get_outputs():
        print(f"Workflow Output: {output}")
Workflow Output: Start...
Workflow Output: Clear and positive message; highlights affordability and fun. Consider shortening or using a more direct call-to-action (e.g., "Affordable Thrills. Electric Adventures."). Including the word "SUV" may improve clarity.

But how do you get the outputs if you run it as an agent?

    workflow_agent = workflow.as_agent()
    thread = workflow_agent.get_new_thread()

    res = await workflow_agent.run(prompt, thread=thread)

res.text looks like this, but it includes the output from writer, despite output_response not being set:

Start...Strong energy and appeal; nicely emphasizes both excitement and affordability. Consider including a nod to the SUV aspect or capability (e.g., "Charge Up the Fun—Adventure Meets Affordability," or "Electrify Your Everyday Adventure"). Overall, great balance of concise message and inviting tone.Charge Up the Fun—Adventure Within Reach.Strong energy and appeal; nicely emphasizes both excitement and affordability. Consider including a nod to the SUV aspect or capability (e.g., "Charge Up the Fun—Adventure Meets Affordability," or "Electrify Your Everyday Adventure"). Overall, great balance of concise message and inviting tone.

If you loop through res.messages, there are four messages, and again it includes the output from the writer:

Start...

Actionable Feedback:  
- Strong use of wordplay with "Charge Ahead."
- Clearly communicates affordability and fun, aligning with target messaging.
- To enhance SUV appeal, consider incorporating phrases that evoke spaciousness, freedom, or versatility, e.g., “Charge Ahead—Affordable Fun for Every Journey.”
- Test the slogan’s distinctiveness to avoid overlap with existing auto brands.

Charge Ahead—Affordable Adventure, Electrifying Fun.

Actionable Feedback:  
- Strong use of wordplay with "Charge Ahead."
- Clearly communicates affordability and fun, aligning with target messaging.
- To enhance SUV appeal, consider incorporating phrases that evoke spaciousness, freedom, or versatility, e.g., “Charge Ahead—Affordable Fun for Every Journey.”
- Test the slogan’s distinctiveness to avoid overlap with existing auto brands.
```</div>

Metadata

Metadata

Assignees

Labels

agentsIssues related to single agentspythonworkflowsRelated to Workflows in agent-framework

Type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions