TAI BUI
Back to curriculum
BuildPython

Multi-Agent RL

Single-agent RL assumes the environment stays stationary. Put two learning agents in the same world and that assumption breaks: each agent is part of the other's environment, and both are moving targets. Multi-agent RL is the set of tricks that make learning converge anyway, once the Markov assumption no longer holds.

TIME: ~45 minutesPREREQUISITES: Phase 9 · 04 (Q-learning), Phase 9 · 06 (REINFORCE), Phase 9 · 07 (Actor-Critic)

Learning Objectives

  • Explain why the Markov property breaks down once multiple learning agents share an environment, and name the five core MARL challenges: non-stationarity, credit assignment, exploration coordination, scalability, and partial observability.
  • Distinguish the four dominant MARL regimes, independent learning (IQL/IPPO), centralized-training-decentralized-execution (MADDPG, COMA, MAPPO, QMIX), self-play, and league play, and explain when each one is the right fit.
  • Implement independent Q-learning and a centralized joint-Q update on a cooperative two-agent GridWorld, and explain why independent learning converges on loosely-coupled tasks but fails on tightly-coupled ones.
  • Diagnose the standard MARL failure modes, including reward hacking via coordination, policy drift, exploration redundancy, and sample explosion, and explain why a rising self-play win rate against a fixed snapshot can be a misleading signal.

The Problem

A robot learning to navigate a room is a single-agent RL problem. A soccer team is not. Neither is AlphaStar playing against StarCraft opponents, a marketplace of bidding agents, two cars negotiating a four-way stop, or any other many-on-many problem you can name.

In every multi-agent setting, from the perspective of any one agent, the other agents are part of the environment. As they learn and change their behavior, the environment becomes non-stationary — the ground keeps shifting while you're trying to stand on it. The Markov property (next state depends only on current state and my action) gets violated, because the next state also depends on what the other agents chose, and their policies are moving targets.

This breaks tabular convergence proofs: Q-learning's guarantee assumes a stationary environment. It breaks naive deep RL too. Agents chase each other in loops and never settle on a stable policy. You need multi-agent-specific techniques: centralized training with decentralized execution, counterfactual baselines, league play, self-play.

2026 applications include robot swarms, traffic routing, autonomous vehicle fleets, market simulators, multi-agent LLM systems (Phase 16), and any game with more than one intelligent player.

Warm-up0/3
1. In a single-agent MDP, what does the Markov property say?Warm-up
A 4 by 4 grid with a robot at cell (2,2), a dashed path of earlier moves from (0,0), and a card listing the move history, the current state (2,2) with action right, and the next state as a question mark.
2. In an actor-critic method, what does the critic do?Warm-up
Actor-critic diagram: the environment sends state and reward to the actor and critic, the actor sends actions to the environment, and a dashed arrow from critic to actor is labelled signal with a question mark.
3. In Q-learning, what does an epsilon-greedy policy do?Warm-up
Four bars of illustrative Q-values for one state (up 0.2, down 0.5, left 0.9, right 0.1) with epsilon 0.1, and a card for the epsilon-greedy policy at that state whose chosen action is a question mark.
Q-values are illustrative.
Check: The Problem0/2
1. Why does the Markov property break down when several learning agents share an environment?Explain
A 3 by 3 grid with agent A at the left middle and agent B at the right middle, and a card from A's view listing state, A's action right, and next state as a question mark, with B described as a second learning agent.
2. What does non-stationarity break in Q-learning theory?Explain
A line from about 0.8 down to about 0.2 over 300 training episodes showing how often one fixed state and action leads to a given next state, above the Q-learning update rule.
Illustrative curve for a state-action pair whose outcome depends on another learner.

The Concept

Four MARL regimes: indep, centralized critic, self-play, league

Formalism: Markov Game. A generalization of MDP: states S, a joint action a = (a_1, …, a_n), transition P(s' | s, a), and per-agent rewards R_i(s, a, s'). Each agent i maximizes its own return under its own policy π_i: identical rewards make the game fully cooperative, zero-sum rewards make it adversarial, and mixed rewards make it general-sum.

