Lab 03 — MSAF / AutoGen Orchestration Patterns
Phase 23 · Lab 03 · Phase README · Warmup · Hitchhiker's
The problem
Above the raw team/Workflow primitives, both AutoGen and MSAF ship a small library of named orchestration patterns, because ~90% of multi-agent systems are one of a handful of shapes. Knowing them as a vocabulary — and being able to build each in ten lines — is what lets you say "that's a bounded handoff with a validated target" in a design review instead of hand-waving. This lab builds four of them as tiny deterministic orchestrators over injected agent policies (group-chat is Lab 01), cross-referencing Phase 07's multi-agent coordination but focused on the framework-named patterns.
What you build
| Pattern | What it does | Bound / invariant |
|---|---|---|
sequential(agents, task) | a chain: each agent's output feeds the next (pipeline) | the cheapest, most auditable shape (a workflow) |
concurrent(agents, task, aggregator=) | fan-out the same task to all, fan-in via an aggregator | agents are independent; run deterministically in list order |
handoff(agents, task, start) | an agent transfers to a named next agent (HANDOFF: name: ctx) | target validated; chain bounded by max_steps |
magentic(manager, team, task) | a manager keeps a progress ledger, assigns subtasks, synthesizes | assignee validated; bounded by max_rounds; ledger recorded |
Helpers you also build: parse_handoff (directive → target + content), parse_directive
(ASSIGN:/FINAL: → the manager's next move), and ProgressLedger (the manager's working memory —
Magentic-One's ledger).
File map
| File | Role |
|---|---|
lab.py | your implementation (Agent, dataclasses, and ProgressLedger given; fill the four orchestrators) |
solution.py | reference + a worked example: all four patterns over one little team |
test_lab.py | 25 tests: chaining, fan-in merges (default + custom aggregator + order), handoff routing/validation/bounding, magentic assign+ledger+synthesis+bound, determinism |
requirements.txt | pytest only |
Run it
pytest test_lab.py -v # your lab.py (red until you implement)
LAB_MODULE=solution pytest test_lab.py -v # the reference (green)
python solution.py # all four patterns worked end-to-end
Success criteria
-
sequentialchains outputs (each agent sees the previous output) and records(name, output)steps. -
concurrentfans the same task to every agent, preserves list order, and merges via the default or a custom aggregator (e.g. "pass only if all approve"). -
handoffroutes to the named agent, terminates on a non-handoff (FINAL) with the right path, rejects an unknown target, and stops atmax_stepson a handoff cycle. -
magenticassigns subtasks from the ledger, records(agent, subtask, result), synthesizes a final answer, bounds rounds, and rejects an unknown assignee. -
Every pattern is deterministic. All 25 tests pass under both
labandsolution.
How this maps to the real stack
sequentialis MSAF'sSequentialBuilder/ AutoGen sequential orchestration — a fixed pipeline, really a workflow (Phase 00).concurrentis MSAF'sConcurrentBuilder/ AutoGen concurrent orchestration; the aggregator is the fan-in reducer, and independence (each agent sees only the task) is what lets the real runtime parallelize.handoffis the OpenAI Agents SDKhandoffand AutoGen Swarm transfer: a structured in-bandtransfer_to_<agent>signal, with the target validated at construction and the chain bounded — the same least-context, target-validated handoff you built in Phase 07 Lab 01.magenticis Magentic-One (Microsoft Research) made a first-class pattern: an orchestrator/manager with a progress ledger that plans, delegates to specialists, observes progress, and synthesizes — bounded by rounds. The ledger is the reliability lever (Phase 00): explicit progress tracking lets the manager detect being stuck and re-plan.ProgressLedgeris Magentic-One's task ledger + progress ledger; a real manager also tracks facts, guesses, and a stall counter to decide when to reset.
Limits of the miniature. Agents are pure policies (no model, no tools, no network); concurrent
is modeled deterministically in list order (real fan-out runs in parallel, but the result is
order-independent, so this is faithful to the result); handoff/magentic directives are parsed from a
simple text convention rather than real tool calls; the magentic manager's re-planning is only as
smart as the injected policy. The coordination shapes — chain, fan-out/fan-in, dynamic transfer,
manager-with-ledger — and their bounds and validations are exactly this.
Extensions (your own machine)
- Concurrent aggregators. Implement majority-vote, best-of-N (score each output with a judge agent, Phase 11), and a debate aggregator (two opposing agents + a judge); compare.
- Real parallelism. Run
concurrentwithconcurrent.futuresand confirm the result is identical to the deterministic list-order version — proving independence. - Handoff context policies. Add least-context vs full-history handoff (Phase 04/07) and measure the
token difference; add a
HandoffTerminationthat stops when control returns to a human. - Magentic stall detection. Add a stall counter to
ProgressLedger(no new entry across N rounds → the manager re-plans or resets), mirroring Magentic-One's orchestrator. - Compose the patterns. Nest them — a magentic manager whose "specialist" is itself a sequential pipeline or a concurrent ensemble — showing magentic subsumes the others.
Interview / resume signal
"Built the AutoGen/MSAF orchestration patterns from scratch — sequential, concurrent (fan-out/fan-in with a pluggable aggregator), dynamic handoff (validated target, bounded chain), and a Magentic-One-style manager driving from a progress ledger (bounded rounds, validated assignees, explicit synthesis) — each over agents injected as pure policies, with the coordination invariants (chains, merges, routing, bounds, ledger) proved deterministically. Naming the pattern and its bound is the design-review move; the magentic manager subsumes the rest and is Microsoft's flagship for open-ended multi-specialist tasks."