Training Multi-Agent Swarms with Cooperative RL & TRL on H200

Hugging Face's "Swarms, Flocks, Gangs" research demonstrates how to train decentralized peer LLM teams via Cooperative Multi-Agent Reinforcement Learning (MARL) in TRL. Using a shared Qwen3-0.6B policy, inbox messaging tools, and a token-penalized team reward on `s³`, trained 4-agent swarms jump from 37.5% best-of-8 success (103,000 tokens) to 82.3% single-attempt success using ~8,000 tokens (13x fewer).
Training Multi-Agent Swarms with Cooperative RL & TRL on H200: Hugging Face's "Swarms, Flocks, Gangs" research demonstrates how to train decentralized peer LLM teams via Cooperative Multi-Agent Reinforcement Learning (MARL) in TRL. Using a shared Qwen3-0.6B policy, inbox messaging tools, and a token-penalized team reward on `s³`, trained 4-agent swarms jump from 37.5% best-of-8 success (103,000 tokens) to 82.3% single-attempt success using ~8,000 tokens (13x fewer). Designed as a zero-dependency, open-source TypeScript architecture under the MIT License with native Model Context Protocol (MCP) support and deterministic phase state machines.
- 13x Token Efficiency vs Untrained Retries: Trained 4-agent teams solve 82.3% of episodes in ~8,000 tokens per problem, beating untrained best-of-8 attempts (37.5% at ~103,000 tokens).
- Decentralized Peer Messaging Primitives: Agents coordinate through `message(to, text)`, `read_messages()`, and `check_notifications()` without a hardcoded orchestrator.
- Token-Budgeted Team Reward Shaping: Applies `reward = success * (1 - 0.25 * min(1, team_tokens / 36864))` across 8 group rollouts per problem so teams learn concise broadcast protocols.
- Reproducible 2x H200 TRL Recipe: Runs 1 vLLM rollout GPU (`Qwen3-0.6B`, 40K context) + 1 BF16 trainer GPU via `async_grpo_s3_aggregation.py` in ~5 hours (~$50 on HF Jobs).
import { createAgent } from '@smoke-monkey/harness';const swarmPeer = createAgent({agentId: 'swarm-marl-peer-01',provider: 'custom',baseUrl: 'http://127.0.0.1:8000/v1',model: '/tmp/swarm/checkpoint-50',workspacePath: process.cwd(),permissions: {read_file: 'allow',write_file: 'allow',run_command: 'ask',},mcpServers: {swarmBus: {command: 'npx',args: ['-y', '@smoke-monkey/mcp-agent-bus', '--peers', '4'],},},});async function runPeerAggregation() {const result = await swarmPeer.run('Call check_notifications() and read_messages(), exchange partial environment observations with peers via message(to, text), and emit the verified aggregate state.');console.log('Swarm Peer Result:', result.summary);}runPeerAggregation().catch(console.error);
Watch: Related Video Guides
Learning Cooperative Strategies for Drone Swarms Using Multi-Agent RL
Multi-agent Reinforcement Learning (MARL) for LLMs
What Is Cooperative Swarm RL? Matched Budgets vs Compute Churn
Cooperative Swarm RL applies Centralized Training with Decentralized Execution (CTDE) to multi-agent LLM teams so peers learn concise communication protocols rather than burning extra tokens. Without training, multi-agent systems often fail matched-budget checks: Anthropic's vulnerability experiment showed per-million-token bug yield stayed flat under directory constraints, and METR documented 1,200 isolated agents exchanging 70,000+ unprompted messages.
Following *s³: Simple Scaling of Swarms via Cooperative Multi-agent RL*, Hugging Face modeled a 4-agent decentralized partially observable MDP (Dec-POMDP) where each agent receives one private integer (1–99) and must collaborate via message(to, text), read_messages(), and check_notifications() until at least one peer outputs the sorted 4-number list.
Trained Swarm vs Untrained Retries & Hyperparameter Matrix
Training a single shared Qwen3-0.6B policy for 75 updates (32 problems per update, 8 team attempts per problem, 1,024 generated problems total) transformed both success rate and message topology—shifting agents from silent or wasteful direct chatter toward concise broadcasts (7,624 mean tokens at batch 75).
| Regime / Metric | Untrained Team (Best of 8, Updates 1–5) | Trained Swarm (1 Attempt, Updates 71–75) | Delta |
|---|---|---|---|
| Problem Success Rate | 37.5% | 82.3% | +44.8 pts |
| Tokens Spent per Problem | ~103,000 tokens | ~8,000 tokens | ~13x Reduction |
| Shared Policy & Context | Qwen3-0.6B (40K max) | Qwen3-0.6B (40K max) | Same model weights |
| Reward Formula | success × (1 - 0.25 × min(1, tok/36864)) | Group-normalized across 8 attempts | Length-averaged per team |
Note that both rows are measured on training problems (with updates 2–5 already partially updated) rather than held-out evaluation splits, demonstrating the rapid learning dynamic of team-level GRPO.
Avoid Long-Conversation Gradient Bias
In TRL, each agent's sampled tokens become a training row while incoming messages act as context. Loss is averaged within each team first and then across teams so verbose conversations never dominate gradient updates.
Reproducing the 2x H200 TRL Async GRPO Swarm Run
While the original 75-update paper run used 1 trainer H200 and 7 vLLM rollout H200s (lr=5e-7, temperature=1.0), TRL's async_grpo_s3_aggregation example runs cleanly on 2 H200 GPUs (~5 hours, ~$50 on Hugging Face Jobs) using NCCL weight transfer.
# Clone TRL and launch 1 vLLM rollout server + 1 BF16 trainer on 2x H200
git clone --depth 1 https://github.com/huggingface/trl /tmp/trl && cd /tmp/trl
python -m pip install -e ".[vllm,kernels]" "vllm==0.32.0" datasets httpx trackio
CUDA_VISIBLE_DEVICES=0 VLLM_SERVER_DEV_MODE=1 vllm serve Qwen/Qwen3-0.6B \
--host 127.0.0.1 --max-model-len 40960 --max-num-seqs 512 --enable-prefix-caching \
--logprobs-mode processed_logprobs --weight-transfer-config '{"backend":"nccl"}' &
CUDA_VISIBLE_DEVICES=1 accelerate launch --num_processes 1 --mixed_precision bf16 \
examples/async_grpo_s3_aggregation/async_grpo_s3_aggregation.py \
--vllm-url http://127.0.0.1:8000 --updates 50 --teams-per-update 128 --concurrent-teams 128Applying Matched-Budget Swarm Metrics in Smoke Monkey
Inside Smoke Monkey Harness and native swarm workflows, spawning multiple agents only pays off when coordinated agents beat an equivalent-token single-agent baseline. Logging per-team token spend and enforcing explicit inbox notification checks prevents the multi-agent coordination overhead from eroding total solve rate.
Frequently Asked Questions
Q:Why compare a 4-agent swarm against matched token budgets rather than pass@k?
Giving four agents independent runs multiplies compute by 4x, which inflates success simply via extra retries. A fair comparison checks whether four agents given 1/4 of the token budget each outperform a single agent spending the full budget.
Q:Do all 4 agents in the Hugging Face swarm run separate model weights?
No. All four logical agents share a single Qwen3-0.6B policy with separate contexts and private inputs; gradients from all four trajectories update that shared checkpoint.
Q:How is credit assignment handled when only one peer submits the answer?
The team receives a shared reward (1 minus up to 0.25 based on total team tokens out of 36,864) whenever at least one agent outputs the sorted list, and every agent in that team receives the group-normalized advantage.
Q:What hardware is needed to reproduce the TRL swarm example?
You need two NVIDIA H200 GPUs: GPU 0 serves the shared Qwen3-0.6B model via vLLM with NCCL weight syncing and 40K context, while GPU 1 runs the BF16 TRL async GRPO trainer.
Related Alternatives & Comparisons
Related Architecture Guides
View all guidesBest Open Source Coding Agents in 2026: Free, Local & Fully Hackable Harnesses
MCP Server Security Best Practices: Hardening Model Context Protocol Agents in 2026
Open Source Coding Agent Harness: Build a Forkable, Local AI Engineering Runtime
Build with Smoke Monkey Harness
Zero dependencies. 24 built-in tools. Human-in-the-loop safety. 100% open source under the MIT License.