这是一系列面向有抱负读者的博客文章。我们(我们,社区,你)想要构建自己的智能体群体,因为它们令人兴奋、充满挑战,且能力日益增强。此外,如果我们能训练自己的智能体以群体方式协作,那将极其酷。而如果这些群体使用的是小型且负担得起的模型,那就更加酷炫了。
这就是我们要在这系列文章中做的事情!每篇博客文章都将包含关于构建群体的背景信息,以及你可以在 Hugging Face Jobs 上运行的可复现示例。本文的示例在两块 H200 GPU 上运行大约需要五小时,成本约为 50 美元。
多智能体系统很难让其正常工作。增加智能体会改变智能体的上下文、预算,进而改变整个系统的复杂性。通过通信混合智能体的上下文,并不一定比单个智能体带来性能提升。模型需要通过训练来学习如何沟通。我们如何定义模型应该学习什么?当我们处理多个智能体时,我们要更新哪些模型权重?
在本系列中,我们将通过教育性的概述和实用的例子来解决这些问题。每篇文章都会提出一个问题,构建一个小系统,并检查发生的情况以及如何复现它。这个第一个示例从四个智能体、一个共享的语言模型和一个简单的可验证任务开始。它非常适合你自己实现、 tinkering(折腾)和学习。
从最简单的情况开始。如果四个智能体各自独立尝试一个任务,只要我们能判断哪个答案是正确的,那么至少有一个成功的概率就高于单次尝试。这使得多智能体系统有了一个有用的基线,但这并不能显示智能体之间互相帮助了。它们可能只是有了更多的尝试机会。
四次尝试的成本也是四倍。因此,更公平的比较是在同等预算下:如果每个智能体只获得总 token 的四分之一,它们是否还能击败花费所有 token 的一个智能体?只有通过测试才能找出答案,因为答案取决于任务、模型和工作分配方式。
图 1. 我们要测试的预期草图:在匹配的预算下比较沟通和独立的智能体。
我们将把智能体数量视为一个扩展维度,与 token 数量和模型大小并列。有时增加智能体会带来帮助。有时协调会消耗我们希望节省的预算。关键在于衡量两者。我们不会从 10,000 个智能体开始。我们会从一个小型团队在一个我们可以轻松检查的任务上开始。
单个智能体的任务是一个马尔可夫决策过程:观察、行动、获得奖励。在一个团队中,每个人都共享奖励,但每个智能体只能看到世界的一部分。这是一个去中心化的部分可观察马尔可夫决策过程:队友,但没有人能看到全貌。
这造成了三个实际问题。首先,队友在不断变化,而每个智能体都在学习。其次,信用分配:当团队成功时,哪些行动值得归功于谁?一个获胜的团队可能包含弱小的行动,而我们可能会最终奖励它们。第三,一条消息会改变其他智能体的观察内容,因此沟通是我们正在训练的策略的一部分。
一个常见的解决方案是集中式训练与去中心化执行:训练使用来自整个团队的信息,但每个智能体仅根据其自身的观察采取行动。我们的第一个示例遵循这种模式,使用共享的团队奖励。
每个智能体接收一个从 1 到 99 的整数。它知道自己的分配及其队友的名字。它最初不知道其他智能体的数字。例如,四个私有分配可能是“五”、“二十六”、“五”和“七十八”。重复的数字保留在列表中,所以正确的最终答案是:
这意味着该任务尚未直接测试图 1。每个智能体持有其他人需要的信息,因此无论重试多少次,单个智能体或没有消息传递的团队都无法成功。相反,该任务测试的是图 1 背后的前提条件:一个小共享策略能否学会沟通,以及这需要多少 token?稍后的文章将转向一个单个智能体可以单独解决的任务,其中匹配预算的比较是有意义的。
图 2. 任务和训练循环。私有数字说明了一个可能的成功片段;此图形不是记录的对话,也不是关于在第 75 次更新时学到的协议的声明。
对于每个训练问题,我们收集八个独立的团队尝试。它们的奖励在该组内进行归一化。表现优于其组平均水平的尝试获得正优势;表现较差的尝试获得负优势。同一团队中的每个智能体都会获得该团队的优势,即使其自己的最终答案是错误的。
图 3. 蓝色曲线描述了在每次更新之前收集的 256 个团队尝试的训练批次。橙色点是所示更新后的保留检查。
查看原文
Part 1: Understanding swarms and training to communicate
This is an aspirational blog series for aspirational readers. We (us, the community, you) want to build our own agent swarms because they're exciting, challenging, and increasingly capable. Furthermore, it would be extremely cool if we could train our own agents to work in a swarm. And exponentially cool if those swarms used small and affordable models.
That's what we'll do in this series! Each blog post will include some context on building swarms, alongside reproducible examples that you can run on Hugging Face Jobs. This post's example takes about five hours on two H200s, which costs roughly $50.
Multi-Agent Systems are hard to get working. Adding agents changes the agent's context, the budget, and in turn the complexity of the whole system. Mixing agents' context together through communication is not an inherent performance boost compared to a single agent. The model needs to learn to communicate through training. How do we define what models should learn? And which model weights do we update when we're dealing with many agents?
In this series, we'll work through those problems with an educational overview and practical examples. Each post will introduce a question, build a small system, and examine what happens and how you can reproduce it. This first example starts with four agents, a shared language model, and a simple verifiable task. It's ideal to implement yourself, to tinker with, and to learn from.
First, we'll start off with some context on swarms.
The rise of the swarms
We've heard a lot about swarms over the past few months, both good and bad. In September this year, OpenAI announced that a swarm of roughly 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 already disproved regularity for the unforced 3D Euler equations, a closely related open problem.
But swarms don't always work on the problems we want them to. METR's investigation of the Hugging Face incident found that around 1,200 OpenAI agents, which were supposed to be isolated, had found a way to exchange over 70,000 messages and files. Around 700 joined an attack on Hugging Face while looking for ways to fool their benchmark's scorer, without instruction to do so.
A big swarm isn't, by itself, evidence that cooperation helped. Noam Brown estimates 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 also searched more code and used more tokens. When the comparison was restricted to the same directories, the results per million tokens were about the same.
Did cooperation help, or did we just spend more?
Start with the simplest case. If four agents each try a task independently, the chance that at least one gets it right is higher than with a single attempt, as long as we can tell which answer is correct. That makes a useful baseline for a multi-agent system, but it doesn't show that the agents helped each other. They may simply have had more tries.
Four attempts also cost four times as much. So the fairer comparison is at an equal budget: if each of four agents gets a quarter of the total tokens, can they still beat one agent that spends all of them? We can only find out by testing, because the answer depends on the task, the model and how the work is divided.
This series keeps asking one question: when agents communicate, does it actually help, or are we just spending more compute?
We understand that question through this simple expectation.

