Multi-Agent RL
AlphaGo beat Lee Sedol via self-play. Pluribus beat the top human poker pros via CFR. AlphaStar reached StarCraft Grandmaster via a league of agents. Cicero negotiated alliances in Diplomacy at human level. Every superhuman game-playing AI is multi-agent, and the moment you have two learners in the same room, the convergence proofs you grew up with stop working. This is where RL gets strange and beautiful.
After this lesson, you will be able to:
- Distinguish cooperative, competitive, and mixed multi-agent settings, and pick the right algorithm family for each
- Use self-play to train two-player zero-sum agents that converge to Nash equilibria, the recipe behind AlphaGo, AlphaZero, AlphaStar
- Apply Counterfactual Regret Minimization (CFR) to imperfect-information games like poker, the math that powers Pluribus and Cepheus
- Pick between centralized-critic (MADDPG / QMIX / MAPPO) and independent learners, and know why naive PPO often surprisingly works
Before you start
Don't worry if "multi-agent" sounds intimidating, once you have one PPO agent working, multi-agent is mostly variations on "let multiple PPO agents play each other and see what falls out". The hard parts are the math of equilibria and the tricks for stability.
#Three Multi-Agent Settings
#The Non-Stationarity Problem
The fundamental challenge of multi-agent RL: the environment changes because everyone keeps learning. Agent A's optimal policy depends on Agent B's policy. As B improves, A's previously-optimal policy becomes obsolete. Standard RL convergence proofs (Q-learning, PPO) assume a stationary environment, they don't apply.
The non-stationarity problem is why naive Q-learning often diverges in multi-agent settings, and why the workarounds below exist.
Where does the changing transition function come from? Open the derivation to see that it is just a sum over what the other agents might do, and a small matrix game shows the effect with numbers.
Try matching pennies first: press Play and watch two learners circle the equilibrium without settling, then switch to the prisoner's dilemma and fictitious play to compare.
#Self-Play: The Workhorse for Two-Player Zero-Sum
The recipe
- Initialize agent π_θ
- Generate games where π_θ plays against a copy of itself
- Train π_θ on the resulting (state, action, outcome) data
- Periodically save snapshots; sometimes play against past versions for stability
- Repeat
Two PPO agents are trained via self-play on rock-paper-scissors. After training, they each output approximately 33%/33%/33% probability for each move. Why?
The answer: rock-paper-scissors has a unique Nash equilibrium of uniform random play. Any agent that biases toward one move (say 50% rock) becomes exploitable, the other agent learns to throw paper. Self-play forces both into the equilibrium.
The answer 1/3 each can be derived by a single idea. At an equilibrium each player must leave the opponent indifferent between the actions the opponent actually plays. Open the derivation to see this for matching pennies and for rock-paper-scissors.
The minimax theorem quoted above is also a statement about a matrix game, and it has a short derivation through linear programming. Write the payoff to the maximizing player as A.
#CFR: Imperfect-Information Games
#Independent vs Centralized Critic
For cooperative or mixed-motive settings, the choice is between:
Where does the actor gradient come from? Open the derivation to see how the centralized critic enters the chain rule.
The factorization used by QMIX comes down to one property of the mixing function: it must never decrease when any agent's value goes up. Open the derivation to see why that makes the joint argmax split by agent.
#Real-World Multi-Agent Wins
| System | Year | Domain | Algorithm |
|---|---|---|---|
| TD-Gammon | 1995 | Backgammon | Self-play TD-λ |
| Cepheus | 2015 | Heads-up Limit Hold'em | CFR+ |
| AlphaGo | 2016 | Go | Sup. + RL self-play + MCTS |
| AlphaZero | 2018 | Chess/Shogi/Go | Pure self-play + MCTS |
| Pluribus | 2019 | 6-player No-Limit Hold'em | MCCFR + depth-limited search |
| AlphaStar | 2019 | StarCraft II | Population-based + IL bootstrap |
| OpenAI Five | 2019 | Dota 2 | Self-play PPO at massive scale |
| CICERO | 2022 | Diplomacy | RL + LLM negotiation |
#Hands-On
torch, which this page does not have, so it is read-only. Copy it to Google Colab to run it.# Copy to Colab: needs torch, so it cannot run on this page.
# Two-agent rock-paper-scissors via self-play with simple policy-gradient
import torch
import torch.nn as nn
import torch.optim as optim
import numpy as np
class RPSPolicy(nn.Module):
def __init__(self):
super().__init__()
# Pure prior — no state. Just learn the action distribution.
self.logits = nn.Parameter(torch.zeros(3))
def forward(self):
return torch.softmax(self.logits, dim=-1)
# Reward matrix: rows = player 1 action, cols = player 2 action
# 0=rock, 1=paper, 2=scissors
R = torch.tensor([
[ 0, -1, 1], # rock vs (rock, paper, scissors)
[ 1, 0, -1], # paper
[-1, 1, 0], # scissors
], dtype=torch.float32)
p1 = RPSPolicy()
p2 = RPSPolicy()
opt1 = optim.Adam(p1.parameters(), lr=0.05)
opt2 = optim.Adam(p2.parameters(), lr=0.05)
print("Training two RPS agents via self-play...")
for step in range(2000):
probs1 = p1()
probs2 = p2()
# Expected reward for each player under joint policy
expected_r1 = (probs1.unsqueeze(1) * probs2.unsqueeze(0) * R).sum()
expected_r2 = -expected_r1 # zero-sum
# P1 maximizes own reward, P2 minimizes P1's (= maximizes own)
loss1 = -expected_r1
loss2 = -expected_r2
opt1.zero_grad(); loss1.backward(retain_graph=True); opt1.step()
opt2.zero_grad(); loss2.backward(); opt2.step()
if step % 200 == 0:
with torch.no_grad():
p1d = p1().numpy().round(3)
p2d = p2().numpy().round(3)
print(f"step {step}: P1=[r={p1d[0]} p={p1d[1]} s={p1d[2]}] P2=[r={p2d[0]} p={p2d[1]} s={p2d[2]}] E[r1]={expected_r1.item():.4f}")
print("\nFinal policies (should converge to ~33% each — Nash equilibrium):")
with torch.no_grad():
print(f"P1: {p1().numpy().round(3)}")
print(f"P2: {p2().numpy().round(3)}")
print("\nCHALLENGE: Now make P1's reward matrix asymmetric (e.g., 'rock'")
print("gives 2 points, scissors gives 1). Check that the equilibrium shifts.")The block that follows runs here, because it uses only the Python standard library. Two learners play each other with a hand-written REINFORCE update. Watch the gap between the average policy and the policy at the last step.
Tests: Check that each agent's average policy over training is close to one third per move, while its policy at the final step is far from uniform.
#Key Takeaways
- Multi-agent introduces non-stationarity. Single-agent convergence proofs don't apply because each agent's environment changes as others learn; fixes include centralized critics, self-play, and population-based training
- Self-play converges to Nash for two-player zero-sum games. TD-Gammon, AlphaGo, AlphaZero, AlphaStar all rely on this; for multiplayer or imperfect-info, you need CFR or PBT
- CFR is the math behind poker AI. Track regret per information set, bias future play toward low-regret actions; powers Cepheus, Pluribus, and most modern poker bots
- CTDE (centralized training, decentralized execution) is the dominant cooperative framework: train with a critic that sees everything; deploy with actors that only see local observations
- Modern multi-agent LLM systems are emerging. CICERO, Constitutional AI debate, multi-agent debate frameworks, fusing RL ideas with LLMs is a current frontier
Interactive Lab
Watch multiple agents interact in cooperative and competitive scenarios, see policies emerge from self-play, observe non-stationarity in real time, and feel why centralized critics stabilize what independent learners cannot.
#Quick Check
Why does naive Q-learning often diverge in multi-agent settings even when the environment is otherwise simple?