Mean Field Multi-Agent RL
When hundreds of agents share one space, each one stops tracking every neighbor and steers by the average move of the few agents next to it.
Why Does This Exist?
Traffic, order books, and drone swarms put hundreds of agents in one loop. A central critic that reads every action at once blows up: input width grows with and the joint action count grows as . Value mixing helps but credit still fades across a huge crowd, and independent learners treat each other as noise and wobble.
Mean field MARL, from Yang and coauthors in 2018, borrows a physics trick. Each agent averages the actions of its local neighbors into one mean action and best responds to that average. An body problem becomes small two body problems. This page shows the average, the factorized update, and one hand computed step. For the general setting see multi-agent RL, for factored values see QMIX and QTRAN, and for the game model see Markov games.
You need one idea first. A one hot vector marks one choice with 1 and the rest with 0, so averaging one hots gives the share of neighbors picking each move.
Think of It Like This
One sardine in a large school
A sardine cannot track nine thousand other fish. It watches five or six neighbors and feels their average heading. When that local average turns left by 30 degrees, it turns left too.
Because every fish runs the same local rule, a turn ripples across the school as tight curves and flashes without any leader calling the move.
Where the analogy stops: sardines share one body and one goal. Engineered agents differ in battery, payload, and destination, so a plain average can wash out a critical neighbor unless you weight by importance.
How It Actually Works
Let be neighbor action as a one hot vector of width . Let be state, reward for agent , and in discount. The local mean action is:
Each entry of is the share of neighbors taking that move. The joint value then drops the full joint action and keeps only own action plus the mean:
Input width stays no matter how large the swarm grows. Learning uses the mean field target:
where averages under the current policy at the next mean . Actor versions condition the policy the same way, , and move along .
Worked example
Four neighbors vote Up, Up, Down, Left as , , , . The sum is , so:
Half the street moves Up. Suppose the net scores Up , Down , Left , Right . The agent picks Up at . With reward , discount , and next mean value :
The TD error is . The diagram shows the same average, the winning Up bar, and the 5.55 target.
Code
The snippet averages the neighbors and forms the same target.
def mean_action(neighbors: list[list[float]]) -> list[float]: """Average one hot neighbor actions into the mean field.""" n = len(neighbors) return [round(sum(col) / n, 4) for col in zip(*neighbors)]
def bellman_target(reward: float, next_value: float, gamma: float = 0.9) -> float: """Mean field target: immediate reward plus discounted next value.""" return round(reward + gamma * next_value, 4)
if __name__ == "__main__": m = mean_action([[1, 0, 0, 0], [1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0]]) print(m) print(bellman_target(1.5, 4.5, gamma=0.9)) print(round(5.55 - 4.2, 2))# -> expected output:[0.5, 0.25, 0.25, 0.0]5.551.35Watch Out For
Averaging away the one neighbor that matters
The symptom: a crowd policy looks smooth in training and fails where one leader decides the outcome, like a tower directing planes or an ambulance in traffic. The plain mean dilutes that signal to one share among many.
The fix: weight neighbors by learned attention over state pairs, or train the few special agents with a full joint critic while the homogeneous crowd stays mean field.
The Quick Version
- Mean field MARL replaces the joint action with own action plus local mean: .
- The mean is the average one hot over neighbors, so input size stays fixed as the swarm grows.
- Learning targets over local moves only, which dodges the joint max.
- In the example the mean is , Up wins at , and the target is with error .
- The trick needs dense local crowds of similar agents and breaks on sparse graphs or dominant leaders.