From 228ce8394f2e441cd0c5fc1cf2fd7989d221df17 Mon Sep 17 00:00:00 2001 From: Yufeng He <40085740+he-yufeng@users.noreply.github.com> Date: Thu, 21 May 2026 00:38:47 +0800 Subject: [PATCH] fix: update sequential workflow sample output handling --- .../orchestrations/sequential_agents.py | 26 ++++++++++--------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/python/samples/03-workflows/orchestrations/sequential_agents.py b/python/samples/03-workflows/orchestrations/sequential_agents.py index 70a25d9f58..62d3aa54f8 100644 --- a/python/samples/03-workflows/orchestrations/sequential_agents.py +++ b/python/samples/03-workflows/orchestrations/sequential_agents.py @@ -4,7 +4,7 @@ import os from typing import cast -from agent_framework import Agent, Message +from agent_framework import Agent, AgentResponse, Message from agent_framework.foundry import FoundryChatClient from agent_framework.orchestrations import SequentialBuilder from azure.identity import AzureCliCredential @@ -17,9 +17,9 @@ Sample: Sequential workflow (agent-focused API) with shared conversation context Build a high-level sequential workflow using SequentialBuilder and two domain agents. -The shared conversation (list[Message]) flows through each participant. Each agent -appends its assistant message to the context. The workflow outputs the final conversation -list when complete. +The shared conversation flows through each participant. Each agent appends its +assistant message to the context. The sample prints the original user message plus +the visible outputs from both agents. Note on internal adapters: - Sequential orchestration includes small adapter nodes for input normalization @@ -56,17 +56,19 @@ async def main() -> None: ) # 2) Build sequential workflow: writer -> reviewer - workflow = SequentialBuilder(participants=[writer, reviewer]).build() + workflow = SequentialBuilder(participants=[writer, reviewer], output_from="all").build() # 3) Run and collect outputs - outputs: list[list[Message]] = [] - async for event in workflow.run("Write a tagline for a budget-friendly eBike.", stream=True): - if event.type == "output": - outputs.append(cast(list[Message], event.data)) - - if outputs: + prompt = "Write a tagline for a budget-friendly eBike." + result = await workflow.run(prompt) + conversation = [Message(role="user", contents=[prompt])] + for output in result.get_outputs(): + response = cast(AgentResponse, output) + conversation.extend(response.messages) + + if conversation: print("===== Final Conversation =====") - for i, msg in enumerate(outputs[-1], start=1): + for i, msg in enumerate(conversation, start=1): name = msg.author_name or ("assistant" if msg.role == "assistant" else "user") print(f"{'-' * 60}\n{i:02d} [{name}]\n{msg.text}")