Core challenges:

  • Non-stationarity. P(s' | s, a_i) from agent i's view depends on π_{-i}, which is changing.
  • Credit assignment. With a shared reward, which agent caused it?
  • Exploration coordination. Agents need to explore complementary strategies, not redundantly cover the same state.
  • Scalability. The joint action space grows exponentially in n.
  • Partial observability. Each agent sees only its own observation; the global state stays hidden.

Four dominant regimes:

1. Independent Q-learning / independent PPO (IQL, IPPO). Each agent learns its own Q-function or policy and treats everyone else as part of the environment. It's simple, and it sometimes works, especially when experience replay doubles as a smoothing trick for modeling the other agent. Theoretical convergence: none. In practice: fine for loosely-coupled tasks, bad for tightly-coupled ones.

2. Centralized training, decentralized execution (CTDE). The most common modern paradigm. Each agent has its own policy π_i that conditions on local observation o_i, the standard setup for decentralized execution at deployment. During training, a centralized critic Q(s, a_1, …, a_n) conditions on the full global state and joint action. Examples:

  • MADDPG (Lowe et al. 2017): DDPG (a continuous-action actor-critic method) with a centralized critic per agent.
  • COMA (Foerster et al. 2017): a counterfactual baseline. It asks what my reward would have been had I taken action a' instead, which isolates my individual contribution.
  • MAPPO / IPPO with shared critic (Yu et al. 2022): PPO with a centralized value function. Dominant in 2026 for cooperative MARL.
  • QMIX (Rashid et al. 2018): value decomposition (Q_tot(s, a) = f(Q_1(s, a_1), …, Q_n(s, a_n))) with monotonic mixing.

3. Self-play. Two copies of the same agent play against each other. The opponent's policy is my policy from a past snapshot. AlphaGo / AlphaZero / MuZero. OpenAI Five. Works best for zero-sum games, where the training signal stays symmetric.

4. League play. An extension of self-play to general-sum / adversarial environments: keep a population of past and current policies, sample an opponent from the league, train against them. Adds exploiters (specialize in beating the current best) and main exploiters (specialize in beating exploiters). AlphaStar (StarCraft II) needed this, because the game admits "rock-paper-scissors" strategy cycles.

Communication. Let agents send learned messages m_i to each other. This works in cooperative settings. Foerster et al. (2016) showed that differentiable inter-agent communication can be trained end-to-end. Today's LLM-based multi-agent systems (Phase 16) mostly communicate in natural language instead.

Check: The Concept0/16
1. What is a Markov game, and what makes a setting fully cooperative rather than adversarial?Define
The Markov game tuple with joint action and per-agent rewards, above two small reward tables for illustrative 2-agent games, Game X with outcomes paying (+5,+5), (+1,+1) and (-1,-1), and Game Y with outcomes paying (+1,-1), (-1,+1) and (0,0).
2. What is the defining feature of centralized training, decentralized execution (CTDE)?Define
Two agents' policies pi_1 and pi_2, an environment holding the global state, per-agent observations o_1 and o_2, and a critic box, with the inputs of each policy and the critic marked with question marks.
3. What trick does COMA use for credit assignment?Define
Two agents that chose right and up, both feeding one team reward of +10, and a card where each agent sees +10 and agent 1's share of it is a question mark.
4. What is QMIX?Define
QMIX layout: three per-agent networks Q_1(o_1,a_1), Q_2 and Q_3 feed a box marked with a question mark that also reads the global state, producing Q_tot as one number for the team.
5. What is IPPO?Define
Three agents with actors pi_i(o_i) acting in one Environment box, and a card on the PPO update saying the advantage comes from a value function, with how many value functions there are and what they read left as a question mark.
6. What is MAPPO?Define
Three agents with actors pi_i(o_i) acting in one Environment box, and a card on the PPO update saying the advantage comes from a value function, with how many value functions there are and what they read left as a question mark.
7. What is self-play?Define
A tic-tac-toe board in progress with X and O marks, and a card saying the learning agent is theta_now, X is played by theta_now, the player of O is a question mark, and the result updates theta_now.
8. What is league play?Define
A card listing saved policies main_v1, main_v2, main_v3, exploiter_1, main_exploiter_1 and main_now, and an episode box saying main_now plays a question mark.
Policy names are illustrative.
9. Why does a shared team reward create a credit assignment problem?Explain
A three-step episode table: agent actions per step and the same reward for both agents each step (-1, -1, then +10 at step 3), with a card asking each agent which of its actions caused the +10.
Actions are illustrative.
10. Why did AlphaStar need league play when AlphaGo Zero could use plain self-play?Explain
Two cards side by side: AlphaGo Zero, game Go, two players, zero-sum, pure self-play against its own policy; and AlphaStar, game StarCraft II, two players competing, league play with past and current opponents and exploiters.
11. Why does self-play fit zero-sum games best?Explain
A table of three outcomes of a game between two copies of one agent: A wins pays +1 to A and -1 to B, B wins pays -1 and +1, draw pays 0 and 0.
12. Why does QMIX mix the per-agent Q-values monotonically?Explain
Two small illustrative tables of per-agent Q-values for three actions each, and a card with Q_tot = f(Q_1(a_1), Q_2(a_2)), nine joint actions, and a note that the goal is the joint action with the largest Q_tot.
Values are illustrative.
13. In cooperative MARL, how can agents learn to send each other messages m_i?Explain
Two cooperating agents, each observing its own o_i, exchanging messages m_1 and m_2 by arrows, with a card saying m_i is a learned vector and asking how it is trained.
14. Two cooperative agents only succeed if both step onto the goal on the exact same turn. Independent Q-learning treats the other agent as part of a black-box environment and never converges, since neither can predict when the other will act. What does this coordination requirement call for?Analyze
A rule that the goal counts only if both agents step onto it on the same turn, a two-row table of attempts in which the agents step onto G on turns 6 and 9 (not the same turn) and on turns 7 and 7 (same turn), and a card saying independent Q-learning updates each agent's own Q-table and treats the other as part of the environment.
Turn numbers are illustrative.
15. MAPPO agents were trained with the global state fed into every policy network. On deployed robots that only receive local sensor data, performance collapses. Which assumption failed?Analyze
Two cards: in training the policy and critic both take global state s with a shared reward; on a deployed robot the sensors give only local data o_i while the policy still expects global state s, and performance collapses.
16. A general-sum multiplayer game has rock-paper-scissors style strategy cycles. Which training regime fits?Design
Three strategy boxes A, B and C joined by arrows in a ring, A beats B, B beats C and C beats A, for a general-sum multiplayer game.
Strategies are generic placeholders.

Build It

This lesson uses a 6×6 GridWorld with two cooperative agents. They start in opposite corners and must reach a shared goal. Shared reward: -1 per step while either agent is still moving, +10 when both arrive. See code/main.py.

Step 1: the multi-agent env

python
class CoopGridWorld:
    def __init__(self):
        self.size = 6
        self.goal = (5, 5)
 
    def reset(self):
        return ((0, 0), (5, 0))  # two agents
 
    def step(self, state, actions):
        a1, a2 = state
        new1 = move(a1, actions[0])
        new2 = move(a2, actions[1])
        done = (new1 == self.goal) and (new2 == self.goal)
        reward = 10.0 if done else -1.0
        return (new1, new2), reward, done

The joint action space is |A|² = 16. The global state is just two positions.

Step 2: independent Q-learning

Each agent keeps its own Q-table keyed on the joint state. Every step, both pick ε-greedy actions, the environment returns a joint transition, and each agent updates its own Q-table off the shared reward.

python
def independent_q(env, episodes, alpha, gamma, epsilon):
    Q1, Q2 = defaultdict(default_q), defaultdict(default_q)
    for _ in range(episodes):
        s = env.reset()
        while not done:
            a1 = epsilon_greedy(Q1, s, epsilon)
            a2 = epsilon_greedy(Q2, s, epsilon)
            s_next, r, done = env.step(s, (a1, a2))
            target1 = r + gamma * max(Q1[s_next].values())
            target2 = r + gamma * max(Q2[s_next].values())
            Q1[s][a1] += alpha * (target1 - Q1[s][a1])
            Q2[s][a2] += alpha * (target2 - Q2[s][a2])
            s = s_next

This works here because the rewards are dense and aligned. It fails on tightly-coupled tasks, where one agent has to wait for the other.

Step 3: centralized Q with a decomposed-value update

Use one Q over joint actions, Q(s, a_1, a_2), updated from the shared reward. Decentralize at execution time by marginalizing: π_i(s) = argmax_{a_i} max_{a_{-i}} Q(s, a_1, a_2). You trade an exponential joint action space for a correct global view.

Step 4: simple self-play (adversarial 2-agent)

Same agent, two roles. Train agent A against agent B, and every K episodes copy A's weights into B. Training stays symmetric and progress stays consistent. It's the AlphaZero recipe in miniature.

Check: Build It0/6
1. Why can independent Q-learning solve the lesson's GridWorld yet fail when one agent must wait for the other?Explain
The lesson's 6 by 6 GridWorld with the goal cell G at (5,5) and no start cells marked, a card with the shared reward of -1 per step and +10 when both are on the goal, and a card describing a variant where agent 2 must wait for agent 1 before it moves.
The variant is a sketch, not code from the lesson.
2. In the cooperative GridWorld, two agents each choose from 4 actions. How large is the joint action space?Apply
Two cards listing the four actions up, down, left, right for agent 1 and for agent 2, an example joint action (up, left), and a note asking for the size of the joint action space.
3. In CoopGridWorld.step, agent 1 is on the goal (5, 5) and its action leaves it there, while agent 2 moves onto (5, 5). What does step return for reward and done?Apply
A 6 by 6 grid with the goal at (5,5), agent 1 on the goal and agent 2 at (4,5) with an arrow onto the goal, next to the step function code that computes done and reward.
Agent 2's start cell is illustrative.
4. In independent_q with gamma = 0.5, a step gives r = -1 and max Q1[s_next] is 10. What is target1?Apply
The independent_q target line with the given values r = -1, gamma = 0.5 and max Q1[s_next] = 10, and target1 left as a question mark.
5. At state s the centralized Q, written Q(a1, a2), is Q(0,0)=1, Q(0,1)=5, Q(1,0)=3, Q(1,1)=4. Using argmax over own action of the max over the other agent's actions, what do agents 1 and 2 choose?Apply
A 2 by 2 table of the centralized Q with Q(0,0)=1, Q(0,1)=5, Q(1,0)=3, Q(1,1)=4 and the two decentralized argmax-of-max rules.
6. In the lesson's miniature self-play recipe (train A against B, copy A's weights into B every K episodes), how many copies have happened after 350 episodes with K = 100?Apply
A pseudocode card with K = 100 and a loop over 350 episodes that trains A against B and copies A's weights into B every K episodes, above an episode axis with ticks every 50 episodes from 0 to 350.
Pseudocode restates the stem's recipe.

