MAF AcademyLearnCapstoneSandbox
MAF Academy · Microsoft Agent Framework hands-on workshop · labs verified on agent-framework-core 1.26
← All modules
MODULE 6 OF 8 10 minutes

Agent Workflows and Orchestration

Typed graphs, prebuilt patterns, checkpoints and humans in the loop.

1.Introduction to Microsoft Agent Framework workflows
2.Understanding workflow architecture
3.Functional and graph-based workflows
4.Sequential workflow execution
5.Concurrent execution and parallel processing
6.Agent handoff and group collaboration patterns
7.Workflow state management
8.Human-in-the-loop interactions

On this page

Executors, edges and superstepsPrebuilt orchestrationsGraph workflows with WorkflowBuilderFunctional workflows: just write async PythonHandoff, group chat and MagenticPause, ask a human, resumeKey takeawaysHands-on activityQuiz
1Architecture

Executors, edges and supersteps

A workflow is a directed graph:

  • Executors — nodes. An agent, or any Python function decorated with @executor.
  • Edges — typed message routes: direct, conditional, fan-out, fan-in, switch-case.
  • Supersteps — the runtime executes all ready nodes, delivers messages, repeats. Parallel branches in one superstep run concurrently.
  • Events — executor_invoked, output, request_info… stream them for live UIs.
superstep 1superstep 2superstep 3superstep 4fan-outfan-inedgeCoordinatorFinanceOperationsRiskAggregator@executor publish
Executors (nodes) connected by typed edges. The runtime runs ready nodes per superstep — Finance, Ops and Risk run in parallel in superstep 2.
2Fast path

Prebuilt orchestrations

For common patterns, use the builders — one line each.

ex6_workflows.py
1from agent_framework.orchestrations import SequentialBuilder, ConcurrentBuilder
2
3# Sequential: shared conversation flows through each agent
4seq = SequentialBuilder(participants=[research, analysis, recommend], output_from="all").build()
5result = await seq.run("Should we expand AI Copilot into Europe?")
6for response in result.get_outputs():
7 for msg in response.messages:
8 print(f"[{msg.author_name}] {msg.text}")
9
10# Concurrent: fan-out to every participant, fan-in their answers
11conc = ConcurrentBuilder(participants=[finance, ops, risk]).build()
12aggregated = (await conc.run(task)).get_outputs()[-1]
3Full control

Graph workflows with WorkflowBuilder

When you need custom logic between agents — validation, formatting, routing — mix agents and plain Python executors.

graph workflow
1@executor(id="publisher")
2async def publisher(response: AgentExecutorResponse, ctx: WorkflowContext[None, str]) -> None:
3 await ctx.yield_output(f"FINAL BRIEF\n{response.agent_response.text}")
4
5workflow = (
6 WorkflowBuilder(start_executor=research)
7 .add_edge(research, analysis)
8 .add_edge(analysis, recommend)
9 .add_edge(recommend, publisher)
10 .build()
11)
12async for event in workflow.run(task, stream=True):
13 if event.type == "executor_invoked":
14 print("running", event.executor_id)
15 elif event.type == "output" and isinstance(event.data, str):
16 print(event.data)
4Functional API

Functional workflows: just write async Python

The functional style (@workflow + @step) lets you write orchestration as ordinary code — if, for, asyncio.gather — while still getting step caching, checkpoints and human-in-the-loop. (Marked experimental in 1.26.)

capstone_business_ops.py
1@step
2async def do_research(plan: str) -> str:
3 return (await research.run(plan)).text
4
5@workflow(name="business_ops_assistant")
6async def business_ops(request: str, ctx: RunContext) -> str:
7 findings = await do_research(request)
8 insights = await do_analysis(findings)
9 recs = await do_recommend(insights)
10 note = await ctx.request_info({"draft": recs}, response_type=str, request_id="manager_approval")
11 return await consolidate(request, insights, recs, note)
5Collaboration

Handoff, group chat and Magentic

  • HandoffBuilder — agents transfer control to each other (triage → billing → tech support), like a call centre.
  • GroupChatBuilder — a manager selects who speaks next in a shared conversation; max_rounds bounds it.
  • MagenticBuilder — a planner agent maintains a task ledger, delegates, tracks progress and re-plans; supports plan review.

Sequential

SequentialBuilder

Pipeline; each agent builds on the last

Concurrent

ConcurrentBuilder

Fan-out in parallel, aggregate results

Handoff

HandoffBuilder

Agents transfer control dynamically

Group chat

GroupChatBuilder

Manager picks next speaker in shared chat

ledger

Magentic

MagenticBuilder

Planner with task ledger, re-plans on stalls

6Human-in-the-loop

Pause, ask a human, resume

request_info suspends the workflow and emits a request_info event. Your app shows it to a human, then resumes with run(responses={request_id: answer}). With @step, completed steps are cached — nothing is re-run. Add checkpoint storage to survive restarts.

step 1

run(request)

Steps execute & are cached

step 2

request_info()

Workflow pauses, emits event

PAUSED

Human reviews

