How Multi-Agent Systems and Swarms Are Taught in the AI Engineering from Scratch Curriculum

The curriculum teaches multi-agent systems and swarms through a 25-lesson progressive journey in Phase 16, moving from historical FIPA foundations to production-grade orchestration using a unified four-primitive model.

The AI Engineering from Scratch repository structures its approach to multi-agent systems and swarms as a comprehensive pedagogical scaffold spanning Phase 16. Rather than jumping directly to API implementations, the curriculum grounds students in distributed systems theory, architectural patterns, and reliability engineering before they deploy production-grade agent collectives.

The Scaffolded Learning Path

The curriculum organizes its 25 lessons as a strict progression from motivation to implementation. Instruction begins with 01-why-multi-agent, which establishes when multi-agent architectures outperform single-agent pipelines through parallelism and specialization. Historical context follows in 02-fipa-acl-heritage, tracing communication standards that inform modern SDKs like OpenAI Agents.

Core communication patterns emerge in 03-communication-protocols, covering message-passing, request-reply cycles, and publish-subscribe topologies. By 05-supervisor-orchestrator-pattern, students analyze flat versus hierarchical supervision models and their respective failure modes. The architecture deepens through 06-hierarchical-architecture and 09-parallel-swarm-networks, comparing centralized control against decentralized star, ring, and mesh topologies.

Advanced coordination mechanisms appear in the latter half. 11-handoffs-and-routines introduces the handoff primitive central to OpenAI Swarm, while 14-consensus-and-bft implements Byzantine Fault Tolerance for adversarial environments. Reinforcement learning foundations arrive via 20-marl-maddpg-qmix-mappo, exploring CTDE, IPPO, and QMIX algorithms. The phase culminates in 25-case-studies-2026-sota, dissecting production systems from Anthropic and Microsoft.

The Four-Primitive Mental Model

A unifying conceptual framework appears in 04-primitive-model, which distills every multi-agent system into four irreducible components: Agent, Handoff, Shared State, and Orchestrator. This abstraction allows students to analyze any framework—whether AutoGen, MetaGPT, or OpenAI Swarm—through a consistent lens.

According to phases/16-multi-agent-and-swarms/04-primitive-model/outputs/skill-primitive-mapper.md, the mapping function demonstrates how these primitives manifest across different implementations. OpenAI Swarm implements handoffs as tool calls returning new LLM prompts, while AutoGen GroupChat uses a global message pool for shared state and a GroupChat manager as the orchestrator.

Implementation Skills with Code Examples

The curriculum provides executable, framework-agnostic utilities that implement these primitives directly. These snippets from the outputs/ directory translate theory into runnable Python.

Primitive Mapping Utility

In phases/16-multi-agent-and-swarms/04-primitive-model/outputs/skill-primitive-mapper.md, the map_to_primitives function classifies any framework:


# Primitive‑Model Mapper (Python)

from typing import Dict

def map_to_primitives(framework: str) -> Dict[str, str]:
    """
    Return a dict describing the four MAS primitives for the given
    framework name.
    """
    mapping = {
        "OpenAI Swarm": {
            "agent": "LLM‐based agent",
            "handoff": "tool call returning a new LLM prompt",
            "shared_state": "conversation history (JSON)",
            "orchestrator": "Swarm runtime that routes handoffs"
        },
        "AutoGen GroupChat": {
            "agent": "LLM agent",
            "handoff": "function call",
            "shared_state": "global message pool",
            "orchestrator": "GroupChat manager"
        },
        # ... add more frameworks as needed

    }
    return mapping.get(framework, {})

Handoff Designer

The make_handoff factory in phases/16-multi-agent-and-swarms/11-handoffs-and-routines/outputs/skill-handoff-designer.md creates callable handoff primitives:


# Handoff Designer (Python)

def make_handoff(name: str, description: str, schema: dict):
    """Return a function that an LLM can call as a handoff."""
    def handoff(**kwargs):
        # In a real system this would invoke an external tool.

        return {"status": "ok", "payload": kwargs}
    handoff.__name__ = name
    handoff.__doc__ = description
    handoff.schema = schema
    return handoff

