Hugging Face Swarms, Flocks, Gangs: How to build, train, and evaluate multi-agent systems
Understanding Multi-Agent Training
Building effective multi-agent systems requires more than simply deploying multiple models; it necessitates training agents to communicate effectively to solve tasks. Simply adding agents to a system does not inherently boost performance and can often lead to increased compute costs without proportional gains in capability. The core challenge lies in determining whether communication provides a genuine performance benefit or if the system is merely consuming more tokens to achieve the same result.
Multi-Agent Reinforcement Learning and Communication
Multi-agent systems are modeled as decentralized partially observable Markov decision processes where agents share a team reward but possess only partial views of the environment. Training these systems involves three primary hurdles:
- Non-stationarity: Teammates evolve as they learn, changing the environment for each other.
- Credit Assignment: Determining which specific actions within a team contributed to a successful outcome.
- Communication Policy: Integrating messaging into the agent's policy so that communication itself is learned rather than hard-coded.
Centralized training with decentralized execution is a common approach, where the system is trained using global information but agents act based on individual observations.
Experimental Results: Information Pooling
In an experiment using four agents sharing a single Qwen3-0.6B policy, agents were tasked with pooling private integers to produce a correctly sorted list. Success was defined as at least one agent submitting the complete, accurate list.
Training results over 75 updates showed significant improvement:
- Success Rate: Increased from 6.6% to 82.3%.
- Token Efficiency: Generated tokens per team decreased by 37.4%, dropping from approximately 13,000 to 8,000 tokens per attempt.
- Communication Patterns: Broadcasts increased from 2.38 to 5.73 per team, indicating that agents learned to favor broader communication over direct messaging as they became more efficient.
When compared to an untrained team, the trained system solved 82.3% of problems in a single attempt, whereas an untrained team required eight attempts to solve fewer than half the problems while consuming 13 times more tokens.
Implementation and Infrastructure
The experiment utilized a shared policy architecture where agents operated with separate contexts but a common reward signal. The training loop involved collecting eight independent team attempts per problem, with rewards normalized within each group to calculate an advantage.
Reproducing these results requires significant compute resources, as each update generates millions of tokens of conversation. The provided walkthrough uses Hugging Face Jobs and the TRL library, utilizing two H200 GPUs: one for serving the shared policy via vLLM and one for training. This setup allows for the evaluation of base models against trained checkpoints on held-out problem sets, providing a baseline for measuring communication efficacy and token efficiency.