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.
Prebuilt orchestrations
For common patterns, use the builders — one line each.
1from agent_framework.orchestrations import SequentialBuilder, ConcurrentBuilder23# Sequential: shared conversation flows through each agent4seq = 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}")910# Concurrent: fan-out to every participant, fan-in their answers11conc = ConcurrentBuilder(participants=[finance, ops, risk]).build()12aggregated = (await conc.run(task)).get_outputs()[-1]
Graph workflows with WorkflowBuilder
When you need custom logic between agents — validation, formatting, routing — mix agents and plain Python executors.
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}")45workflow = (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)
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.)
1@step2async def do_research(plan: str) -> str:3 return (await research.run(plan)).text45@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)
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_roundsbounds 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
Magentic
MagenticBuilder
Planner with task ledger, re-plans on stalls
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.
run(request)
Steps execute & are cached
request_info()
Workflow pauses, emits event
PAUSEDHuman reviews
Approve / edit / reject in your UI
run(responses={…})
Resume — cached steps skipped
Output
Final brief yielded
1wf = business_ops.build()2result = await wf.run("Reduce onboarding time by 30%")34event = result.get_request_info_events()[0] # workflow paused5print(event.data["draft"])6result = await wf.run(responses={event.request_id: "Approve — focus on EU"})7print(result.get_outputs()[-1]) # final brief
Key takeaways
Workflows = executors + typed edges, run in supersteps, observable via events.
SequentialBuilder / ConcurrentBuilder cover 80% of cases in one line.
WorkflowBuilder for custom graphs; @workflow + @step for code-first orchestration.
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
- 1Multi-Agent Studio → choose Coordinator mode (the capstone flow).
- 2Enable “Human approval before final brief”.
- 3Run a scenario; when it pauses, edit/annotate the draft and approve.
- 4Code Lab → Exercise 6: build Sequential + Concurrent workflows; stretch: WorkflowBuilder.
Reference solution — labs/ex6_workflows.py (verified on agent-framework-core 1.26)
1"""Exercise 6 — Sequential, concurrent and graph workflows (Module 6)."""23import asyncio45from agent_framework import Agent, AgentExecutorResponse, WorkflowBuilder, WorkflowContext, executor6from agent_framework.orchestrations import ConcurrentBuilder, SequentialBuilder7from common import make_client89client = make_client()101112def make_agent(name: str, instructions: str) -> Agent:13 return Agent(client=client, name=name, instructions=instructions)141516research = 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.")192021# --- 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 one24 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 far27 for msg in response.messages:28 print(f"[{msg.author_name}] {msg.text[:300]}\n")293031# --- 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 agent39 for msg in aggregated.messages:40 print(f"[{msg.author_name}] {msg.text[:300]}\n")414243# --- 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}")484950async 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 fire59 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 updates63 print(event.data)646566async 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)747576if __name__ == "__main__":77 asyncio.run(main())
Check your understanding
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?