Pitfalls

  • Non-stationary replay. Experience replay is worse for independent agents than for a single agent, because old transitions came from opponents whose policies have since moved on. Relabel the stored transitions or weight them by recency.
  • Credit assignment ambiguity. A shared reward lands at the end of a long episode with no clean way to say which agent caused it. Counterfactual baselines (COMA) or per-agent reward shaping are the usual fixes.
  • Policy drift / chasing. Each agent's best response keeps shifting as the others update, so nobody settles. Use a centralized critic, slow the learning rate, or freeze one agent at a time.
  • Reward hacking via coordination. Agents find coordinated exploits nobody designed for: auction agents converging to bid zero is the classic example. Careful reward design and behavioral constraints are the fix.
  • Exploration redundancy. Both agents explore the same state-action pairs and waste the run. Per-agent entropy bonuses or role-conditioning fix that.
  • League cycles. Pure self-play can get stuck in a dominance cycle. League play with diverse opponents breaks it.
  • Sample explosion. n agents × state space × joint actions grows fast. Approximate it: function approximation, factored action spaces, one policy head per agent.
Check: Pitfalls0/7
1. Which example of reward hacking via coordination does the Pitfalls section give?Define
The seven pitfall names from the lesson's Pitfalls section as a table, with the row for reward hacking via coordination highlighted, and a card describing it as agents finding coordinated exploits nobody designed for and asking for the example the section gives.
2. Why is experience replay worse for independent multi-agent learners than for a single agent?Explain
A replay buffer table for agent 1 listing five transitions with the episode they were collected in (40, 120, 310, 495, 500) and the partner agent's policy at that episode, the last row marked now.
Entries are illustrative.
3. What is policy drift (chasing) in MARL, and what helps?Explain
Two lines over 200 update steps showing the probability of playing heads for two learners in matching pennies, each moving to improve its own payoff against the other, both swinging up and down without settling.
Computed here: gradient ascent, step 0.05, start p=0.7, q=0.4.
4. What fix does the lesson suggest for exploration redundancy, where both agents explore the same state-action pairs?Explain
Two 6 by 6 grids shading the cells each of two agents visited over 20 simulated episodes from the same start, and a card counting 26 cells for agent 1, 22 for agent 2 and 21 visited by both.
Simulated here, not the lesson's code: greedy = step toward (5,5), epsilon 0.3, 40 steps per episode, seed 7.
5. What is the sample explosion pitfall?Explain
A table for n = 2, 3, 4 and 6 agents on the 36-cell GridWorld with 4 actions each, showing joint states, joint actions and the number of table entries.
Computed from 36^n and 4^n.
6. A self-play agent keeps beating its latest copy, yet an older snapshot beats it, and that snapshot loses to another in a loop. Which pitfall is this, and what is the lesson's fix?Analyze
Four boxes: agent, latest copy, older snapshot and another snapshot, with arrows from winner to loser: agent beats latest copy, older snapshot beats agent, another snapshot beats older snapshot.
7. A team grows from 2 to 10 agents, and a single centralized table Q(s, a_1, ..., a_n) no longer fits in memory. What went wrong, and what is a fix?Analyze
Two panels: a team of 2 agents whose centralized table Q(s, a_1, ..., a_n) fits in memory, and a team of 10 agents whose table does not fit.

