Multi-Agent RL advanced 7 min read 6 flashcards

Opponent Shaping and Learning-Aware Agents

Why differentiating through another agent's learning step turns mutual defection into reciprocal cooperation, what access that requires, and how shaping becomes exploitation once both sides do it.

Two policy-gradient agents in the iterated prisoner's dilemma converge to mutual defection. Each is doing exactly what its objective asks: given the other's current policy, defection has higher immediate value, and the gradient points there. The failure is not in the optimiser, it is in the objective, which treats the other agent as part of a fixed environment when it is in fact a learner whose next update you influence.

The naive gradient and the extra term

Let agent 1 have parameters \(\theta^1\) and agent 2 have \(\theta^2\), with expected returns \(V^1(\theta^1, \theta^2)\) and \(V^2\). The naive learner ascends

\[\nabla_{\theta^1} V^1(\theta^1, \theta^2)\]

holding \(\theta^2\) fixed. A learning-aware agent instead anticipates one step of the opponent's update, \(\Delta\theta^2 = \eta \nabla_{\theta^2} V^2\), and optimises \(V^1(\theta^1, \theta^2 + \Delta\theta^2)\). Expanding to first order adds a second term,

\[\nabla_{\theta^1} V^1 + (\nabla_{\theta^2} V^1)^\top \nabla_{\theta^1} \Delta\theta^2,\]

which contains a mixed second derivative of the opponent's value. This is learning with opponent-learning awareness, or LOLA (Foerster et al., 2018, Learning with Opponent-Learning Awareness, AAMAS, arXiv:1709.04326).

The new term is the whole story. It is the derivative of your return with respect to their parameter change, times how their change responds to you. Defecting now teaches the opponent to defect later, and that cost is invisible to the naive gradient and visible to this one. Two LOLA agents in the iterated prisoner's dilemma converge to tit-for-tat and cooperate, where independent learners do not, and LOLA earns higher returns against naive learners while resisting exploitation by other gradient-based methods.

Shaping is not modelling

Opponent modelling predicts what the other agent will do and conditions on the prediction. The other agent is treated as a stochastic process to be estimated.

Opponent shaping treats the other agent's learning rule as the thing to be influenced. The target is not their next action but their next parameter vector.

The distinction determines what you need. Modelling needs observed behaviour. Exact LOLA needs white-box access to the opponent's differentiable learning algorithm and its parameters, which almost never holds outside a research setting; the usual workarounds estimate the opponent's update from trajectories and inherit the variance of doing so.

Beyond one step

LOLA anticipates a single opponent update, which makes it myopic, and it assumes the opponent is a naive learner, which makes it wrong against anyone who is also shaping. Model-free opponent shaping reframes the problem: each episode of the underlying game becomes one step of a meta-game whose state is both agents' policies, and a meta-policy is trained on it with ordinary model-free RL, needing no higher-order derivatives. The authors report near-optimal exploitation of naive learners and other published algorithms, and the first learned instance of the zero-determinant extortion strategy in the iterated prisoner's dilemma (Lu et al., 2022, Model-Free Opponent Shaping, ICML, arXiv:2205.01447).

Note what that result is. Extortion is not cooperation. The same machinery that produces reciprocal tit-for-tat against a naive partner produces exploitation when the shaper is strong enough and the partner keeps learning. Shaping is a capability, and which outcome it yields depends on the asymmetry between the parties.

When it breaks

Mutual shaping is unstable. The derivation assumes the opponent does not anticipate you. When both sides shape, the higher-order terms compound and the dynamics can cycle or diverge rather than settle, which is the recursion the literature on stable shaping and higher-order learning awareness tries to tame.

White-box access is the binding constraint. Exact gradients through an opponent's update require their parameters, their learning rate and their differentiable objective. Deployed systems do not expose these, so practical shaping runs on estimated updates with correspondingly weak guarantees.

Reciprocity and extortion share a mechanism. The published cooperative results pair two shapers of equal strength; the exploitative results pair a shaper with a naive learner. Any system that shapes its counterparties has the second case available to it, which is a design question rather than an algorithmic one.

It inherits the sample cost of a meta-game. Treating whole episodes as single meta-steps multiplies the interaction budget. Reported results concentrate on small matrix games and low-dimensional settings for this reason.

Shaping assumes the other side is still learning. Against a fixed policy there is nothing to shape, and the extra term is zero. The method's value is exactly proportional to how plastic the counterparty is.

References and further reading

Every source this page cites, in the order it cites them. All of them open in a new tab.

  1. Foerster et al., 2018, Learning with Opponent-Learning Awareness, AAMAS, arXiv:1709.04326 arxiv.org
  2. Lu et al., 2022, Model-Free Opponent Shaping, ICML, arXiv:2205.01447 arxiv.org
Check yourself

6 flashcards for this concept

Click a card to reveal the answer.

Drill the whole track