Title: Lab 12 — Supervisor vs. Swarm: Building and Comparing Two Multi-Agent Architectures
Course: AIINFRA 300: Agentic AI & the Model Context Protocol (MCP) > Section: Week 12 — Multi-Agent Orchestration and Handoffs

🛠️ Lab 12 — Supervisor vs. Swarm: Building and Comparing Two Multi-Agent Architectures (50 pts)

Goal: Build the same multi-agent task two ways — once as a centralized supervisor hierarchy and once as a decentralized peer-to-peer swarm — using langgraph-supervisor, running entirely on free/local tools (Ollama or a free-tier hosted model). Trace which agent handled each step in both versions, and compare the control-vs-flexibility trade-offs directly.

Steps

1. Set up your environment. Install Ollama locally (or configure a free-tier hosted model of your choice) and pull a small instruction-tuned model (e.g., llama3.1:8b or similar). In a fresh Python virtual environment, install langgraph, langgraph-supervisor, and your LLM client library.
2. Define two specialist agents. Build a math agent (equipped with a calculator/Python-eval tool for arithmetic and simple computation) and a research agent (equipped with a web-search or document-lookup tool, or a stubbed "knowledge base" tool if you don't have search access). Give each a narrow, explicit system prompt describing only its specialty.
3. Build the centralized supervisor. Using langgraph-supervisor, create a top-level supervisor agent that receives a multi-part user request (design a prompt that genuinely needs both specialists, e.g., "Look up the current population of X and calculate what a 3% annual growth rate would produce in 10 years"). Use create_handoff_tool to let the supervisor hand off to each specialist, and have the supervisor aggregate both results into one final answer.
4. Instrument tracing. Add logging (simple print statements or LangGraph's built-in tracing/callbacks are fine) that records, for each step: which agent acted, what it received, and what it returned. Run your test prompt through the supervisor version and save the trace.
5. Build the decentralized version. Reimplement the same task as a peer-to-peer swarm: instead of a central supervisor, let the math agent and research agent hand off directly to each other as tools (no manager in between) whenever one needs the other's specialty to finish. Add the same tracing.
6. Run and compare. Run the same test prompt through both architectures. Capture both traces (supervisor version and swarm version) as text or screenshots.
7. Write your comparison (300–500 words). Discuss: Which version was easier to debug and why? Which handled an ambiguous or malformed handoff better? What failure mode would you worry about most in each architecture at production scale? Which would you choose for this specific task, and why?

Deliverables: Submit your two working scripts (or one script with a config flag toggling architecture), both traced run logs, and your written comparison, either as an upload (.py/.ipynb + .txt/.md files, zipped) or pasted directly into the text-entry box.