Figure 1. Sketch of the expectation we want to test: compare communicating and independent agents at matched budgets.
We'll treat agent count as a scaling dimension, alongside tokens and model size. Sometimes adding agents will help. Sometimes coordination will consume the budget we hoped to save. The point is to measure both. We won't start with 10,000 agents. We'll start with a small team on a task that we can check easily.
Multi-agent Systems and Reinforcement Learning
Multi-agent reinforcement learning has studied cooperation and competition long before language models were called swarms.
A single agent's task is a Markov decision process: observe, act, get a reward. In a team, everyone shares the reward, but each agent sees only part of the world. This is a decentralized partially observable Markov decision process: teammates, but no one sees the whole picture.
This creates three practical problems. First, teammates keep changing while each agent learns. Second, credit assignment: when the team succeeds, which actions deserve the credit? A winning team can include weak actions, and we may end up rewarding them. Third, a message changes what other agents observe, so communication is part of the policy we're training.
A common solution is centralized training with decentralized execution: training uses information from the whole team, but each agent acts only on its own observations. Our first example follows this pattern with a shared team reward.
Agents can also be organized in different ways. Two useful starting points are:
-
A hierarchy. A lead agent assigns work to workers and collects their results. Anthropic's Research system works this way, with a separate context for each worker. Kimi K2.5's PARL trains only the orchestrator and keeps the subagents frozen, so training a multi-agent system doesn't mean updating every component. See Anthropic's system description and Kimi's technical blog.
-
A distributed team. Peers send each other messages and decide when to read their inboxes. No lead agent assigns the actions. This is the setup we'll use here, following the information-aggregation task in s³: Simple Scaling of Swarms via Cooperative Multi-agent RL.
Our first experiment: four agents ordering numbers
We'll reproduce the information-sharing task from Simple Scaling of Swarms because it's interpretable and straightforward to implement. Four agents share a small language model and learn to pool what each of them knows.
Each agent receives one integer from 1 to 99. It knows its own assignment and its teammates' names. It does not initially know the other agents' numbers. For example, four private assignments might be "five", "twenty-six", "five" and "seventy-eight". Duplicates stay in the list, so a correct final answer is:
#### [5, 5, 26, 78]
The team succeeds when at least one agent submits the complete, correctly sorted list. One correct answer is enough; success does not require all four agents to answer correctly. An agent cannot reliably infer the other private assignments without information from its teammates.
This means the task does not yet test Figure 1 directly. Each agent holds information the others need, so a single agent, or a team without messaging, cannot succeed however many retries it gets. Instead, the task tests the precondition behind Figure 1: can a small shared policy learn to communicate at all, and how many tokens does that cost? A later post moves to a task that a single agent can solve alone, where the matched-budget comparison is meaningful.
The main communication tools are message(to, text), read_messages(), and check_notifications(). A notification tells an agent that unread messages exist; reading its inbox makes their contents available. Agents can send direct messages or broadcast to everyone.
We defined a four-agent system using one shared Qwen3-0.6B policy, with separate contexts and private inputs. We are not training four different models. The prompt explains the task and the tools, including the need to share assignments.