Use It

The 2026 MARL application map:

DomainMethodNotes
Cooperative navigation / manipulationMAPPO / QMIXCTDE; shared critic + decentralized actors. Covers robot swarms and warehouse/fleet coordination.
Two-player games (chess, Go, poker)Self-play with MCTS (AlphaZero)Zero-sum; symmetric training.
Complex multiplayer (Dota, StarCraft)League play + imitation pretrainingOpenAI Five, AlphaStar.
Autonomous-vehicle fleets / traffic routingCTDE MAPPO / PPO with attentionPartial obs; variable team sizes.
Auction marketsGame-theoretic equilibrium + RLMean-field RL when n → ∞.
LLM multi-agent systems (Phase 16)Natural-language comm + role conditioningRL loop at the agent-planning layer.

MARL's biggest growth area in 2026 is LLM-based: swarms of language-model agents negotiating, debating, and building software together. The RL there shows up as preference optimization on trajectory-level outputs, not token-level (Phase 16 · 03).

Check: Use It0/1
1. A fleet of autonomous vehicles has variable team sizes and each vehicle sees only part of the scene. Which method does the application map recommend?Apply
Two scenes of a vehicle fleet, one with 3 vehicles and one with 5, each vehicle with a dashed circle for its limited view, and a one-row table with the domain autonomous-vehicle fleets, method as a question mark and notes partial observation and variable team sizes.

