Task 2 — Orchestrate multiple agents in sequence
Part of the Build multi-agent solutions with the Agent Framework lab. New here? Start with Getting started.
Set up (start here): This task needs a Foundry project and the starter code. If you haven’t already, complete Getting started to create your project, clone the code, and set
PROJECT_ENDPOINTandMODEL_DEPLOYMENT_NAMEinPython/.env. Then, from theLabfiles/C-build-multi-agent-solutions-with-agent-frameworkfolder, verify you’re ready:
python setup/check_env.py --task 2
Continuing from a previous task? If you just finished an earlier task in the same
Pythonfolder, your project, virtual environment, and.envare already set — go straight to Create the agents below.
Some jobs are best done by a team of specialists, each handling one step and passing its result to the next. The Microsoft Agent Framework’s sequential orchestration does exactly that: it runs a list of agents in order and collects each one’s output. In this task you’ll build a Tailwind Traders feedback triage pipeline — a summarizer condenses a customer comment, a classifier labels it, and an action agent recommends the next step.
What is sequential orchestration?
Sequential orchestration runs several agents one after another, feeding the running
conversation from each agent into the next. It’s a good fit when a task breaks cleanly into
ordered stages — summarize, then classify, then decide — and each stage benefits from the output
of the one before it. In the Agent Framework you build one with SequentialBuilder, listing the
participant agents in the order they should run.
Open the Python folder and activate the virtual environment from Getting started (.\labenv\Scripts\Activate.ps1), then continue below.
Create the agents
Open feedback_agents.py and add code at each commented placeholder.
-
Review the code already in the file. In the
mainfunction, take a moment to read the three sets of agent instructions (summarizer, classifier, action) — these define what each agent does.Tip: As you add code, keep the indentation aligned with the comments.
-
At the top of the file, find the comment Add references and add the namespaces you’ll need:
# Add references from agent_framework import Message from agent_framework.foundry import FoundryChatClient from agent_framework.orchestrations import SequentialBuilder from azure.identity import AzureCliCredential -
Find the comment Create the chat client and add the following (keep the indentation level):
# Create the chat client credential = AzureCliCredential() chat_client = FoundryChatClient( credential=credential, project_endpoint=os.getenv("PROJECT_ENDPOINT"), model=os.getenv("MODEL_DEPLOYMENT_NAME"), )The AzureCliCredential lets your code authenticate to Azure using your
az loginsession, and the FoundryChatClient connects to your Foundry project. All three agents share this one client. -
Find the comment Create agents and add the following to create the three agents from the shared client:
# Create agents summarizer_agent = chat_client.as_agent( name="summarizer", instructions=summarizer_instructions, ) classifier_agent = chat_client.as_agent( name="classifier", instructions=classifier_instructions, ) action_agent = chat_client.as_agent( name="action", instructions=action_instructions, ) -
Find the comment Initialize the current feedback and add a sample piece of customer feedback for the pipeline to triage:
# Initialize the current feedback feedback=""" I use your trail-finder app before every hike, and it works well overall. But when I'm checking the map at night on the trail, the bright screen is really harsh on my eyes. If you added a dark mode option, it would make it much more comfortable to use in low light. """
Create a sequential orchestration
-
Find the comment Build sequential orchestration and add the following to define the pipeline:
# Build sequential orchestration workflow = SequentialBuilder( participants=[summarizer_agent, classifier_agent, action_agent], output_from="all", ).build()The agents process the feedback in the order they’re listed.
output_from="all"ensures the outputs from every agent are collected, not just the last one. -
Find the comment Run and collect outputs and add the following:
# Run and collect outputs result = await workflow.run(f"Customer feedback: {feedback}") outputs = result.get_outputs()This runs the orchestration and collects the output from each participating agent.
-
Find the comment Display outputs and add the following:
# Display outputs i = 1 for response in outputs: for msg in cast(list[Message], response.messages): name = msg.author_name or ("assistant" if msg.role == "assistant" else "user") print(f"{'-' * 60}\n{i:02d} [{name}]\n{msg.text}") i += 1This formats and prints each message collected from the orchestration, labeled with the agent that produced it.
-
Save the file (Ctrl+S).
Run and test
-
In the terminal, sign in and run the app:
az loginpython feedback_agents.py -
Review the output. Each agent contributes one step, and you should see output similar to:
Customer requests a dark mode option for comfortable nighttime trail use. Feature request Log as an enhancement request to add a dark mode for nighttime trail use. ------------------------------------------------------------ 01 [summarizer] Customer requests a dark mode option for comfortable nighttime trail use. ------------------------------------------------------------ 02 [classifier] Feature request ------------------------------------------------------------ 03 [action] Log as an enhancement request to add a dark mode for nighttime trail use.Tip: If the app fails because the rate limit is exceeded, wait a few seconds and try again. Try editing the
feedbackstring to a complaint or a compliment and run again to see the classification and recommended action change.
✅ Checkpoint: You’ve orchestrated three agents in a sequence with the Microsoft Agent Framework, passing work from one specialist to the next and collecting every agent’s output.
When you’re finished, enter deactivate to exit the virtual environment.
Next (optional): Task 3 — Connect remote agents with A2A