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

PatternWhat it doesBound / 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 aggregatoragents 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, synthesizesassignee 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

FileRole
lab.pyyour implementation (Agent, dataclasses, and ProgressLedger given; fill the four orchestrators)
solution.pyreference + a worked example: all four patterns over one little team
test_lab.py25 tests: chaining, fan-in merges (default + custom aggregator + order), handoff routing/validation/bounding, magentic assign+ledger+synthesis+bound, determinism
requirements.txtpytest 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

  • sequential chains outputs (each agent sees the previous output) and records (name, output) steps.
  • concurrent fans 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").
  • handoff routes to the named agent, terminates on a non-handoff (FINAL) with the right path, rejects an unknown target, and stops at max_steps on a handoff cycle.
  • magentic assigns 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 lab and solution.

How this maps to the real stack

  • sequential is MSAF's SequentialBuilder / AutoGen sequential orchestration — a fixed pipeline, really a workflow (Phase 00). concurrent is MSAF's ConcurrentBuilder / 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.
  • handoff is the OpenAI Agents SDK handoff and AutoGen Swarm transfer: a structured in-band transfer_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.
  • magentic is 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.
  • ProgressLedger is 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 concurrent with concurrent.futures and 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 HandoffTermination that 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."