Ship It

Save as outputs/skill-marl-architect.md:

markdown
---
name: marl-architect
description: Pick the right multi-agent RL regime (IPPO, CTDE, self-play, league) for a given task.
version: 1.0.0
phase: 9
lesson: 10
tags: [rl, multi-agent, marl, self-play]
---
 
Given a task with `n` agents, output:
 
1. Regime classification. Cooperative / adversarial / general-sum. Justify.
2. Algorithm. IPPO / MAPPO / QMIX / self-play / league. Reason tied to coupling tightness and reward structure.
3. Information access. Centralized training (what global info goes to the critic)? Decentralized execution?
4. Credit assignment. Counterfactual baseline, value decomposition, or reward shaping.
5. Exploration plan. Per-agent entropy, population-based training, or league.
 
Refuse independent Q-learning on tightly-coupled cooperative tasks. Refuse to recommend self-play for general-sum with cycle risks. Flag any MARL pipeline without a fixed-opponent eval (cherry-picked self-play numbers are common).
Check: Ship It0/3
1. A self-play system's win rate against its own frozen snapshot climbs past 90%, but drops back to roughly 50% the moment it faces a completely different opponent. What does this most likely mean?Analyze
A curve of win rate against a frozen snapshot rising from 0.5 to above 0.9 over 60 checkpoints, and one point at the last checkpoint at about 0.5 labelled vs new opponent.
Curve is illustrative: the last point is the stem's roughly 50 percent.
2. You built a MARL system that trains only against snapshots of itself and must report real progress. What evaluation should you add?Design
A pipeline in which an agent theta_t plays a snapshot theta_t-1 during self-play training, feeding a box that says report progress with a question mark.
3. Warehouse robots must hand items off at the same moment, share one team reward, and each sees only its local view at deployment. Which design fits?Design
A warehouse floor with robots R1 and R2 each seeing only a dashed local circle, an item between them to be handed off at the same moment, and a card saying the team reward is one shared number and the view at deployment is local only.
Author's Note

