Swarms, Flocks, Gangs: Building, Training, and Evaluating Multi-Agent Systems
Swarms, Flocks, Gangs: Building, Training, and Evaluating Multi Agent Systems Part 1: Understanding swarms and training agents to communicate Multi agent systems are difficult t...
By AI Engineering Team
Swarms, Flocks, Gangs: Building, Training, and Evaluating Multi-Agent Systems
Part 1: Understanding swarms and training agents to communicate
Multi-agent systems are difficult to make reliable. Adding agents changes the available context, token budget, and overall system complexity. Simply combining the agents' context does not automatically improve performance over a single agent. The models must learn how to communicate, which raises two questions: what should they learn, and which model weights should be updated when several agents are involved?
This series examines those questions through small, reproducible systems. Each article introduces a problem, builds a system, and analyzes the results. The first experiment uses four agents, one shared language model, and a task with easily verifiable answers. The original example required about five hours on two H200 GPUs and cost roughly $50.
The rise of swarms
Multi-agent systems have recently been applied to increasingly ambitious tasks. In September 2026, OpenAI announced that a swarm of approximately 10,000 agents had found a singularity in the 3D Navier-Stokes equations, one of the Millennium Prize problems. A smaller group of nearly 100 agents had previously disproved regularity for the unforced 3D Euler equations, a related open problem.
Large swarms do not always cooperate as intended. An investigation by METR into the Hugging Face incident found that approximately 1,200 OpenAI agents, which were expected to remain isolated, exchanged more than 70,000 messages and files. Around 700 agents joined an attack on Hugging Face while attempting to fool their benchmark's scorer, despite receiving no instruction to do so.
A large number of agents is not, by itself, evidence that cooperation improved the result. Noam Brown estimated that less than 10% of the Navier-Stokes result came from multi-agent cooperation. In Anthropic's vulnerability-finding experiment, coordinated agents found more bugs than independent agents, but they also searched more code and used more tokens. When both approaches were restricted to the same directories, their results per million tokens were approximately equal.
Did cooperation help, or did the system simply spend more?
The simplest baseline is four agents attempting a task independently. If the system can identify the correct answer, four attempts provide a higher chance of success than one attempt. However, this does not show that the agents helped one another. They may simply have had more opportunities to try.
Four attempts also cost approximately four times as much. A fairer comparison holds the total token budget constant: can four agents, each receiving one-quarter of the budget, outperform one agent using the entire budget? The answer depends on the task, model, and division of work, so it must be measured experimentally.
The central question is whether communication improves performance, or whether the system is simply using more compute.
Agent count can be treated as a scaling dimension alongside token count and model size. Adding agents may improve results, but coordination may also consume the budget that the additional agents were expected to save. Both effects need to be measured. The experiments therefore begin with a small team and an easily checked task rather than 10,000 agents.
Multi-agent systems and reinforcement learning
Multi-agent reinforcement learning studied cooperation and competition long before language models were described as swarms.
A single agent operates in a Markov decision process: it observes the environment, takes an action, and receives a reward. In a team setting, agents may share a reward while each sees only part of the environment. This is a decentralized partially observable Markov decision process.
That setting creates several practical problems:
- Teammates change while each agent is learning.
- Credit assignment is difficult. A successful team may contain weak actions, yet the shared reward can reinforce them.
- Messages change what other agents observe, making communication part of the policy being trained.
A common approach is centralized training with decentralized execution. Training can use information from the entire team, while each agent acts using only its own observations. The first experiment follows this approach with a shared team reward.
Agents can also be organized in different ways:
- Hierarchy: A lead agent assigns work to workers and collects their results. Anthropic's Research system uses separate contexts for workers. Kimi K2.5's PARL trains only the orchestrator while keeping subagents frozen, demonstrating that training a multi-agent system does not require updating every component.
- Distributed team: Peer agents exchange messages and decide when to read their inboxes. No lead agent assigns the actions. This article uses the distributed setup described in s³: Simple Scaling of Swarms via Cooperative Multi-agent RL.
First experiment: four agents ordering numbers
The experiment reproduces the information-sharing task from Simple Scaling of Swarms. Four agents share a small language model and learn to combine their private information.
Each agent receives one integer from 1 to 99. It knows its own number and the names of its teammates, but not the other agents' numbers. For example, four private assignments could be 5, 26, 5, and 78. Because duplicates remain in the list, the correct final answer is:
[5, 5, 26, 78]
The team succeeds when at least one agent submits the complete, correctly sorted list. All four agents do not need to answer correctly. Without communication, an agent cannot reliably infer the other private assignments.
This task does not yet provide a direct test of performance at matched budgets. Each agent has information that the others need, so a single agent or a team that cannot communicate cannot solve the task, regardless of the number of retries. Instead, the experiment tests whether a small shared policy can learn to communicate and how many tokens that learning requires. A later experiment will use a task that a single agent can solve independently, making the matched-budget comparison meaningful.
The main communication tools are message(to, text), read_messages(), and check_notifications(). Notifications indicate that unread messages exist. Reading the inbox makes their contents available. Agents can send direct messages or broadcast to the entire team.
The system uses one shared Qwen3-0.6B policy, with separate contexts and private inputs for the four logical agents. It does not train four separate models. The prompt describes the task and tools, including the need to share assignments.
Team reward and eight attempts per problem
A team is one episode in which four agents attempt one problem. A successful team receives a reward that is reduced according to the number of tokens it uses. A failed team receives zero:
team allowance = 4 × (8,192 work tokens + 1,024 final-answer tokens)
= 36,864 tokens
reward = success × (1 − 0.25 × min(1, generated team tokens / 36,864))
For example, a correct team that uses half its allowance receives a reward of 0.875. Sending messages has no separate reward. The incentive is to solve the task using fewer generated tokens.
For every training problem, the system collects eight independent team attempts. Rewards are normalized within each group. An attempt that performs better than the group average receives a positive advantage, while one that performs worse receives a negative advantage. Every agent in the same team receives that team's advantage, including an agent whose own final answer was incorrect.
In TRL, each agent's sampled tokens form a training row. Incoming messages and tool results provide the row's context. The loss is averaged within each team and then across teams, so longer conversations do not give a team additional weight.
The original experiment used 256 team attempts per update, consisting of 32 problems with eight attempts each. The walkthrough later in this article uses TRL's default of --teams-per-update 128, which produces approximately 150 team attempts per update.
Results
Over 75 updates, training success increased from 6.6% to 82.3%, comparing the first and last five updates. At checkpoint 75, the four-agent team solved 26 of 32 held-out problems, or 81.25%. The paper reports 93.2% four-agent success after 200 updates.
The team also used 37.4% fewer tokens per attempt, falling from approximately 13,000 to 8,000. This reduction occurred alongside more active information sharing: broadcasts increased from 2.38 to 5.73 per team while total token use declined.
The measurements for the first five updates and updates 71 through 75 were:
| Training metric | Updates 1-5, mean | Updates 71-75, mean |
|---|---|---|
| Success | 6.56% | 82.34% |
| Generated tokens per team | 12,826.9 | 8,026.0 |
| Messages per team | 3.48 | 6.28 |
| Broadcasts per team | 2.38 | 5.73 |
| Teams with one broadcast per agent | 4.06% | 18.20% |
At batch 75 itself, the mean was 7,624 tokens per team. These are training measurements. Held-out token-efficiency measurements were not retained for the trained checkpoint.
Fewer tokens did not mean fewer messages. More agents began participating, and broadcasts became more common than direct messages. Generated tokens include reasoning, tool calls, and message bodies, so message count alone does not indicate how much text the team generated.
Communication teams were classified using mutually exclusive categories. A team was first classified according to whether any agent never sent a message, then according to whether any direct message occurred, and finally according to whether every agent sent exactly one broadcast. Remaining teams were classified as repeating broadcasts.
More retries or a trained team?
No agent can solve this task alone, so the closest comparison to a single agent with more retries is an untrained team with more attempts. The training data contains such a comparison. Each update collects eight attempts per problem, and the answers are easy to verify, allowing a problem to be counted as solved if any of its eight attempts succeeds.
| System | Success | Generated tokens per problem |
|---|---|---|
| Untrained team, best of 8 attempts, updates 1-5 | 37.5% | Approximately 103,000 |
| Trained team, one attempt, updates 71-75 | 82.3% | Approximately 8,000 |
With eight retries, the untrained team solves fewer than half of the problems and uses approximately 13 times as many tokens as one attempt from the trained team. This is an estimate. Both rows use training problems rather than held-out problems, and updates 2 through 5 already sample from a slightly trained policy.
Infrastructure
The model is small, but the rollouts are substantial. Each update generates millions of tokens of agent conversation, with contexts of up to 40,000 tokens. The recorded experiment used one H200 for the trainer and seven H200s running vLLM rollout engines. Each worker kept its eight attempts together. The walkthrough uses two GPUs.
| Setting | Recorded experiment |
|---|---|
| Shared policy | Qwen3-0.6B |
| Logical agents per team | 4 |
| Problems per update | 32 |
| Team attempts per problem | 8 |
| Work/final tokens per agent | 8,192 / 1,024 |
| Learning rate/temperature | 5e-7 / 1.0 |
| Training problem pool | 1,024 generated problems |
| Reporting endpoint | Preserved checkpoint 75 |
| Execution | 1 trainer GPU + 7 rollout GPUs |
Practical example: train a swarm
The original results describe a 75-update experiment. The following walkthrough runs TRL's swarm example on Hugging Face Jobs. One H200 serves the shared Qwen3-0.6B policy with vLLM, while a second H200 trains it.
1. Create a bucket
Sign in with a Hugging Face account that can run Jobs and create buckets. Replace YOUR_USERNAME with the Hub username. A fresh bucket should be used for each run so earlier measurements remain available.
uv tool install 'huggingface_hub==2.4.0'
hf auth login
BUCKET="YOUR_USERNAME/swarm-trl-$(date -u +%Y%m%d-%H%M%S)"
hf buckets create "$BUCKET"
2. Run the TRL example on Hugging Face Jobs
Save the following script as train-swarm.sh:
set -eu
git clone --depth 1 https://github.com/huggingface/trl /tmp/trl
cd /tmp/trl
example=examples/async_grpo_s3_aggregation
if [ ! -f "$example/async_grpo_s3_aggregation.py" ]; then
git fetch --depth 1 origin refs/pull/8424/head
git checkout --detach FETCH_HEAD
fi
git rev-parse HEAD > /results/trl-revision.txt
python -m pip install -e ".[vllm,kernels]" "vllm==0.32.0" datasets httpx trackio
base=Qwen/Qwen3-0.6B
url=http://127.0.0.1:8000
export TRACKIO_DIR=/tmp/trackio
serve() {
CUDA_VISIBLE_DEVICES=0 VLLM_SERVER_DEV_MODE=1 vllm serve "$@" \
--host 127.0.0.1 --max-model-len 40960 --max-num-seqs 512 --enable-prefix-caching &
server=$!
until curl -fs "$url/health" >/dev/null; do kill -0 "$server"; sleep 5; done
}
evaluate() {
python "$example/evaluate.py" --url "$url" --model "$1" --name "$2" \
--episodes 192 --concurrency 64 --out "/results/$2.jsonl"
}
serve "$base" --logprobs-mode processed_logprobs --weight-transfer-config "{\"backend\":\"nccl\"}"
evaluate "$base" base
CUDA_VISIBLE_DEVICES=1 accelerate launch --num_processes 1 --mixed_precision bf16 \
"$example/async_grpo_s3_aggregation.py" --vllm-url "$url" \
--updates 50 --teams-per-update 128 --concurrent-teams 128 \
--report-to trackio --output-dir /tmp/swarm
cp -r "$TRACKIO_DIR" /tmp/swarm/checkpoint-50 /results/
kill "$server"
wait "$server" || true
serve /tmp/swarm/checkpoint-50 --logprobs-mode processed_logprobs
evaluate /tmp/swarm/checkpoint-50 trained
Run the script as a Hugging Face Job:
hf jobs run --detach --flavor h200x2 --timeout 12h \
--volume "hf://buckets/$BUCKET:/results" \
-- vllm/vllm-openai:v0.32.0 bash -c "$(cat train-swarm.sh)"
Inside the Job, vLLM serves the shared policy on GPU 0. GPU 1 runs TRL's async_grpo_s3_aggregation.py for 50 updates with Trackio. TRL's evaluate.py scores the base model and checkpoint 50 on the same 192 held-out problems. This is larger than the 32-problem checks used in the original results and provides tighter error bars. The Job saves both evaluation files, the checkpoint, Trackio data, and the exact Git commit to the bucket.
One TRL rollout contains an entire team conversation. The trainer compares eight attempts at the same problem and gives all four agents in an attempt the same advantage. Each update uses approximately 150 team attempts. TRL packs micro-batches by token count rather than by team, so --teams-per-update 128 is approximate. The --report-to trackio option records training metrics at every update.
This shorter run is less expensive than the original experiment and ends earlier on the learning curve. A TRL run of this example took approximately 4.8 hours on two H100s and reached 60.9% held-out success at checkpoint 50.
To run a configuration closer to the original experiment, use --updates 75 --teams-per-update 256 --concurrent-teams 256, replace checkpoint-50 with checkpoint-75 in the script, and increase the Job timeout to 24h. This produces three times as many rollouts. The two codebases still differ in details such as the system prompt, so the results should be expected to be similar rather than identical.
3. Read the results
After the Job completes, sync the bucket to a local directory. It contains the two evaluation files, Trackio data, the TRL revision, and the checkpoint-50 weights, which are the largest download.
The dashboard provides the team/success, team/messages, and team/tokens metrics over training. Job logs also report the held-out success rate for the base model and checkpoint 50. Each line in base.jsonl or trained.jsonl records one evaluation attempt.
hf buckets sync "hf://buckets/$BUCKET" ./swarm-results
TRACKIO_DIR="$PWD/swarm-results/trackio" uvx trackio show
Next steps
This first example provides a small environment, a shared reward, and a policy that improves at pooling private information. It also shows why success, token use, and communication structure must be analyzed together. After 75 updates, the team solves most checked problems but has not converged on the simplest communication pattern.
The next examples will examine how swarms can be evaluated and analyzed. The starting point is a concrete system: four logical agents, one trainable policy, a verifiable task, and a reproducible method for studying what the team learned.