Consensus Configurator

For reliable multi-agent decision-making, phases/16-multi-agent-and-swarms/14-consensus-and-bft/outputs/skill-consensus-configurator.md provides a BFT voting implementation:


# Simple BFT Consensus (Python)

from collections import Counter

def bft_consensus(proposals: list, quorum: int) -> str:
    """
    Accepts a list of proposals from agents and returns the value
    that reaches the required quorum. Raises if no quorum is reached.
    """
    counts = Counter(proposals)
    for value, cnt in counts.items():
        if cnt >= quorum:
            return value
    raise ValueError("Quorum not reached")

From MARL to Production Engineering

The curriculum bridges classical optimization and modern LLM-based agents. 19-swarm-optimization-pso-aco covers Particle Swarm Optimization and Ant Colony Optimization for combinatorial tasks, while 20-marl-maddpg-qmix-mappo introduces Multi-Agent Reinforcement Learning algorithms including MADDPG, MAPPO, and QMIX for training cooperative policies.

Production reliability appears in 14-consensus-and-bft through Byzantine Fault Tolerance mechanisms like PBFT and Raft-style quorums. 22-production-scaling-queues-checkpoints translates research prototypes into durable services using persistent work queues and checkpointing. Security-conscious developers reference 23-failure-modes-mast-groupthink, which catalogs 14 specific failure modes including collusion, token-gating, and hallucination loops.

Evaluation and Real-World Case Studies

Rigorous evaluation methodologies appear in 24-evaluation-coordination-benchmarks, which introduces the MARLBench and MARBLE suites. These provide standardized metrics for coordination, latency, and cost across star, chain, tree, and graph network topologies.

The final lesson, 25-case-studies-2026-sota, analyzes three production-grade implementations: Anthropic's research infrastructure, Microsoft's Swarm platform, and the OpenAI Agents SDK. Students extract practical patterns for agent economies, token-based incentives, and market-driven resource allocation from these real-world architectures.

Summary

  • The curriculum structures multi-agent systems and swarms education as a 25-lesson progression from FIPA history to production deployment.
  • All frameworks map to the four-primitive model (Agent, Handoff, Shared State, Orchestrator) taught in 04-primitive-model.
  • Implementation utilities in outputs/skill-*.md files provide framework-agnostic code for primitives, handoffs, and consensus.
  • MARL algorithms (MADDPG, QMIX, MAPPO) and classical swarm optimization (PSO, ACO) provide complementary optimization foundations.
  • Production lessons cover Byzantine Fault Tolerance, durable queues, and a catalog of 14 specific failure modes for secure deployment.

Frequently Asked Questions

What prerequisites are needed before starting Phase 16 on multi-agent systems?

Students should possess working knowledge of single-agent LLM patterns, function calling, and basic reinforcement learning concepts. The curriculum assumes familiarity with agent state management and API integration before introducing distributed coordination challenges.

How does the four-primitive model help when choosing between frameworks like OpenAI Swarm and AutoGen?

By mapping any library to the four primitives—Agent, Handoff, Shared State, and Orchestrator—you can immediately identify architectural mismatches. For example, if your application requires complex shared memory, the blackboard pattern taught in 13-shared-memory-blackboard may suit you better than simple message-passing implementations.

What is the difference between hierarchical supervision and parallel swarm networks?

Hierarchical supervision (05-supervisor-orchestrator-pattern) uses a central coordinator to delegate tasks and monitor outcomes, suitable for workflows requiring strict ordering. Parallel swarm networks (09-parallel-swarm-networks) employ decentralized topologies like mesh or ring structures that minimize latency for large-scale agent collectives operating on shared objectives.

Which failure modes are most critical when deploying multi-agent systems to production?

According to 23-failure-modes-mast-groupthink, critical risks include collusion (agents coordinating against system goals), token-gating (resource exhaustion through excessive communication), and hallucination loops (agents amplifying false information). The curriculum teaches mitigation through checkpointing, quorum consensus via bft_consensus(), and explicit communication cost budgeting.

Have a question about this repo?

These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →