Search

Search papers and lessons

Counterfactual Multi-Agent Policy Gradients

Jakob Foerster, Gregory Farquhar, Triantafyllos Afouras et al. · 2017

COMA trains decentralised agents with a centralised critic and a per-agent counterfactual baseline, which gives each agent its own credit for a shared team reward.

On this page

  • Colour = topic mix
  • Probability
  • Reinforcement learning
  • Discrete math
  • Calculus
  • Linear algebra
  • Microeconomics
  • ReadReady to readNot yet

TL;DR

COMA, short for counterfactual multi-agent policy gradients, is a method for teams of agents that learn together in a simulator and act separately in the world. A single critic that can see the full state and every agent's action estimates the value of the team's joint action. For each agent, COMA then compares that value with the average value over the agent's own alternative actions, holding the teammates' actions fixed. That difference is the agent's credit for the team reward. On a decentralised version of StarCraft micromanagement, the paper reports that COMA beats the other multi-agent actor-critic methods it tests, and that its best agents are competitive with centralised controllers.

Builds on: Actor-Critic Methods, Markov Game, partially observable Markov decision process, Advantage Function · Leads to: Centralized Training with Decentralized Execution, QMIX: Monotonic Value Function Factorisation for Deep Multi-Agent

Why it mattered

Multi-agent systems are everywhere the paper points: coordinating autonomous vehicles, routing network packets and planning distributed logistics. In all of them the team earns one shared reward, so no single agent can see how much it contributed. COMA made a specific claim: a critic used only during training can supply that per-agent credit without extra simulations, without a hand-designed reward for each agent and without a default action. The paper gives a clear actor-critic method for the centralised-training, decentralised-execution pattern, and it supplies an agent-specific counterfactual advantage. Its StarCraft benchmark, with the field of view reduced to the firing range, is the testbed that the experiments below use.

The problem

Three problems make cooperative multi-agent learning hard, and the paper names each one.

The joint action space explodes. If there are nn agents and each has ∣U∣|U| actions, the joint action has ∣U∣n|U|^n possibilities. A single critic with one output per joint action becomes impractical as nn grows.

Execution has to be decentralised. Each agent acts on its own action-observation history, because it cannot see the whole state or talk to teammates in real time. The policy of each agent must therefore be a function of its local history only, which is the setting of a partially observable problem.

Credit is hard to assign. The team gets one reward at each step. Plain actor-critic uses the team's temporal-difference error as the learning signal for every actor. If one agent acts well while another makes a mistake, the same signal pushes both the same way. The paper calls this the multi-agent credit assignment problem.

A natural fix is difference rewards, in which an agent is scored by how much the team reward drops when its action is replaced by a default action. This works, but it needs a simulator to rerun the episode for each agent, and the default action is hard to choose. COMA keeps the idea and removes both costs.

How it works

COMA has three parts, and the paper builds them up in this order: a centralised critic, a counterfactual baseline, and a critic architecture that makes the baseline cheap. Here is the training loop for one step, with a tiny illustrative instance. Each step uses an actor-critic update with a policy gradient. The numbers below are made up for the walkthrough and are not from the paper.

  1. Collect a step. Each agent aa looks at its own history τa\tau^a and samples an action uau^a from its actor πa(ua∣τa)\pi^a(u^a \mid \tau^a). The team applies the joint action u\mathbf{u} and returns one shared reward rr and a new state s′s'. Check: the actors used only local histories, so the same policies can run during execution without the critic.
  2. Estimate the joint action value. The centralised critic Q(s,τ,u)Q(s, \boldsymbol{\tau}, \mathbf{u}) takes the global state and all histories, and it returns the value of the whole joint action. Suppose it returns Q=8Q = 8 for the joint action the team took. Check: this value depends on the teammates' actions as well as on agent aa's, so it can tell whether agent aa helped.
  3. Build the counterfactual baseline. Hold the teammates' actions fixed, and ask the critic for the value of each alternative action u′u' that agent aa could have taken. Suppose agent aa has three actions with values Q=(8,5,2)Q = (8, 5, 2) and policy probabilities πa=(0.5,0.3,0.2)\pi^a = (0.5, 0.3, 0.2). The baseline is the policy-weighted average of these values: 0.5(8)+0.3(5)+0.2(2)=5.90.5(8) + 0.3(5) + 0.2(2) = 5.9. Check: the baseline is an average over agent aa's own choices only, so it does not depend on what agent aa actually did.
  4. Compute the advantage. Subtract the baseline from the value of the action taken. If agent aa took action 1, its advantage is 8−5.9=2.18 - 5.9 = 2.1. If it took action 2, the advantage is 5−5.9=−0.95 - 5.9 = -0.9. Check: a positive advantage says the action beat the average alternative, and a negative one says it did not.
  5. Update the actor. Each agent's policy gradient is its log-probability gradient times its own advantage, summed over agents. An agent whose action beat its alternatives is pushed toward that action, and an agent whose action did not is pushed away from it. Check: the expected advantage over the agent's own actions is zero, so the baseline does not bias the gradient. The check for the example is 0.5(2.1)+0.3(−0.9)+0.2(−3.9)=00.5(2.1) + 0.3(-0.9) + 0.2(-3.9) = 0.
  6. Train the critic. The critic is updated toward a bootstrapped target built from the team reward, using TD(λ\lambda) with a target network. Only the critic uses the full state, and the agents do not need it at execution time. Check: at execution time the agents need only their actors, which is the decentralised execution the setting requires.

The diagram below shows the information flow. The red parts exist only during learning.

flowchart LR
  E["Environment"] -->|"local observation"| A1["Actor 1"]
  E -->|"local observation"| A2["Actor 2"]
  A1 -->|"action u1"| E
  A2 -->|"action u2"| E
  E -->|"global state, all histories"| C["Central critic Q"]
  A1 -.->|"joint action"| C
  A2 -.->|"joint action"| C
  C -->|"Q for each action of agent a"| B["Counterfactual baseline per agent"]
  B -->|"advantage A^a"| A1
  B -->|"advantage A^a"| A2

The math

The paper's setting is a fully cooperative stochastic game with nn agents, a true state ss, a shared reward r(s,u)r(s, \mathbf{u}) and discount factor γ∈[0,1)\gamma \in [0, 1). Each agent sees an observation zz and keeps an action-observation history τa\tau^a, and its policy πa(ua∣τa)\pi^a(u^a \mid \tau^a) conditions only on that history. Bold symbols are joint quantities over all agents, and the superscript −a-a means all agents except aa.

Definition: the counterfactual advantage

Definition: Counterfactual advantage

For agent aa with policy πa\pi^a, the counterfactual advantage of its taken action uau^a is

Aa(s,τ,u)=Q(s,τ,u)−∑u′aπa(u′a∣τa) Q(s,τ,(u−a,u′a)).A^a(s, \boldsymbol{\tau}, \mathbf{u}) = Q(s, \boldsymbol{\tau}, \mathbf{u}) - \sum_{u'^a} \pi^a(u'^a \mid \tau^a)\, Q(s, \boldsymbol{\tau}, (\mathbf{u}^{-a}, u'^a)).

The sum is the baseline. It averages the critic's value over the agent's own alternative actions while the teammates' actions u−a\mathbf{u}^{-a} stay fixed.

This is the formula used in step 4 of the walkthrough. The baseline in step 3 is the sum in the definition, which for the example equals 5.95.9.

Step 2 in symbols: the joint value

The centralised critic Q(s,τ,u)Q(s, \boldsymbol{\tau}, \mathbf{u}) is trained on the team's return. The paper trains it with TD(λ\lambda), in which the target is a mixture of nn-step returns, Gt(n)=∑l=1nγl−1rt+l+γnfc(⋅t+n,θc)G_t^{(n)} = \sum_{l=1}^{n} \gamma^{l-1} r_{t+l} + \gamma^n f^c(\cdot_{t+n}, \theta^c). The paper's target is

y(λ)=(1−λ)∑n=1∞λn−1Gt(n),y^{(\lambda)} = (1 - \lambda) \sum_{n=1}^{\infty} \lambda^{n-1} G_t^{(n)},

and the critic minimises (y(λ)−fc(⋅t,θc))2\left(y^{(\lambda)} - f^c(\cdot_t, \theta^c)\right)^2. The paper sets λ=0.8\lambda = 0.8, the value that worked best for both COMA and the baselines in its tuning.

Step 3 in symbols: the baseline does not change the expected gradient

The policy gradient for the team is

g=Eπ[∑a∇θlog⁡πa(ua∣τa) Aa(s,τ,u)].g = \mathbb{E}_{\boldsymbol{\pi}}\left[\sum_a \nabla_{\theta} \log \pi^a(u^a \mid \tau^a)\, A^a(s, \boldsymbol{\tau}, \mathbf{u})\right].

The counterfactual baseline does not depend on the action uau^a that agent aa actually took, so it adds no expected contribution to this gradient. For agent aa, the sum over its own actions of the policy times the gradient of its log-probability is ∑u∇πa(u∣τa)=∇1=0\sum_{u} \nabla \pi^a(u \mid \tau^a) = \nabla 1 = 0. This is the standard property that makes an action-independent baseline safe, not a separate result of the paper; Lemma 1's proof rests on the same policy-gradient results. The check in step 5 of the walkthrough is this property on the example numbers.

Step 4 in symbols: exploration floor

The paper bounds each action probability from below so that every action keeps some chance of being tried:

P(u)=(1−ϵ) softmax(z)u+ϵ∣U∣.P(u) = (1 - \epsilon)\,\mathrm{softmax}(\mathbf{z})_u + \frac{\epsilon}{|U|}.

Here z\mathbf{z} are the final-layer outputs of the actor and ∣U∣|U| is the number of actions. The paper anneals ϵ\epsilon linearly from 0.5 to 0.02 across 750 training episodes. Because each action has probability at least ϵ/∣U∣\epsilon / |U|, the explored set of actions never shrinks to zero.

Step 5 in symbols: efficient evaluation

Because the critic takes the other agents' actions as input and outputs one value per action of agent aa, all ∣U∣|U| values needed for the baseline come from one forward pass. The network has ∣U∣|U| outputs rather than ∣U∣n|U|^n, which is what the paper calls the efficient representation.

Convergence

The paper's Lemma 1 states that an actor-critic method with a compatible TD(1) critic following the COMA gradient reaches a locally optimal policy, in the sense that the gradient norm has a limit inferior of zero with probability 1. The paper's errata notes that an earlier version had a flaw in the proof, which came from a critic that depended on the state but not the joint history. The revised version adds that dependence and changes the proof accordingly.

Results

The paper's main test is a decentralised version of StarCraft unit micromanagement. Agents see only units within their weapon's firing range, and they lose the built-in attack-move action, so each agent must position and focus fire itself. Four scenarios are reported: 3 marines (3m), 5 marines (5m), 5 wraiths (5w) and 2 dragoons with 3 zealots (2d_3z). Each win rate is a mean over the final 1000 evaluation episodes, with a 95% confidence interval in brackets. The paper runs 35 independent trials per method, with learning frozen every 100 training episodes to evaluate.

MapHand-coded heuristicIAC-VIAC-Qcentral-Vcentral-QVCOMA
3m3547 (3)56 (6)83 (3)83 (5)87 (3)
5m6663 (2)58 (3)67 (5)71 (9)81 (5)
5w7018 (5)57 (5)65 (3)76 (1)82 (3)
2d_3z6327 (9)19 (21)36 (6)39 (5)47 (5)

Reading the table honestly, the paper's claims are as follows.

  • COMA has the highest mean win rate on all four maps among the learned methods. It improves on the strongest ablation, central-QV, by 4 points on 3m, 10 on 5m, 6 on 5w and 8 on 2d_3z.
  • The heuristic is stronger than COMA on 2d_3z (63 against 47). The paper does not claim COMA beats it on every map.
  • The text notes that the heuristic reaches a 98% win rate on 5m with a full field of view, but only 66% in the restricted setting. The restriction is what makes the benchmark hard.
  • COMA is the most consistent method across training, and it reaches good policies faster than central-V. The paper attributes this to the shaped training signal.
  • The paper states that centralised critics clearly outperform their decentralised counterparts. The gap between IAC and the centralised methods is the evidence for this claim.
  • The paper also compares the best COMA agents against published centralised controllers that see the full state and use macro-actions. It says the decentralised agents are competitive with them in most settings. The table's right-hand columns are published numbers under different conditions, so they should not be read as a direct comparison.

Limits. The paper focuses on discrete actions. It notes that continuous actions can be handled by estimating the baseline's expectation with Monte Carlo samples or with analytic forms such as Gaussian policies. The authors tried critics factored at the agent level and found that the bottleneck for scalability was not the centralisation of the critic but the difficulty of multi-agent exploration. They deferred factored COMA critics to future work.

Reading guide

Read the paper in this order, with the prerequisite lessons in hand.

Check yourself

QuestionIn one sentence, what does the counterfactual baseline compare, and for which agent?Show answer

For a given agent, it compares the critic's value for the action the agent took with the average value over the agent's own alternative actions, holding the other agents' actions fixed. The result is that agent's own credit for the team reward.

QuestionAn agent has policy probabilities (0.4,0.6)(0.4, 0.6) over two actions, and the critic gives values Q=(10,4)Q = (10, 4) for those actions with the teammates' actions fixed. What is the baseline, and what is the advantage of the first action?Show answer

The baseline is 0.4(10)+0.6(4)=4+2.4=6.40.4(10) + 0.6(4) = 4 + 2.4 = 6.4. The advantage of the first action is 10−6.4=3.610 - 6.4 = 3.6. The advantage of the second action would be 4−6.4=−2.44 - 6.4 = -2.4, and the policy-weighted sum of the two advantages is zero, as it should be.

QuestionWhy does the paper use one critic during learning but only the actors during execution?Show answer

The critic needs the global state and all agents' histories, which are available in a simulator but not to the agents once they are deployed. The actors condition only on their own action-observation histories, so they can run without the critic. This is the centralised training, decentralised execution pattern.

QuestionIn the paper's experiments, which map is the one where the hand-coded heuristic beats COMA, and why does this not contradict the paper's main claim?Show answer

The map is 2d_3z, where the heuristic scores 63 and COMA scores 47. The main claim is that COMA beats the other multi-agent actor-critic methods, and the table supports that on this map too, since COMA beats every learned baseline there. The paper does not claim COMA beats every hand-coded strategy.

QuestionWhy does the paper bound each action probability from below with an exploration floor?Show answer

Each action keeps probability at least ϵ/∣U∣\epsilon / |U|, so every action keeps some chance of being tried while the policy is still poor. The floor is annealed from 0.5 to 0.02 over 750 episodes, so exploration is heavy early and light later.

Sources

Read the full paper

Jakob Foerster, Gregory Farquhar, Triantafyllos Afouras et al., 2017. arXiv:1705.08926