The failure mode that actually got me was self-play. Win rate against a fixed snapshot climbs past 90%, which feels like real progress, right up until you swap in a fresh opponent and it collapses back to 50-50 — both networks got better together, so nothing an outside observer would call "skill" actually moved. If you're shipping a MARL system, freeze an external benchmark opponent early and keep re-running it every checkpoint. Win rate against your own past self is close to meaningless on its own.

Exercises

  1. Easy. Train independent Q-learning on the 2-agent cooperative GridWorld. How many episodes does it take before mean return crosses 0? Plot the joint learning curve.
  2. Medium. Add a "coordination" task where the goal only counts if both agents step onto it on the same turn. Does independent Q still converge? What breaks?
  3. Hard. Implement a centralized critic for MAPPO-style training and compare its convergence speed to independent PPO on the coordination task.

Key Terms

TermWhat people sayWhat it actually means
Markov game"Multi-agent MDP"(S, A_1, …, A_n, P, R_1, …, R_n); each agent has its own reward.
CTDE"Centralized training, decentralized execution"Joint critic at training time; each agent's policy uses only local obs.
IPPO"Independent PPO"Each agent runs PPO separately. Simple baseline; often underrated.
MAPPO"Multi-agent PPO"PPO with a centralized value function conditioned on global state.
QMIX"Monotonic value decomposition"Q_tot = f_monotone(Q_1, …, Q_n) allows decentralized argmax.
COMA"Counterfactual multi-agent"Advantage = my Q minus expected Q marginalizing over my action.
Self-play"Agent vs past self"Single agent, two roles; standard for zero-sum games.
League play"Population training"Cache past policies, sample opponents from the pool; handles strategy cycles.

Further Reading

Code

Ships With