Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 14 additions & 12 deletions python/samples/03-workflows/orchestrations/sequential_agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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])]
Comment thread
moonbox3 marked this conversation as resolved.
for output in result.get_outputs():
response = cast(AgentResponse, output)
conversation.extend(response.messages)
Comment thread
moonbox3 marked this conversation as resolved.

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}")

Expand Down
Loading