Figure 2. The task and training loop. The private numbers illustrate a possible successful episode; this graphic is not a recorded conversation or a claim about the learned protocol at update 75.
A team reward and eight attempts at each problem
In this post, a team means one episode: four agents attempting one problem once. A successful team receives a reward reduced by the 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 illustration, a correct team using half its allowance receives 0.875. There is no separate reward for sending messages. The incentive is to solve the task while using fewer generated tokens.
For every training problem, we collect eight independent team attempts. Their rewards are normalized within that group. An attempt that does better than its group average gets a positive advantage; one that does worse gets a negative advantage. Every agent in the same team receives that team's advantage, including an agent whose own final answer was wrong.
In TRL, each agent's sampled tokens form a training row. Its incoming messages and tool results provide context. The loss is averaged within each team and then across teams, so longer conversations do not give a team more weight.
Our results come from the original experiment, which used 256 team attempts per update (32 problems with eight attempts each). The walkthrough uses TRL's default of --teams-per-update 128, which works out to about 150 team attempts per update.
Our Results
Over 75 steps, training success rose 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 (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 about 13k to 8k. This improvement accompanied more active information sharing: broadcasts increased from 2.38 to 5.73 per team, even as total token use fell.
Figure 3. The blue curve describes training batches of 256 team attempts, collected before each update. Orange points are held-out checks after the indicated update.
The team also used fewer tokens later in training. Comparing the first five updates with updates 71–75:
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%
That is a 37.4% reduction in generated tokens per training team between those windows. At batch 75 itself, the mean was 7,624 tokens per team. These are training measurements; we did not retain held-out token-efficiency measurements for the trained checkpoint.
Notice that fewer tokens did not mean fewer messages. More agents began participating but broadcasting became more common, rather than direct messaging. Generated tokens include reasoning and tool calls as well as message bodies, so message count alone does not tell us how much text the team produced.
Figure 4. Top: training token use and a trailing five-update mean. Bottom: mutually exclusive communication classes, based on sent-message events. A team is classified first by whether some agent never sends, then whether any direct message occurs, then whether every agent sends exactly one broadcast; the remaining teams repeat broadcasts.
More retries or a trained team?
No agent can solve the problem alone, so the closest equivalent of "a single agent with more retries" is the untrained team with more retries. The training data already contains this comparison. Each update collects eight attempts per problem, and the task's answers are easy to check, so we can count a problem as solved when any of its eight attempts succeeded. Early in training, that count gives the untrained team's best-of-8 success rate:
Success
Generated tokens per problem
Untrained team, best of 8 attempts (updates 1–5)
37.5%
about 103,000
Trained team, one attempt (updates 71–75)
82.3%
about 8,000
With eight retries, the untrained team solves fewer than half the problems and spends about 13 times as many tokens as one attempt from the trained team. Read this as an estimate. Both rows use training problems rather than held-out ones, and updates 2–5 already sample from a slightly trained policy.
Infrastructure
The model is small, but the rollouts are not. Each update generates millions of tokens of agent conversation at contexts of up to 40k tokens. We used one H200 for the trainer and seven H200s running vLLM rollout engines to get through those rollouts quickly, and kept each worker's eight attempts together. The walkthrough below runs the same task on two GPUs. Here are the infra details:
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 your own swarm
The figures above describe our original 75-update experiment. In this walkthrough we'll run TRL's swarm example on Hugging Face Jobs. One H200 serves the shared Qwen3-0.6B policy with vLLM and a second H200 trains it.
1. Create a bucket for the run
Sign in with a Hugging Face account that can run Jobs and create buckets. Replace YOUR_USERNAME with your Hub username.
Use a fresh bucket for each run so earlier measurements stay 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 script below as train-swarm.sh in your current directory.
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
The command below sends its contents to the job. 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. That is a larger set than the 32-problem checks in our results, which gives tighter error bars. The job saves both scores, the checkpoint, Trackio data and the exact Git commit to your bucket.
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)"
One TRL rollout contains a whole 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 about 150 team attempts. TRL packs micro-batches by token count rather than by team, so the --teams-per-update 128 setting is approximate. The --report-to trackio flag records training metrics at every update.
This shorter run is cheaper than our original experiment, and it stops earlier on the learning curve. TRL's run of this example took about 4.8 hours on two H100s and reached 60.9% held-out success at checkpoint 50.
To run closer to our original experiment, change the training flags to --updates 75 --teams-per-update 256 --concurrent-teams 256, replace checkpoint-50 with checkpoint-75 in the script, and raise the job's --timeout to 24h. That is three times as many rollouts. The two codebases still differ in details such as the system prompt, so expect similar results rather than an exact replication.
3. Read the results
Once the job completes, sync the bucket to a local folder. It holds the two evaluation files, the Trackio data, the TRL revision and the checkpoint-50 weights, which are the largest download. In the dashboard, compare team/success, team/messages and team/tokens over training. The job logs also give the held-out success rate for the base model and checkpoint 50. Each line of base.jsonl or trained.jsonl records one of those evaluation attempts.
hf buckets sync "hf://buckets/$BUCKET" ./swarm-results
TRACKIO_DIR="$PWD/swarm-results/trackio" uvx trackio show
What we'll try next
This first example gives us 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 need to be read together. At 75 updates, the team is solving most checked problems, but it has not converged to the cleanest communication pattern.
In the coming examples, we'll take a step back from training and look at how we evaluate and analyze swarms.
For now, we have something concrete to build on: four small agents, one trainable policy, a checkable task, and a reproducible way to examine what the team learned.