Approve / edit / reject in your UI

step 4

run(responses={…})

Resume — cached steps skipped

step 5

Output

Final brief yielded

With a checkpoint store the pause can last minutes or days — even across process restarts.
resume after approval
1wf = business_ops.build()
2result = await wf.run("Reduce onboarding time by 30%")
3
4event = result.get_request_info_events()[0] # workflow paused
5print(event.data["draft"])
6result = await wf.run(responses={event.request_id: "Approve — focus on EU"})
7print(result.get_outputs()[-1]) # final brief

Key takeaways

01

Workflows = executors + typed edges, run in supersteps, observable via events.

02

SequentialBuilder / ConcurrentBuilder cover 80% of cases in one line.

03

WorkflowBuilder for custom graphs; @workflow + @step for code-first orchestration.

04

request_info + responses={…} = human-in-the-loop; checkpoints make it durable.

Hands-on activity

Connect multiple agents through a coordinated workflow for an end-to-end business task

  1. 1Multi-Agent Studio → choose Coordinator mode (the capstone flow).
  2. 2Enable “Human approval before final brief”.
  3. 3Run a scenario; when it pauses, edit/annotate the draft and approve.
  4. 4Code Lab → Exercise 6: build Sequential + Concurrent workflows; stretch: WorkflowBuilder.
Open Multi-Agent Studio Exercise 6 in Code Lab

Reference solution — labs/ex6_workflows.py (verified on agent-framework-core 1.26)

ex6_workflows.py
1"""Exercise 6 — Sequential, concurrent and graph workflows (Module 6)."""
2
3import asyncio
4
5from agent_framework import Agent, AgentExecutorResponse, WorkflowBuilder, WorkflowContext, executor
6from agent_framework.orchestrations import ConcurrentBuilder, SequentialBuilder
7from common import make_client
8
9client = make_client()
10
11
12def make_agent(name: str, instructions: str) -> Agent:
13 return Agent(client=client, name=name, instructions=instructions)
14
15
16research = make_agent("Research", "Collect 5 bullet facts about the request.")
17analysis = make_agent("Analysis", "From the conversation so far, list 3 key insights.")
18recommend = make_agent("Recommendation", "Give 3 actionable recommendations based on the insights.")
19
20
21# --- A) Sequential: Research -> Analysis -> Recommendation -------------------
22async def run_sequential(task: str) -> None:
23 # output_from="all" -> collect every agent's response, not just the last one
24 workflow = SequentialBuilder(participants=[research, analysis, recommend], output_from="all").build()
25 result = await workflow.run(task)
26 for response in result.get_outputs(): # each agent saw the conversation so far
27 for msg in response.messages:
28 print(f"[{msg.author_name}] {msg.text[:300]}\n")
29
30
31# --- B) Concurrent: fan-out to three lenses, fan-in the answers -------------
32async def run_concurrent(task: str) -> None:
33 finance = make_agent("Finance", "Assess the request from a financial lens in 3 bullets.")
34 ops = make_agent("Operations", "Assess the request from an operations lens in 3 bullets.")
35 risk = make_agent("Risk", "Assess the request from a risk/compliance lens in 3 bullets.")
36 workflow = ConcurrentBuilder(participants=[finance, ops, risk]).build()
37 result = await workflow.run(task)
38 aggregated = result.get_outputs()[-1] # default aggregator: one message per agent
39 for msg in aggregated.messages:
40 print(f"[{msg.author_name}] {msg.text[:300]}\n")
41
42
43# --- C) Graph workflow: explicit executors + edges --------------------------
44@executor(id="publisher")
45async def publisher(response: AgentExecutorResponse, ctx: WorkflowContext[None, str]) -> None:
46 """A plain-Python node: format the last agent output as the workflow result."""
47 await ctx.yield_output(f"FINAL BRIEF\n===========\n{response.agent_response.text}")
48
49
50async def run_graph(task: str) -> None:
51 workflow = (
52 WorkflowBuilder(start_executor=research)
53 .add_edge(research, analysis)
54 .add_edge(analysis, recommend)
55 .add_edge(recommend, publisher)
56 .build()
57 )
58 # Stream events to watch each executor fire
59 async for event in workflow.run(task, stream=True):
60 if event.type == "executor_invoked":
61 print(f" > running {event.executor_id}")
62 elif event.type == "output" and isinstance(event.data, str): # skip token-level agent updates
63 print(event.data)
64
65
66async def main() -> None:
67 task = "Should we expand our AI Copilot product into the European market next year?"
68 print("=== SEQUENTIAL ===")
69 await run_sequential(task)
70 print("=== CONCURRENT ===")
71 await run_concurrent(task)
72 print("=== GRAPH ===")
73 await run_graph(task)
74
75
76if __name__ == "__main__":
77 asyncio.run(main())

Check your understanding

0/3

Q1.In a graph workflow, what is an executor?

Q2.How do you resume a workflow paused by request_info?

Q3.Triage agent routes a customer to Billing or Tech Support, who may route back. Pattern?

M5 · Multi-AgentM7 · Testing & RAI