Swarms, Flocks, Gangs: How to build, train, and evaluate multi-agent systems

Multi‑agent swarms can learn to communicate and solve tasks more efficiently, but the benefit depends on budget‑matched comparisons and careful training design.

Swarms, Flocks, Gangs: How to build, train, and evaluate multi-agent systems

Swarms, Flocks, Gangs: Building, Training, and Evaluating Multi‑Agent Systems

Multi‑agent systems (MAS) have moved from theoretical reinforcement‑learning labs to practical deployments on affordable hardware. This article walks through the core ideas, challenges, and a reproducible example that lets you train a small swarm on Hugging Face Jobs.

---

1. Why Swarms Matter – and What to Measure

A swarm is simply a collection of agents that share a common goal while each sees only a fragment of the environment. The hype around massive swarms (e.g., 10 000‑agent Navier‑Stokes experiments) often masks a key question: does communication itself improve performance, or are we just spending more compute?

To answer that, we need a budget‑matched comparison:

  • Independent baseline – multiple agents solve the same problem without talking, each receiving a fraction of the total token budget.
  • Cooperative baseline – the same agents can exchange messages, still respecting the same overall token limit.

If the cooperative team outperforms the independent baseline under equal budgets, we have evidence that communication adds value.

---

2. Core Challenges in Multi‑Agent RL

| Challenge | Why It Matters | Typical Remedy | |-----------|----------------|----------------| | Non‑stationary teammates | Each agent’s policy changes during training, making the environment appear unstable. | Centralized training with access to all agents’ observations. | | Credit assignment | A shared reward does not reveal which agent’s action contributed most. | Compute a team‑wide advantage and apply it uniformly to all agents in the episode. | | Communication as policy | Sending a message changes what other agents observe, so the message itself is an action. | Treat tool calls (`message`, `read_messages`) as part of the action space and train them jointly. |

A common recipe is centralized training, decentralized execution: during learning we feed each agent the full team context, but at inference time each agent only sees its own observations and inbox.

---

3. A Minimal, Reproducible Swarm

The example below follows the Simple Scaling of Swarms (s³) information‑aggregation task. It is deliberately tiny so you can run it on two NVIDIA H200 GPUs in ~5 hours (~$50).

3.1 Task definition

  1. Four agents each receive a private integer between 1 and 99.
  2. The goal is to output the sorted list of all four numbers.
  3. Success is achieved when any agent submits the correct list.
  4. Agents share a single 0.6 B Qwen‑3 model; each has its own conversation context.

3.2 Communication primitives

  • `message(to, text)`: send a direct or broadcast message.
  • `read_messages()`: retrieve unread inbox entries.
  • `check_notifications()`: flag whether new messages exist.

These tools are exposed to the model via the TRL (Transformer Reinforcement Learning) framework, allowing the policy to decide when and what to communicate.

3.3 Training loop (high‑level)

```text for each update: sample 32 problems for each problem: run 8 independent team attempts collect rewards (team success × token‑efficiency) compute advantage = attemptreward - mean(teamrewards) back‑propagate on all agents using the same advantage ``` The reward penalises token usage: ``` teamallowance = 4 × (8192 work tokens + 1024 answer tokens) reward = success × (1 - 0.25 × min(1, usedtokens / team_allowance)) ``` Thus agents are incentivised to solve the task while keeping the conversation short.

---

4. What the Numbers Tell Us

| Metric | Early updates (1‑5) | Late updates (71‑75) | |--------|--------------------|----------------------| | Success rate | 6.6 % | 82.3 % | | Tokens per team | ~12.8 k | ~8.0 k | | Messages per team | 3.5 | 6.3 | | Broadcasts per team | 2.4 | 5.7 |

Key observations:

  • Success skyrockets once the policy discovers a reliable communication protocol.
  • Token consumption drops by ~37 % despite more messages, indicating that agents learn to convey information concisely.
  • Broadcasts become dominant; a simple “share my number” broadcast is cheaper than a series of direct exchanges.

These trends validate the central hypothesis: cooperation can reduce compute when agents learn to exchange the right information efficiently.

---

5. Practical Steps to Build Your Own Swarm

  1. Create a bucket on Hugging Face to store logs and checkpoints.
  2. Launch the TRL job using the provided `run_swarm.py` script (specify `--model qwen3-0.6b`, `--agents 4`).
  3. Monitor the `teamsuccess` and `tokensper_team` metrics via the Jobs UI.
  4. Iterate: try different reward shapes (e.g., add a small bonus for each broadcast) or scale the number of agents.
  5. Evaluate on a held‑out set with the same token budget to confirm that gains generalise.

---

6. Looking Ahead

The next post in this series will shift to a single‑agent solvable task (e.g., sorting a list given all numbers) so we can directly compare independent vs. cooperative agents under identical budgets. That will let us answer the headline question more cleanly: When does communication truly help?

---

Takeaway: Building a swarm starts with a clear budget‑matched benchmark, a shared policy, and a simple communication API. With those pieces, even a modest 0.6 B model can learn to coordinate, cut token usage, and dramatically improve success rates. The same framework scales to larger models and more complex hierarchies, opening the door to practical, affordable multi‑agent AI.

Source

Read original source

Why we picked this

Core AI research on building and evaluating multi-agent systems.

← Back to all articles