Multi-agent cooperation through learning-aware policy gradients

## Abstract

Abstract Self-interested individuals often fail to cooperate, posing a fundamental challenge for multi-agent learning. How can we achieve cooperation among self-interested, independent learning agents? Promising recent work has shown that in certain tasks cooperation can be established between learning-aware agents who model the learning dynamics of each other. Here, we present the first unbiased, higher-derivative-free policy gradient algorithm for learning-aware reinforcement learning, which takes into account that other agents are themselves learning through trial and error based on multiple noisy trials. We then leverage efficient sequence models to condition behavior on long observation histories that contain traces of the learning dynamics of other agents. Training long-context policies with our algorithm leads to cooperative behavior and high returns on standard social dilemmas, including a challenging environment where temporally-extended action coordination is required. Finally, we derive from the iterated prisoner’s dilemma a novel explanation for how and when cooperation arises among self-interested learning-aware agents.

## 1 Introduction

From self-driving autonomous vehicles to personalized assistants, there is a rising interest in developing agents that can learn to interact with humans (Collins et al., ; Gweon et al., ), and with each other (Park et al., ; Vezhnevets et al., ). However, multi-agent learning comes with significant challenges that are not present in more conventional single-agent paradigms. This is perhaps best seen through the study of ‘social dilemmas’, general-sum games which model the tension between cooperation and competition in abstract form (von Neumann and Morgenstern, ). Without further assumptions, letting agents independently optimize their individual objectives on such games results in poor outcomes and a lack of cooperation (Tan, ; Claus and Boutilier, ).

Optimal single-agent behavior can be formalized through the theory of stochastic optimal control on Markov decision processes (Bellman, ; Åström, ), which provides a basis for reinforcement learning (Sutton and Barto, ). The independent multi-agent learning problems that we study here are more complicated. First, for general-sum games, reaching an equilibrium point does not necessarily imply appropriate behavior because there can be many sub-optimal equilibria (Fudenberg and Levine, ; Shoham and Leyton-Brown, ). Second, the control problem an agent faces is non-stationary from its own viewpoint, because other agents themselves simultaneously learn and adapt (Hernandez-Leal et al., ). Centralized training algorithms sidestep non-stationarity issues by sharing agent information (Sunehag et al., ), but this transformation into a global learning problem is usually prohibitively costly, and impossible to implement when agents must be developed separately (Zhang et al., ).

The above two fundamental issues have hindered progress in multi-agent reinforcement learning, and have limited our understanding of how self-interested agents may reach high returns when faced with social dilemmas. In this paper, we join a promising line of work on ‘learning awareness’ (Foerster et al., ). The key idea behind such approaches is to take into account the learning dynamics of other agents explicitly, rendering it into a meta-learning problem (Schmidhuber, ; Bengio et al., ; Hochreiter et al., ). Foerster et al. () showed that two players could reach cooperation in the infamous iterated prisoner’s dilemma by using a simple form of anticipation of each other’s learning, whereas standard, independent learning would fail to produce cooperation.

The present paper contains two main novel results on learning awareness in general-sum games. First, we introduce a new learning-aware reinforcement learning rule derived as a policy gradient estimator. Unlike existing methods (Foerster et al., , ; Xie et al., ; Balaguer et al., ; Lu et al., ; Willi et al., ; Cooijmans et al., ; Khan et al., ), it has a number of desirable properties: (i) it does not require computing higher-order derivatives, (ii) it is provably unbiased, (iii) it can model minibatched learning algorithms, and (iv) it is applicable to scalable architectures based on recurrent sequence policy models. This policy gradient rule significantly outperforms previous methods in the general-sum game setting. Notably, we show that it reaches cooperation for the first time in a challenging sequential social dilemma involving temporally extended actions (Leibo et al., ) that we adapted from the Melting Pot suite (Agapiou et al., ). Second, we analyze the iterated prisoner’s dilemma, a canonical model for studying cooperation among self-interested agents (Rapoport, ; Axelrod and Hamilton, ), and we discover a previously unknown mechanism for the emergence of cooperation through learning awareness. The mechanism we identify relies on heterogeneous groups of agents with various degrees of learning awareness, further reinforcing the importance of population heterogeneity in overcoming social dilemmas (Nowak and Sigmund, ; Santos et al., ).

## 2 Background and problem setup

We consider partially observable stochastic games (POSGs; Kuhn, ) consisting of a tuple $(\mathcal{I},\mathcal{S},\allowbreak\mathcal{A},P_{t},P_{r},P_{i},\mathcal{O},
P_{o},\gamma,T)$ with $\mathcal{I}=\{1,\ldots,n\}$ a finite set of $n$ agents, $\mathcal{S}$ the state space, $\mathcal{A}=\times_{i\in\mathcal{I}}\mathcal{A}^{i}$ the joint action space, $P_{t}(S_{t+1}\mid S_{t},A_{t})$ the state transition distribution, $P_{i}(S_{0})$ the initial state distribution, $P_{r}=\times_{i\in\mathcal{I}}P_{r}^{i}(R\mid S,A)$ the joint factorized reward distribution with $R=\{R^{i}\}_{i\in\mathcal{I}}$ and bounded rewards $R^{i}$, $\mathcal{O}=\times_{i\in\mathcal{I}}\mathcal{O}^{i}$ the joint observation space, $P_{o}(O_{t}\mid S_{t},A_{t-1})$ the observation distribution, $\gamma$ the discount factor, $t$ the time step, and $T$ the horizon. We use superscript $i$ to indicate agent-specific actions, observations and rewards, $-i$ to indicate all agent indices except $i$, and we omit the superscript for joint actions, observations and rewards. As agents only receive partial state information, they benefit from conditioning their policies $\pi^{i}(a^{i}_{t}\mid x^{i}_{t};\phi^{i})$ on the observation history $x^{i}_{t}=\{o^{i}_{k}\}_{k=1}^{t}$ (Åström, ; Kaelbling et al., ), with $\phi^{i}$ the policy parameters. Note that the observations can contain the agent’s actions on previous timesteps.

### 2.1 General-sum games and their challenges

We focus on general-sum games, where each agent has their own reward function, possibly different from those of other agents. Analyzing and solving general-sum games while letting every agent individually and independently maximize their rewards (a setting often referred to as “fully-decentralized reinforcement learning”; Albrecht et al., ) is a longstanding problem in the fields of machine learning and game theory. Alongside the difficulties of standard reinforcement learning, this setting comes with two additional significant issues that we briefly review below.

##### Non-stationarity of the environment.

In a general-sum game, each agent aims to maximize its expected return $J^{i}(\phi^{i},\phi^{-i})=\mathbb{E}_{P^{\phi^{i},\phi^{-i}}}\left[\sum_{t=1}^
{T}\gamma^{t}R^{i}_{t}\right]$, with $P^{\phi^{i},\phi^{-i}}$ the distribution over environment trajectories $x_{T}$ induced by the environment dynamics, the policy $\pi^{i}(a^{i}\mid x^{i};\phi^{i})$ of agent $i$, and the policies $\pi^{-i}$ of all other agents. Importantly, the expected return $J^{i}(\phi^{i},\phi^{-i})$ does not only depend on the agent’s own policy, but also on the current policies of the other agents. As other agents are updating their policies through learning, the environment which includes the other agents is effectively non-stationary from a single agent’s perspective. Furthermore, the actions of an agent can influence this non-stationarity by changing the observation histories of other agents, on which they base their learning updates.

##### Equilibrium selection.

It is not clear how to identify appropriate policies for a general-sum game. To see this, let us first briefly revisit the concept of a Nash equilibrium (Nash Jr., ). For a fixed set of co-player policies $\phi^{-i}$, one can compute a best response, which for agent $i$ is given by $\phi^{\scalebox{0.42}{$\bigstar$}i}=\operatorname*{arg\,max}_{\phi^{i}}J^{i}(
\phi^{i},\phi^{-i})$. When all current policies $\phi$ are a best response against each other, we have reached a Nash equilibrium, where no agent is incentivized to change its policy anymore, $\forall i,\tilde{\phi}^{i}:J^{i}(\tilde{\phi}^{i},\phi^{-i})\leq J^{i}(\phi^{i
},\phi^{-i})$. Various ‘folk theorems’ show that for most POSGs of decent complexity, there exist infinitely many Nash equilibria (Fudenberg and Levine, ; Shoham and Leyton-Brown, ). This lies at the origin of the equilibrium selection problem in multi-agent reinforcement learning: it is not only important to let a multi-agent system converge to a Nash equilibrium, but also to target a good equilibrium, as Nash equilibria can be arbitrarily bad. Famously, unconditional mutual defection in the infinitely iterated prisoner’s dilemma is a Nash equilibrium, with strictly lower expected returns for all agents compared to the mutual tit-for-tat Nash equilibrium (Axelrod and Hamilton, ). While reviewing them is out of the scope of the current paper, we note that there are various approaches to define the notion of good equilibria, such as high global welfare, Pareto optimality, and low inequality.

### 2.2 Co-player learning awareness

We aim to address the above two major challenges of multi-agent learning in this paper. Our work builds upon recent efforts that are based on adding a meta level to the multi-agent POSG, where the higher-order variable represents the learning algorithm used by each agent (Lu et al., ; Balaguer et al., ; Khan et al., ). In this meta-problem, the environment includes the learning dynamics of other agents. At the meta-level, one episode now extends across multiple episodes of actual game play, allowing the ‘ego agent’, $i$, to observe how its co-players, $-i$, learn, see Fig. 1. The goal of this meta-agent may be intuitively understood as that of *shaping* co-player learning to its own advantage.

Provided that co-player learning algorithms remain constant, the above reformulation yields a single-agent problem that is amenable to standard reinforcement learning techniques. This setup is fundamentally asymmetric: while the meta agent (ego agent) is endowed with co-player learning awareness (i.e., observing multiple episodes of game play), the remaining agents remain oblivious to the fact that the environment is non-stationary. We thus refer to them here as naive agents (see Fig. 1B). Despite this asymmetry, prior work has observed that introducing a learning-aware agent in a group of naive learners often leads to better learning outcomes for all agents involved, avoiding mutual defection equilibria (Lu et al., ; Balaguer et al., ; Khan et al., ). Moreover, Foerster et al. () has shown that certain forms of learning awareness can lead to the emergence of cooperation even in symmetric cases, a surprising finding that is not yet well understood.

These observations motivate our study, leading us to derive novel efficient learning-aware reinforcement learning algorithms, and to investigate their efficacy in driving a group of agents (possibly composed of both meta and naive agents) towards more beneficial equilibria. Below, we proceed by first formalizing asymmetric co-player shaping problems, which we solve with a novel policy gradient algorithm (Section 3). In Section 4, we then return to the question of why and when co-player learning awareness can result in cooperation in multi-agent systems with equally capable agents.

Figure: Figure 1: A. Experience data terminology. Inner-episodes comprise $T$ steps of (inner) game play, played between agents $B$ times in parallel, forming a batch of inner-episodes. A given sequence of $M$ inner-episodes forms a meta-trajectory, thus comprising $MT$ steps of inner game play. The collection of $B$ meta-trajectories forms a meta-episode. B. During game play, a naive agent takes only the current episode context into account for decision making. In contrast, a meta agent takes the full long context into account. Seeing multiple episodes of game play endows a meta agent with learning awareness.
Refer to caption: x1.png

##### Co-player shaping.

Following Lu et al. (), we first introduce a meta-game with a single meta-agent whose goal is to shape the learning of naive co-players to its advantage. This meta-game is defined formally as a single-agent partially observable Markov decision process (POMDP) $(\tilde{\mathcal{S}},\tilde{\mathcal{A}},\tilde{P}_{t},\tilde{P}_{r},\tilde{P}
_{i},\tilde{\mathcal{O}},\tilde{\gamma},M)$. The meta-state consists of the policy parameters $\phi^{-i}$ of all co-players together with the agent’s own parameters $\phi^{i}$. The meta-environment dynamics represent the fixed learning rules of the co-players, and the meta-reward distribution represents the expected return $J^{i}(\phi^{i},\phi^{-i})$ collected by agent $i$ during an inner episode, with ‘inner’ referring to the actual game being played. The initialization distribution $\tilde{P}_{i}$ reflects the policy initializations of all players. Finally, we introduce a meta-policy $\mu(\phi^{i}_{m+1}\mid\phi^{i}_{m},\phi^{-i}_{m};\theta)$ parameterized by $\theta$, that decides the update to the parameter $\phi^{i}_{m+1}$ (the meta-action) to shape the co-player learning towards highly rewarding regions for agent $i$ over a horizon of $M$ meta steps. This leads to the co-player shaping problem

$$ $\displaystyle\max_{\mu}\mathbb{E}_{\tilde{P}_{i}(\phi^{i}_{0},\phi^{-i}_{0})} \mathbb{E}_{\tilde{P}^{\mu}}\left[\sum_{m=1}^{M}J^{i}(\phi_{m}^{i},\phi^{-i}_{ m})\right],$ (1) $$

with $\tilde{P}^{\mu}$ the distribution over parameter trajectories induced by the meta-dynamics and meta-policy.

### 2.3 Single-level co-player shaping by leveraging sequence models

In this paper, we combine both inner- and meta-policies in a single long-context policy, conditioning actions on long observation histories spanning multiple inner game episodes (see Fig. 1B). Instead of hand-designing the co-player learning algorithms, we instead let meta-learning discover the algorithms used by other agents. This way, we leverage the in-context learning and inference capabilities of modern neural sequence models (Brown et al., ; Rabinowitz, ; Akyürek et al., ; von Oswald et al., ; Li et al., ) to both simulate in-context an inner policy, as well as strategically update it based on current estimates of co-player policies. This philosophy has been adopted in Khan et al. (), in which a flat policy is optimized using an evolutionary algorithm. We compare to this method in Section 3.1, after we derive our meta reinforcement learning algorithm.

To proceed with this approach, we must first reformulate the meta-game. In particular, we must deal with a difficulty that is not present in single-agent meta reinforcement learning (e.g., Wang et al., ; Duan et al., ), which stems from the fact that co-players generally update their own policies based on multiple inner episodes (‘minibatches’), without which reinforcement learning cannot practically make progress. Here, we solve this by defining the environment dynamics over $B$ parallel trajectories, with $B$ the size of the minibatch of inner episode histories that co-players use to update their policies at each inner episode boundary (see Fig. 1A).

##### Batched co-player shaping POMDP.

We define the batched co-player shaping POMDP $(\bar{\mathcal{S}},\bar{\mathcal{A}},\allowbreak\bar{P}_{t},\bar{P}_{r},\bar{P
}_{i},\bar{\mathcal{O}},\bar{\gamma},M,B)$, with hidden states consisting of the hidden environment states of the $B$ ongoing inner episodes, combined with the current parameters $\phi^{-i}_{m}$ of all co-players; environment dynamics $\bar{P}_{t}$ simulating $B$ environments in parallel, combined with updating the co-player’s policy parameters $\phi^{-i}$, and resetting the environments at each inner episode boundary; initial state distribution $\bar{P}_{i}$ that initializes the co-player policies and initializes the environments for the first inner episode batch; and finally, an ego-agent policy $\bar{\pi}^{i}(\bar{a}^{i}_{l}\mid\bar{h}^{i}_{l};\phi^{i})$ parameterized by $\phi^{i}$, which determines a distribution over the batched action $\bar{a}^{i}_{l}=\{a^{i,b}_{l}\}_{b=1}^{B}$, based on the batched long history $\bar{h}^{i}_{l}=\{h^{i,b}_{l}\}_{b=1}^{B}$. We refer to each element of the latter as a long history $h^{i,b}_{l}$, with long time index $l$ running across multiple episodes, from $l=1$ until $l=MT$. It should be contrasted to the inner episode history $x_{t}^{i}$, which runs from $t=1$ to $t=T$ and thus only reflects the current (inner) game history.

The POMDP introduced above suggests using a sequence policy $\bar{\pi}^{i}(\bar{a}^{i}_{l}\mid\bar{h}^{i}_{l};\phi^{i})$ that is aware of the full minibatch of long histories and which produces a joint distribution over all current actions in the minibatch. However, as we aim to use our agents not only to shape naive learners, but also to play against/with each other, we require a policy that can be used both in a batch setting with naive learners, and in a single-trajectory setting with other learning-aware agents.
Within our single-level approach, we achieve this by factorizing the batch-aware policy $\bar{\pi}^{i}(\bar{a}^{i}_{t}\mid\bar{h}^{i}_{l};\phi^{i})$ into $B$ independent policies with shared parameters $\phi^{i}$,

$$ $\displaystyle\bar{\pi}^{i}(\bar{a}^{i}_{l}\mid\bar{h}^{i}_{l};\phi^{i})=\prod_ {b=1}^{B}\pi^{i}(a^{i,b}_{l}\mid h^{i,b}_{l};\phi^{i}).$ (2) $$

Thanks to the batched POMDP, we can now pose co-player shaping as a standard (single-level, single-agent) expected return maximization problem:

$$ $\displaystyle\max_{\phi^{i}}\mathbb{E}_{\bar{P}^{\phi^{i}}}\left[\frac{1}{B} \sum_{b=1}^{B}\sum_{l=0}^{MT}R^{i,b}_{l}\right].$ (3) $$

This formulation is the key for obtaining an efficient policy gradient co-player shaping algorithm.

## 3 Co-agent learning-aware policy gradients

Figure: Figure 2: Policy update and credit assignment of naive and meta agents. For credit assignment of action $a_{l}^{i,b}$, a naive agent (left) takes only intra-episode context into account. A COALA agent (right) takes inter-episode context across the batch dimension into account. For policy updates, a naive agent aggregates policy gradients over the inner-batch dimension (dashed blocks) and updates their policy between episode boundaries. In contrast, a COALA agent updates their policy at a lower frequency along the meta-episode dimension.
Refer to caption: x2.png

### 3.1 A policy-gradient for shaping naive learners

We now provide a meta reinforcement learning algorithm for solving the co-player shaping problem stated in Eq. 3 efficiently. Under the POMDP introduced in the previous section, co-player shaping becomes a conventional expected return maximization problem. Applying the policy gradient theorem (Sutton et al., ) to Eq. 3, we arrive at COALA-PG (co-agent learning-aware policy gradients, c.f. Theorem 3.1): a policy-gradient method compatible with shaping other reinforcement learners that base their own policy updates on minibatches of experienced trajectories.

###### Theorem 3.1 .

Take the expected shaping return $\bar{J}(\phi^{i})=\mathbb{E}_{\bar{P}^{\phi^{i}}}\left[\frac{1}{B}\sum_{b=1}^{
B}\sum_{l=0}^{MT}R^{i,b}_{l}\right]$, with $\bar{P}^{\phi^{i}}$ the distribution induced by the environment dynamics $\bar{P}_{t}$, initial state distribution $\bar{P}_{i}$ and policy $\phi^{i}$. Then the policy gradient of this expected return is equal to

$$ $\displaystyle\nabla_{\phi^{i}}\bar{J}(\phi^{i})=\mathbb{E}_{\bar{P}^{\phi^{i}} }\left[\sum_{b=1}^{B}\sum_{l=1}^{MT}\nabla_{\phi^{i}}\log\pi^{i}(a^{i,b}_{l} \mid h^{i,b}_{l})\left(\frac{1}{B}\sum_{b^{\prime}=1}^{B}\sum_{k=l}^{MT}R_{k}^ {i,b^{\prime}}\right)\right].$ (4) $$

We provide a proof in Appendix C. There are two important differences between COALA-PG and naively applying policy gradient methods to individual trajectories in a batch. (i) Each gradient term for an individual action $a_{l}^{i,b}$ takes into account the future return averaged over the whole minibatch, instead of the future return along trajectory $b$ (see Fig. 2). This allows taking into account the influence of this action on the parameter update of the naive learner, which influences all trajectories in the minibatch.
(ii) Instead of averaging the policy gradients for each trajectory in the batch, COALA-PG accumulates (sums) them. This is important, as otherwise the learning signal would vanish in the limit of large minibatches. Intuitively, when a naive learner uses a large minibatch for its updates, the effect of a single action on the naive learner’s update is small, creating the need to sum the small effects together to obtain a policy gradient with a magnitude that does not depend on batch size. We will later show experimentally in Section 6 that correct treatment of minibatches critically affects reinforcement learning performance.

The expectation appearing in the policy gradient expression must be estimated in practice. To reduce gradient estimation variance, we use value function baselines in our experiments, and sample a meta-batch of $\bar{B}$ batched trajectories from $\mathbb{E}_{\bar{P}^{\phi^{i}}}$.

###### Theorem 3.1 .

##### Relationship to prior shaping methods.

We now contrast our policy gradient algorithm to two closely related methods, M-FOS (Lu et al., ) and Shaper (Khan et al., ). Like COALA-PG, M-FOS is a model-free meta reinforcement learning method. Unlike the approached followed here, though, it aims to solve the bilevel co-player shaping problem of Eq. 1, treating meta- and inner-policy networks separately. Moreover, the M-FOS parameter update is not derived as the policy gradient on the batched co-player shaping POMDP introduced above, and current-episode returns are overemphasized compared to future-episode returns (see Appendix E).
This leads to a biased parameter update, which results in learning inefficiencies. We comment on other existing bilevel shaping methods in Appendix D.

Khan et al. () adopt a single-level sequence policy for their Shaper algorithm, as we do here, but then resort to black-box evolution strategies (Rechenberg and Eigen, ) to learn the policy. Obtaining an efficient meta reinforcement learning algorithm from a POMDP applicable to such single-level policies is thus our key distinguishing contribution. The unbiased policy gradient property of our learning rule translates in practice onto learning speed and stability gains, as we will see in the experiments reported in Section 6.

## 4 Why is learning awareness beneficial on general-sum games?

We have established that co-player shaping can be cast as a single-agent reward maximization problem whenever there is a single learning-aware player amongst a group of learners that are otherwise naive. This allowed us to derive a policy gradient shaping method. However, such an asymmetric setup cannot in general be taken for granted. In our experimental analyses, we therefore consider the more realistic scenario where equally-capable, learning-aware agents try to shape each other.

As reviewed in Section 2.2, prior work has shown that learning-awareness can result in better outcomes in general-sum games, but the origin and conditions for the occurrence of this phenomenon are not yet well understood. Here, we shed light on this question by analyzing the interactions of agents with varying degrees of learning-awareness in an analytically tractable matrix game setting. This leads us to uncover a novel explanation for the emergence of cooperation in general-sum games.

### 4.1 The iterated prisoner’s dilemma

**Table 1: Single-round IPD rewards $(r^{1},r^{2})$.**
|  | c | d |
| --- | --- | --- |
| c | (1,1) | (-1,2) |
| d | (2,-1) | (0,0) |

We focus on the infinitely iterated prisoner’s dilemma (IPD), the quintessential model for understanding the challenges of cooperation among self-interested agents (Rapoport, ; Axelrod and Hamilton, ). The game goes on for an indefinite number of rounds, where for each round of play two players ($i=1,2$) meet and choose between two actions, cooperate or defect, $a_{t}^{i}\in\{\mathrm{c},\mathrm{d}\}$. The rewards collected as a function of the actions of both agents are shown in Table 1. These four rewards are set so as to create a social dilemma. When the agents meet only once, mutual defection is the only Nash equilibrium; self-interested agents thus end up obtaining low reward. In the infinitely iterated variant of the game, there exist Nash equilibria involving cooperative behavior, but these are notoriously hard to converge to through self-interested reward maximization.

We model each agent through a tabular policy $\pi^{i}(a_{t}^{i}\mid x_{t}^{i};\phi^{i})$ that depends only on the previous action of both agents, $x_{t}^{i}=(a^{1}_{t-1},a^{2}_{t-1})$. Their behavior is thus fully specified by five parameters, which determine the probability of cooperating in response to the four possible previous action combinations together with the initial cooperation probability. For this game, the discounted expected return $J^{i}(\phi^{1},\phi^{2})$ can be calculated analytically. We exploit this property and optimize policies by performing exact gradient ascent on the expected return, with gradients computed by automatic differentiation (c.f. Appendix B for details). Results can be found in Fig. 3.

### 4.2 Explaining cooperation through learning awareness

Based on the experimental results reported in Fig. 3, we now identify three key findings that establish how learning awareness enables cooperation to be reached in the iterated prisoner’s dilemma:

Finding 1: Learning-aware agents extort naive learners. We first pit naive against learning-aware agents. We find that the latter develop extortion policies which force naive learners onto unfair cooperation, in the spirit of the zero-determinant extortion strategies discovered by Press and Dyson (). Even when a learning-aware agent is initialized at pure defection, maximizing the shaping objective of Eq. 3 lets it escape mutual defection (see Fig. 3A).

Finding 2: Extortion turns into cooperation when two learning-aware players face each other. After developing extortion policies against naive learners (grey shaded area in Fig. 3B), we then let two learning-aware agents (C1 and C2 in Fig. 3B) play against each other after. We see that optimizing the co-player shaping objective turns extortion policies into cooperative policies. Intuitively, under independent learning, an extortion policy shapes the co-player to cooperate more. We remark that the same occurs if learning-aware agents play against themselves (self-play; data not shown). This analysis explains the success of the annealing procedure employed by Lu et al. (), according to which naive co-players transition to self-play throughout training.

Finding 3: Cooperation emerges within groups of naive and learning-aware agents. Findings 1. and 2. motivate studying learning in a group containing both naive and learning-aware agents, with every agent in the group trained against each other. This mixed group setting yields a sum of two distinct shaping objectives, which depend on whether the agent being shaped is learning-aware or naive. The gradients resulting from playing against naive learners pull against mutual defection and towards extortion, while those resulting from playing against other learning-aware agents push away from extortion towards cooperation. Balancing these competing forces leads to robust cooperation, see Fig. 3C (left). By contrast, a pure group of learning-aware agents cannot escape mutual defection, see Fig. 3C (right). This can be explained by the fact that the agents can no longer observe other players learning, and must deal again with a non-stationary problem. The resulting gradients do not therefore contain information on the effects of unconditional defection on the future strategies of co-players, or that policies in the vein of tit-of-tat can shape co-players towards more cooperation.

Our analysis thus reveals a surprising path to cooperation through heterogeneity. The presence of short-sighted agents that greedily maximize immediate rewards turns out to be essential for full cooperation to be established among far-sighted, learning-aware agents.

Figure: Figure 3: (A) Learning-aware agents learn to extort naive learners, even when initialized with pure defection strategy. (B) An extortion policy developed against naive agents (shaded area period) turns into a cooperative one when playing against another learning-aware agent (M1 & M2). (C) Cooperation emerges within mixed training pools of naive and learning-aware agents, but not in pools of learning-aware agents only. The shaded regions represent the interquartile range (25th to 75th quantiles) across 32 random seeds
Refer to caption: extracted/5950919/figures/figure3/3_defection_init_coala_vs_naive.png

## 5 Revisiting Learning with Opponent-Learning Awareness

We now leverage our results from Sections 3-4 to explain how and when cooperation arises in Learning with Opponent-Learning Awareness (LOLA; Foerster et al. ()), the seminal work that spearheaded the learning awareness field. Furthermore, we will use COALA-PG to derive a new LOLA gradient estimator that does not require higher-order derivative estimates.

LOLA considers a POSG (c.f. Section 2.2) with agent policies $(\phi^{i},\phi^{-i})$, and expected return $J^{i}(\phi^{i},\phi^{-i})$. Instead of estimating the naive gradients $\nabla_{\phi^{i}}J^{i}(\phi^{i},\phi^{-i})$, LOLA anticipates that the co-players update their parameters with $M$ naive gradient steps, and estimates the total gradient through this look-ahead objective:

$$ $\displaystyle\nabla_{\phi^{i}}^{\mathrm{LOLA}}=\frac{\mathrm{d}}{\mathrm{d} \phi^{i}}\left[J^{i}\left(\phi^{i},\phi^{-i}+\sum_{q=1}^{M}\Delta_{q}\phi^{-i} \right)\leavevmode\nobreak\ \leavevmode\nobreak\ \leavevmode\nobreak\ \text{s. t.}\leavevmode\nobreak\ \leavevmode\nobreak\ \Delta_{q}\phi^{-i}=\alpha\frac{ \partial}{\partial\phi^{-i}}J^{i}\left(\phi^{i},\phi^{-i}+\sum_{q^{\prime}=1}^ {q-1}\Delta_{q^{\prime}}\phi^{-i}\right)\right]$ (5) $$

with $\frac{\mathrm{d}}{\mathrm{d}\phi^{i}}$ the total derivative taking into account the effect of $\phi^{i}$ on the parameter updates $\Delta_{q}\phi^{-i}$, and $\frac{\partial}{\partial\phi^{-i}}$ the partial derivative. Note that Eq. 5 considers the LOLA-DICE update (Foerster et al., ), an improved version of the LOLA update. In reality, all players update their parameters with the LOLA-DICE update equation 5, hence the look-ahead assumption with naive gradients is inconsistent, sometimes hampering the performance of LOLA (Willi et al., ; Letcher et al., ).

### 5.1 Explaining when and how cooperation arises with LOLA

In Section 4, we showed that the two main ingredients for learning to cooperate with selfish objectives are (i) observe that one’s actions influence the future behavior of others, providing shaping gradients pulling away from defection towards extortion, and (ii), also play against other extortion agents immune to being shaped on the fast timescale, providing gradients pulling away from extortion towards cooperation. We then showed that both ingredients can be combined by training agents in a heterogeneous group containing both naive and learning-aware agents.

We can explain the emerging cooperation in LOLA by observing that LOLA also combines both ingredients, albeit in a different manner from the heterogeneous group setting. By considering the look-ahead objective equation 5, LOLA computes gradients to shape naive learners performing $M$ naive gradient steps. Unique to LOLA however, the naive learners in the look-ahead objective equation 5 are initialized with the parameters of the other LOLA agents $\phi^{-i}$. If only few look-ahead steps are used, the updated naive learner parameters stay close to $\phi^{-i}$, mimicking playing against other extortion agents resulting in emergent cooperative behavior.

Figure 4A shows that indeed, LOLA-DICE with few look-ahead steps leads to cooperation on the iterated prisoner’s dilemma. However, when more look-ahead steps are used, the naive learner moves too far away from its $\phi^{-i}$ initialization, removing the second ingredient, leading to defection. In figure 4, we take the policy resulting from LOLA-training with many look-ahead steps, and train a new randomly initialized naive learner against this fixed LOLA policy. The results show that the LOLA policy extorts the naive learner into unfair cooperation, confirming that with many look-ahead steps, only a shaping incentive is present in the LOLA update, resulting in extortion policies. Hence, the low reward in Fig. 4A for LOLA agents with many look-ahead steps does not result from unconditional defection, but instead both LOLA policies trying to extort the other one. Finally, we can improve the performance of LOLA with many look-ahead steps by explicitly introducing ingredient 2 through adding the partial gradient $\frac{\partial}{\partial\phi^{-i}}J^{i}(\phi,\phi^{-i})$ to the LOLA update equation 5 (c.f. Fig. 4C).

Figure: Figure 4: (A) Performance of two agents trained by LOLA on the iterated prisoner’s dilemma with analytical gradients for various look-ahead steps (only the performance of the first agent is shown). (B) Performance of a randomly initialized naive learner trained against the fixed LOLA 20 look-aheads policy taken from the end of training of (A). (C) Same setting as (A), but with the naive gradient $\lambda\frac{\partial}{\partial\phi^{-i}}J^{i}(\phi,\phi^{-i})$ added to the LOLA update, with $\lambda$ a hyperparameter (c.f. Appendix B). Shaded regions indicate standard error computed over 64 seeds.
Refer to caption: extracted/5950919/figures/COALA-LOLA.png

### 5.2 A higher-derivative-free LOLA gradient estimator

Despite the apparent dissimilarities of the two algorithms, we show in Theorem 5.1 that as a special case of COALA-PG, we can estimate the gradient of a similar objective to the LOLA-DICE method. We consider a mixed agent group of meta agents $(\phi^{i},\phi^{-i})$, and naive learners.

###### Theorem 5.1 .

Assuming that (i) the COALA policy is only conditioned on inner episode histories $x_{m,t}^{i,b}$ (instead of long histories $h_{l}^{i,b}$), with subscript $m=1,\ldots,M$ indexing histories over meta-steps, and (ii) the naive learners are initialized with the current parameters $\phi^{-i}$ of the other agents, then the COALA-PG update on the batched co-player shaping POMDP equals

$$ $\displaystyle\nabla_{\phi^{i}}\bar{J}(\phi^{i})=\frac{\mathrm{d}}{\mathrm{d} \phi^{i}}\sum_{m=0}^{M}\mathbb{E}_{\bar{P}^{\phi^{i}}}\left[J^{i}\left(\phi^{i },\phi^{-i}+\sum_{q=1}^{m}\Delta\phi^{-i}(\bar{x}_{q,T})\right)\right]$ (6) $$

with $\Delta\phi^{-i}(\bar{x}_{q,T})$ the naive learner’s update based on the batch of inner-episode histories $\bar{x}_{q,T}$.

Compared to the LOLA-DICE gradient of Eq. 5, there are two main differences. (i) LOLA-DICE assumes that the naive learner takes a deterministic gradient step on $J$, whereas COALA-PG takes into account that the naive learner takes a stochastic policy gradient step based on the current minibatch of inner policy histories. When $J$ is linear, we can bring the expectation in the COALA-PG expression inside, resulting in the deterministic gradient, but in general $J$ is nonlinear. (ii) LOLA-DICE considers only the average inner episode return $J$ after $M$ naive learner updates, whereas COALA-PG considers the whole learning trajectory.

The above two differences are rooted in the distinction of the objectives on which LOLA-DICE and COALA-PG estimate the policy gradient. A bigger difference arises on how both methods estimate the policy gradient. As LOLA-DICE assumes that the naive learner takes deterministic gradient updates, their resulting gradient estimator backpropagates explicitly through this learning update, resulting in higher-order derivative estimates. By contrast, COALA-PG assumes that the naive learner takes stochastic gradient updates, and can hence estimate the policy gradient through measuring the effect of $\phi^{i}$ on the distribution of $\bar{x}_{l,T}$, and thereby on the resulting co-player parameter updates, without requiring higher-order derivatives.

We emphasize that both estimators have their strengths and weaknesses. When LOLA-DICE has access to an accurate model of the co-players and their learning algorithm, explicitly backpropagating through this learning algorithm and model can provide detailed gradient information. However, when the co-player and learning algorithm model are inaccurate, the detailed higher-order derivative information can actually hurt (Zhao et al., ). In this case, a higher-order-derivative-free approach such as COALA-PG can be beneficial.

In sum, in contrast to existing methods, we introduce a return estimator that avoids higher-order derivative computations while taking into account that other agents are themselves undergoing minibatched reinforcement learning.
Furthermore, while methods of the LOLA type require an explicit model of the opponent and its update function, COALA-PG allows for more flexible modeling. Importantly, this enables exploiting the information in long histories that cover multiple inner episodes with a powerful sequence model, for which credit assignment can be carried out over long time scales. This makes it possible to combine implicit co-player modeling with modeling the *learning* of co-players, a process known as algorithm distillation (Laskin et al., ).

###### Theorem 5.1 .

## 6 Experimental analysis of policy gradient implementations

The results presented on the previous section were obtained by performing gradient ascent on analytical expected returns. This assumes knowledge of co-player parameters, and it is only possible on a restricted number of games which admit closed-form value functions. We now move to the general reinforcement learning setting, with the main aim of studying the performance of the COALA-PG learning rule. We consider both the iterated prisoner’s dilemma and a simplified version of the CleanUp game, a challenging general-sum game belonging to the Melting Pot suite of environments (Agapiou et al., ). We compare to the M-FOS meta reinforcement learning algorithm (Lu et al., ), which we take as a best-in-class baseline method, as well as to an ablation motivated by our batched POMDP.

### 6.1 Agents trained with COALA-PG master the iterated prisoner’s dilemma

We train a long-context sequence policy $\pi^{i}(a^{i,b}_{l}\mid h_{l}^{i,b};\phi^{i})$ with the COALA-PG rule to play the (finite) iterated prisoner’s dilemma, see Appendix A. We choose a Hawk recurrent neural network as the policy backbone (De et al., ). Hawk models achieve transformer-level performance at scale, but with time and memory costs that grow only linearly with sequence length. This allows processing efficiently the long history context $h_{l}^{i,b}$, which contains all actions played by the agents across episodes, from their first round up to current round $l$. Based on the results of the preceding section, we consider a mixed group setting, pitting COALA-PG-trained agents against naive learners as well as other equally capable learning-aware agents. Naive learners are equipped with the same policy architecture as the agents trained by COALA-PG, but their context is limited to the current inner game history $x_{t}^{i,b}$.

Figure: Figure 5: Agents trained by COALA-PG play iterated prisoner’s dilemma. Left: When trained against naive agents only, COALA-PG-trained agents extort the latter and reach considerably higher reward than other baseline agents. The stars ($\star$) indicate overlapping curves of the corresponding color at that point Center: When analyzing the behavior of the agents within one meta-episode, we observe COALA-PG-trained agents shaping naive co-players, leading to low defection rate in the beginning, which is then exploited towards the end. M-FOS on the other hand defects from the beginning, achieving lower reward, thus failing to properly optimize the shaping problem. Batch-unaware COALA-PG performs identically to M-FOS and is therefore omitted. Right: Average performance of meta agents playing against other meta agents, when training a group of meta agents against a mixture of naive and other meta agents. Such agents trained with COALA-PG cooperate when playing against each other, but fail to do so when trained with baseline methods. When removing naive agents from the pool, meta agents also fail to cooperate, as predicted in Section 3. Shaded regions indicate standard deviation computed over 5 seeds.
Refer to caption: extracted/5950919/figures/IPD/ipd_shaping.png

In Fig. 5, we see that COALA-PG reproduces the analytical game findings reported in the previous section: learning-aware agents cooperate with other learning-aware agents, and extort naive learners. Importantly, the identity of each agent is not revealed to a learning-aware agent, which must therefore infer in-context the strategy used by the player it faces.

By contrast, the whole group falls into defection when training the exact same sequence model with the M-FOS rule, which weighs disproportionately future vs. current episode returns. We note that the experiments reported by Lu et al. () were performed with a tabular policy and analytical inner game returns, for which cooperation could be achieved with the M-FOS rule. This shows how crucial the unbiased policy gradient property of COALA-PG is for co-player shaping by meta reinforcement learning to succeed in practice. The same failure to beat defection occurs when using a naive policy gradient meta-update ablation which does not take co-player batching into account. We refer to Appendix E for expressions for this baseline as well as the M-FOS rule.

### 6.2 Agents trained with COALA-PG cooperate on a sequential social dilemma

Figure: Figure 6: Agents trained by COALA-PG against naive agents only successfully shape them in CleanUp. Left: COALA-PG-trained agents better shape naive opponents compared to baselines, obtaining higher return. Center left & center right & right: Analyzing behavior within a single meta-episode after training reveals that COALA outperforms baselines and shapes naive agents, (i) collecting overall higher reward across the episode, (ii) exhibiting an improved cleaning-harvesting ratio, and (iii) being less often zapped. Shaded regions indicate standard deviation computed over 5 seeds.
Refer to caption: extracted/5950919/figures/CleanUp/cleanup_legend.png

Finally, we consider CleanUp-lite, a simplified two-player version of the CleanUp game, which is part of the Melting Pot suite of multi-agent environments (Agapiou et al., ). We briefly describe the game here, and provide additional details on Appendix A. On a high level, CleanUp-lite is a two-player game that models the social dilemma known as the tragedy of the commons (Hardin, ). A player receives rewards by picking up apples. Apples are spontaneously generated in an orchard, but the rate of generation is inversely proportional to the pollution level of a nearby river. Agents can spend time cleaning the river to reduce the pollution level, and thus increase the apple generation rate. In a single-player game, an agent would balance out cleaning and harvesting to maximize the return. In a multi-player setting however, this gives room for a ‘freerider’ who never cleans and always harvests, letting the opponent clean instead. At any time point, agents can ‘zap’ the opponent, which would result in the opponent being frozen for a number of time steps, unable to harvest or clean. In contrast to matrix games where cooperation corresponds to a single action, this game is a sequential social dilemma (Leibo et al., ), where cooperation involves orchestrating sequences of actions.

As in the previous section, we model agent behavior through Hawk sequence policies, and compare COALA-PG to the same baseline methods as before. Naive agents here would learn too slowly if initialized from scratch, and are therefore handled differently, see Appendix A.2.2. In Figs. 6 and 7, we see that agents trained by the COALA-PG rule reach significantly higher returns than all baselines, establishing a mutual cooperation protocol with other learning-aware agents, while exploiting naive ones. We further describe below the qualitative behavior found in the simulations.

##### Exploitation of naive agents.

COALA-PG-trained agents shape the behavior of naive ones to their advantage. Our behavioral analysis reveals three salient features. First, COALA-PG successfully shapes naive opponents to zap less often throughout the meta-episode. Less overall zapping means that agents can harvest more apples while the pollution level is low, thus increasing the overall reward. Second, when COALA-PG shapes naive learners, overall, the pollution level is lower on average. Looking closer, both baselines spend all of their time harvesting, delegating the cleaning entirely to the naive agents. In that case, the naive agent quickly alternates between cleaning and picking up crumbs in the orchard, but it is not incentivized to bring the pollution down significantly. On the other hand, COALA-PG-trained agents also participate in cleaning (albeit less than naive ones), which brings the pollution level further down, thus increasing the apple production. Third, the increased availability in apples in the learning-aware vs. naive setting is disproportionately picked up by the learning-aware agent, who increases its reward w.r.t. baselines by about 60%, as opposed to about 40% for the naive agent, who therefore also benefits from the increased apples.

Figure: Figure 7: Agents trained with COALA-PG against a mixture of naive and other meta agents learn to cooperate in CleanUp-lite. Left: COALA-PG-trained agents obtain higher reward than baseline agents. Center & right: COALA-PG leads to higher apple production because of lower pollution through more cleaning and lower zapping rates. Shaded regions indicate standard deviation computed over 5 seeds.
Refer to caption: extracted/5950919/figures/CleanUp/cleanup_legend_coop.png

##### Learning-aware agents cooperate.

We see similar trends when introducing other COALA-PG-trained agents in the game, see Fig. 7. Essentially, COALA-PG allows for higher apple production because of lower pollution, and lower zapping rate. We see that over training time, cleaning rate goes up, and zapping rate goes down. Interestingly, the cleaning (38 % vs 17 %) and zapping rates (5 % vs 7%) averaged over the meta-episode are higher resp. lower than in the pure shaping setting (i.e., with naive agents only), indicating that learning-aware agents mutually shape each other to clean more and zap less.

## 7 Conclusion

We have shown that learning awareness allows reaching high returns in challenging social dilemmas, designed to make independent learning difficult. We identified two key conditions for this to occur. First, we found it necessary to take into account the stochastic minibatched nature of the updates used by other agents. This is one distinguishing aspect of the COALA-PG learning rule proposed here, which translates into a significant performance advantage over prior methods. Second, learning-aware agents had to be embedded in a heterogeneous group containing non-learning-aware agents. An interesting question for future work is whether this condition can be generalized to mixtures of agents that learn at multiple time scales, beyond the all-or-none case considered here.

An important component of our result is the ability to leverage modern and scalable sequence models. Modern sequence models have scaled favorably and in a predictable manner, most notably in autoregressive language modeling (Kaplan et al., ), and our results suggest important gains could be made applying similar approaches to multi-agent learning.
Our method shares key aspects with the current scalable machine learning approach: unbiased stochastic gradients, sequence model architectures that are amenable to gradient-based learning, and in-context learning/inference. Moreover, we focused on the setting of independent agent learning, which scales well in parallel by design. We thus see it as an exciting question to investigate the approach pursued here at larger scale and in a wider range of environments. The resulting self-organized behavior may display unique social properties that are absent from single-agent machine learning paradigms, and which may open new avenues towards artificial intelligence (Duéñez-Guzmán et al., ).

##### Acknowledgements.

We are grateful to Joel Z. Leibo and Sasha Vezhnevets for an insightful discussion, and to Rif A. Saurous for providing detailed comments on a version of this manuscript.

## Appendix A Experimental details

### A.1 Environments

#### A.1.1 Iterated prisoner’s dilemma (IPD)

We model the IPD environment as follows:

- •
State: The environment has $5$ states, that we label by $s_{0},(c,c),(c,d),(d,c),(d,d)$.
- •
Action: Each agent has 2 possible actions: cooperate ($c$) and defect ($d$).
- •
Dynamics: Based on the action taken by each agent in the previous time step, the state of the environment is set to the states $(a_{1},a_{2})$ where $a_{1},a_{2}$ are respectively the previous action of the first and second player in the environment. The assignment of who is first and second is made arbitrarily and fixed.
- •
Initial state: The initial state is always set to $s_{0}$.
- •
Observation: The agents observe directly the state, modulo a permutation of the tuple to ensure a symmetry of observation. The 5 possible observations are then encoded as one-hot encoding.
- •
Reward: At every timestep, each agents receive a reward following the reward matrix in Table 1

#### A.1.2 CleanUp-lite

CleanUp-lite is a simplified two-player version of the CleanUp game, which is part of the Melting Pot suite of multi-agent environments (Agapiou et al., ). It is modelled as follows:

- •
State: The world is a grid of size 3, arranged horizontally. The right extremity is the river, and the left one the orchard. The world state also contains the pollution level of the river $P$, number of apples currently available in the orchard $A$, the position of each agent, and their respective zapped state
- •
Action: There exists 4 actions: $\{$move right, move left, zap, do nothing$\}$.
- •
Dynamic: the environment evolves at every timestep in the following order:
1.
The pollution level increases by 1 with a fixed probability $p_{\text{pollution}}=0.5$, and capped at $P_{\text{max}}=5$.
2.
The apple grows by 1 with probability $1-\min(1,P/P_{\text{threshold}})$, where $P_{\text{threshold}}=3$, and capped at $A_{\text{max}}=4$.
3.
Then, agent in the "orchard" cell who is not zapped, has a probability $A/A_{\text{max}}$ of picking up an apple, independently from one another, in which case the apple level decreases by 1 (capped at 0).
4.
An agent in the "river" cell who is not zapped has a probability $p_{\text{clean}}=0.7$ of decreasing the pollution level by 1, independently of other agents (capped at 0).
5.
Finally, an agent zapping has a $p_{\text{zap}}=0.8$ probability of successfully zapping the opponent who is in the same cell. If the zapping is successful, the opponent is frozen for $t_{\text{zap}}=3$ timesteps, during which it is frozen and cannot be further zapped.
- •
Initial state: Agents are randomly placed on the grid, unzapped, $A$ is set to 0 0, $P$ to $P_{\text{threshold}}$.
- •
Observation: the observation is fully observable. Each agent sees the position of each agent encoded as concatenated one-hot vectors indicating the position in the grid, the normalized number of apples $A/A_{\text{max}}$, normalized pollution level $P/P_{\text{max}}$, the normalized remaining timeout status (zapped or not), and if so, a countdown indicating how many timestep is of each agent ($t_{\text{agent}}/t_{\text{zap}}$ where $t_{\text{agent}}$ is the time left before the agent unfreezes). The observation is symmetric.
- •
Reward: An agent that picks up an apple receives a reward of $r_{\text{apple}}=1$ in that timestep.

### A.2 Training details

Here, we describe the procedure that we use in our experiments to train meta agents in an arbitrary mixture of naive and other meta agents (who themselves are learning). A single parameter, $p_{\text{naive}}$, indicating the probability of encountering a naive agent, controls the heterogeneity of the pool that a meta agents trains against. If $p_{\text{naive}}=1$, the meta agents are trained only against naive opponents, and thus the training corresponds to a pure shaping setting. If $p_{\text{naive}}=0$, meta agents are only trained against other meta agents.

Given a set of meta agent parameters $\{\phi_{i}\}$, and a set of naive agent parameters $\{\psi_{i}\}$, a training iteration updates each parameters as follows.

#### A.2.1 Meta agents

The meta-agent parameters are updated simultaneously. For each parameter $\phi_{i}$, the following update is applied:

- 1.
First, a meta batch of opponents is sampled. Each opponent is hierarchically sampled by first determining whether it is a naive opponent (with probability $p_{\text{naive}}$), and then sampling uniformly from $\{\phi_{i}\}$ or $\{\psi_{i}\}$ accordingly. The sampling is done with replacement, and disallow sampling of oneself.
- 2.
For each opponent, generate a batch of $B$ trajectories of length $T*M$, where $M$ is the number of inner episode, and $T$ the episode length of the environment. Crucially, after every $T$ steps, the environment terminates and is reset, and, if the opponent is naive, the previous batch of length $T$ trajectory is used to update its parameter following an update rule RL of choice.
- 3.
For each collected batched trajectories, the policy gradient of the meta agent parameter is computed following the COALA-PG update rule (or other baselines, c.f. E) if the opponent is naive, and the standard policy gradient otherwise otherwise (i.e. the batch and meta batch dimensions are flattened). Crucially, the done signal from the inner episodes are ignored. The gradient is then averaged, and the parameter updated.

#### A.2.2 Naive agent

The naive agents parameters are used to initialize the naive opponents when training the meta agents, but the resulting "trained" parameters is discarded. The initialization may or may not be nonetheless updated during training. In more challenging environment however, training from scratch until good performance is achieved in a single meta trajectory may require prohibitely many inner episodes. To avoid this, in some of our experiments, at each training iteration, we set each $\{\psi_{i}\}$ to be equal to one of the $\{\phi_{i}\}$. This ensures that naive agents are initialized as an already capable agent, and is possible due to our choice of common architecture between naive and meta agents (c.f. below). In that case, we say that the naive agents are dynamic. Otherwise, naive agent is always initailized at one of a predefined static set of parameters.

#### A.2.3 Reinforcement learning

We experiment with both Advantage Actor-Critic (A2C) (Mnih et al., ) and Proximal Policy Optimization (PPO) Schulman et al. () on our COALA policy gradient estimate.
We details here how to adapt our policy gradient to these methods, together with additional tricks.

We remind for reference, that by denoting by $m_{l}$ the inner episode index corresponding to the meta episode time step $l$, the COALA Policy gradient can be rewritten as

$$ $\displaystyle\nabla_{\phi^{i}}\bar{J}(\phi^{i})$ $\displaystyle=\mathbb{E}_{\bar{P}^{\phi^{i}}}\left[\sum_{b=1}^{B}\sum_{l=1}^{ MT}\nabla_{\phi^{i}}\log\pi^{i}(a^{i,b}_{l}\mid h^{i,b}_{l})\left(\frac{1}{B} \sum_{k=l}^{Tm_{l}}R_{k}^{i,b}+\frac{1}{B}\sum_{b^{\prime}=1}^{B}\sum_{k=Tm_{l }+1}^{MT}R_{k}^{i,b^{\prime}}\right)\right].$ (7) $$

We remind that the standard policy gradient, which would be used to train against e.g. another meta agent, is

$$ $\displaystyle\nabla_{\phi^{i}}\bar{J}(\phi^{i})$ $\displaystyle=\mathbb{E}_{\bar{P}^{\phi^{i}}}\left[\frac{1}{B}\sum_{b=1}^{B} \sum_{l=1}^{MT}\nabla_{\phi^{i}}\log\pi^{i}(a^{i,b}_{l}\mid h^{i,b}_{l})\left( \sum_{k=l}^{Tm_{l}}R_{k}^{i,b}+\sum_{k=Tm_{l}+1}^{MT}R_{k}^{i,b}\right)\right].$ (8) $$

##### Value function estimation.

Value functions are used for reducing the variance in the policy gradient estimator, by typically subtracting a baseline from the return estimator. In the above equation 7, the straightforward value function function to learn is

$$ $\displaystyle V(h_{l}^{i,b})$ $\displaystyle=\mathbb{E}_{\bar{P}^{\phi^{i}}(\cdot\mid h_{l}^{i,b})}\left[ \left(\frac{1}{B}\sum_{k=l}^{Tm_{l}}R_{k}^{i,b}+\frac{1}{B}\sum_{b^{\prime}=1} ^{B}\sum_{k=Tm_{l}+1}^{MT}R_{k}^{i,b^{\prime}}\right)\right].$ (9) $$

On expectation, the second term equals can be simplified, and the expression then becomes

$$ $\displaystyle\mathbb{E}_{\bar{P}^{\phi^{i}}(\cdot\mid h_{l}^{i,b})}\left[\left (\sum_{k=l}^{Tm_{l}}\frac{1}{B}R_{k}^{i,b}+\sum_{k=Tm_{l}+1}^{MT}R_{k}^{i,b^{ \prime}}\right)\right].$ (10) $$

Which has an additional $\frac{1}{B}$ factor on the left term compared to a value function that would need to be learnt when playing e.g. against a meta agent. This is undesirable for several reasons, one of which being that as $B$ increases, the value target becomes increasingly insensitive to the inner episode return, which makes learning difficult. Another reason is that the target magnitude between when playing against a naive agent or a meta agent can significantly differ.

We circumvent this by instead always learning the batch-unaware value function, i.e.

$$ $\displaystyle\hat{V}(h_{l}^{i,b})$ $\displaystyle=\mathbb{E}_{\bar{P}^{\phi^{i}}(\cdot\mid h_{l}^{i,b})}\left[ \left(\sum_{k=l}^{Tm_{l}}R_{k}^{i,b}+\sum_{k=Tm_{l}+1}^{MT}R_{k}^{i,b}\right) \right].$ (11) $$

As such, the same target is used for both when playing against a naive or a meta agent.

In practice, one can use the monte carlo estimates to learn it (or with variance reduction techniques such as td-lambda). Optionally, the second term can be replaced by the return over future inner episodes averaged over inner batch, for meta-episodes against naive learners.

We now see how the above value estimation can be used to update the policy following COALA-PG.

##### Policy update.

Ultimately we want an unbiased estimate of the advantage function, since this would allow the usage of algorithms like PPO or A2C.

The advantage of a state $h_{l}^{i,b}$ and action $a_{l}^{i,b}$ against a naive agent is

$$ $\displaystyle A(h_{l}^{i,b},a_{l}^{i,b})=$ $\displaystyle\mathbb{E}_{\bar{P}^{\phi^{i}}(\cdot\mid h_{l}^{i,b},a_{l}^{i,b}) }\left[\frac{1}{B}\sum_{k=l}^{Tm_{l}}R_{k}^{i,b}+\frac{1}{B}\sum_{b^{\prime}=1 }^{B}\sum_{k=Tm_{l}+1}^{MT}R_{k}^{i,b^{\prime}}\right]$ (12) $\displaystyle-\mathbb{E}_{\bar{P}^{\phi^{i}}(\cdot\mid h_{l}^{i,b})}\left[ \frac{1}{B}\sum_{k=l}^{Tm_{l}}R_{k}^{i,b}+\frac{1}{B}\sum_{b^{\prime}=1}^{B} \sum_{k=Tm_{l}+1}^{MT}R_{k}^{i,b^{\prime}}\right].$ (13) $$

We can reformulate the expression using $\hat{V}$ as follows:

$$ $\displaystyle A(h_{l}^{i,b},a_{l}^{i,b})=$ $\displaystyle\mathbb{E}_{\bar{P}^{\phi^{i}}(\cdot\mid h_{l}^{i,b},a_{l}^{i,b}) }\left[\frac{1}{B}\sum_{k=l}^{Tm_{l}}R_{k}^{i,b}+\frac{1}{B}\sum_{b^{\prime}=1 }^{B}\sum_{k=Tm_{l}+1}^{MT}R_{k}^{i,b^{\prime}}\right]$ (14) $\displaystyle-\frac{1}{B}\hat{V}(h_{l}^{i,b})-\frac{1}{B}\mathbb{E}_{\bar{P}^{ \phi^{i}}(\cdot\mid h_{l}^{i,b})}\left[\sum_{b^{\prime}\neq b}\hat{V}(h_{Tm_{l }+1}^{i,b^{\prime}})\right].$ (15) $$

A candidate is thus to simply take the monte carlo estimate of the above.

##### Additional tricks.

Here, we list a few tweaks of classical reinforcement learning trick for our application.

- •
Advantage normalization: as is common with PPO implementation, we investigate the use of advantage normalization. Given a batched trajectory of advantage estimation over which the policy should be updated, the trick consists in centering the advantage estimates over the batched trajectory. Empirically, we found out that when playing against a mixture of naive and meta learners, it was beneficial to apply the centering separately for the 2 types of meta-trajectories.
- •
Value normalization: Given that meta trajectories can be extremely long, and thus the return of very high variance, we investigate the use of value normalization, a crude approximation of the PopArt layer (Hessel et al., ). Effectively, for each batched trajectory on which the value loss is to be computed, we first normalize the empirical return by centering it to unit variance and zero mean, and regress the value estimate against it. Then, for the value prediction used for the policy update, the prediction is de-normalized (using the statistics from the batch). This allows for improved learning of value estimate with deep learning, at the cost of introducing non stationarity.
- •
Reward rescaling: as another way to prevent issues stemming from large value target, we investigate simply rescaling the reward of an environment when appropriate. Effectively, the reward is rescaled for the value and policy gradient computation, but all metrics are reported by reverting the scaling, i.e. reported in the original reward scale.

### A.3 Architecture

We choose a Hawk recurrent neural network as the policy and value function backbone (De et al., ), for all methods, both for meta and naive agents. First, a linear layer projects the observation into an embedding space of dimension $32$. Then, a single residual Hawk recurrent neural network with LRU width 32, MLP expanded width 32 and 2 heads follows. Finally, an RMS normalization layer is applied, after which 2 linear readouts, one for the value estimate, and the other for the policy logits, are applied.

All meta agent and naive agent parameters are initialized following the standard initialization scheme of Hawk. The last readout layers are however initialized to 0.

### A.4 Hyperparameters for each experiment

In all experiments, we first fix the environment hyperparameters. In order to find the suitable hyperparameter for each methods, we perform for each of them a sweep over reinforcement learning hyperparameters, and select the best hyperparameters over after averaging over 3 seeds. The final performance and metrics are then computed using 5 fresh seeds.

In all our experiments, naive agents update their parameters using the Advantage Actor Critic (A2C) algorithm, without value bootstrapping on the batch of length T trajectories. The hyperparameter for all experiments, can be found on Table 8.

##### IPD, Figure 5

We perform 2 experiments in the IPD environment, (i) the pure Shaping experiment with $p_{\text{naive}}=1$ to investigate the shaping capabilities of meta agents, and (ii) the mixed pool setting with $p_{\text{naive}}=0.75$, to investigate the collaboration capabilities of meta agents. For both experimental setting, we show the environment hyperparameters in Table 2. All meta agents are trained by PPO and Adam optimizer. For each method, we sweep hyperparameters over range specified in Table 3. Table  4 shows the resulting hyperparameters for all methods.

**Table 2: Hyperparameter fixed for the IPD experiments**
| IPD Hyperparameter | Pure Shaping | Mixed Pool |
| --- | --- | --- |
| training_iteration | $3000$ | $3000$ |
| meta_batch_size | $128$ | $128$ |
| batch_size (B) | $16$ | $16$ |
| num_inner_episode (M) | $20$ | $20$ |
| inner_episode_length (T) | $10$ | $10$ |
| p_naive | $1.$ | $0.75$ |
| population_size (meta) | $1$ | $4$ |
| population_size (naive) | $10$ | $10$ |
| dynamic_naive_agents | False | False |

**Table 3: The range of values swept over for hyperparameter search for each method for the IPD environment**
| RL Hyperparameter | Range |
| --- | --- |
| advantages_normalization | $\{False,True\}$ |
| value_normalization | $\{False,True\}$ |
| value_discount ($\gamma$) | $\{0.999,1.0\}$ |
| td_lambda ($\lambda_{\text{td}}$) | $\{1.0\}$ |
| gae_lambda ($\lambda_{\text{gae}}$) | $\{0.98,1.0\}$ |
| learning_rate | $\{0.003,0.001,0.0003\}$ |

**Table 4: Hyperparameters used for the IPD Shaping and Mixed Pool experiments. Despite the search, the hyperparameter chosen for each method were identical**
| RL Hyperparameter | Pure Shaping | Mixed Pool |
| --- | --- | --- |
| algorithm | PPO | PPO |
| ppo_nminibatches | $2$ | $2$ |
| ppo_nepochs | $4$ | $4$ |
| ppo_clipping_epsilon | $0.2$ | $0.2$ |
| value_coefficient | $0.5$ | $0.5$ |
| clip_value | True | True |
| entropy_reg | 0 0 | 0 0 |
| advantage_normalization | False | False |
| value_normalization | False | True |
| reward_rescaling | $0.05$ | $0.05$ |
| $\gamma$ | $1$ | $1$ |
| $\lambda_{\text{td}}$ | $1$ | $1$ |
| $\lambda_{\text{gae}}$ | $1$ | $1$ |
| optimizer | ADAM | ADAM |
| adam_epsilon | $0.00001$ | $0.00001$ |
| learning_rate | $0.0003$ | $0.0003$ |
| max_grad_norm | $1$ | $1$ |

##### Cleanup, Figure 6 , 7

Likewise, we have the pure shaping (Figure 6) and mixed pool (Figure 7) experiment in the Cleanup-lite environment. For both experimental setting, we show the environment hyperparameters in Table 5. All meta agents are trained by PPO and Adam optimizer for the pure shaping setting, while using A2C and SGD for the mixed pool setting. For each method, we sweep hyperparameters over range specified in Table 6. Table  7 shows the resulting hyperparameters for PPO for all methods.

**Table 5: Cleanup hyperparameters**
| Hyperparameter fixed for the Cleanup experiments | Pure Shaping | Mixed Pool |
| --- | --- | --- |
| training_iteration | $3000$ | $10000$ |
| meta_batch_size | $512$ | $512$ |
| batch_size (B) | $32$ | $64$ |
| num_inner_episode (M) | $100$ | $5$ |
| inner_episode_length (T) | $64$ | $64$ |
| p_naive | $1.$ | $0.75$ |
| population_size (meta) | $1$ | $4$ |
| population_size (naive) | $10$ | $4$ |
| dynamic_naive_agents | False | True |

**Table 6: The range of values swept over for hyperparameter search for each method for the Cleanup environment**
| RL Hyperparameter | Pure Shaping | Mixed Pool |
| --- | --- | --- |
| advantages_normalization | $\{False,True\}$ | $\{False,True\}$ |
| value_normalization | $\{False,True\}$ | $\{False,True\}$ |
| reward_rescaling | $\{1.\}$ | $\{0.1\}$ |
| value_discount ($\gamma$) | $\{0.999,1.0\}$ | $\{0.99,1.0\}$ |
| gae_lambda ($\lambda_{\text{gae}}$) | $\{0.98,1.0\}$ | $\{1.0\}$ |
| learning_rate | $\{0.003,0.001,0.0003\}$ | $\{0.03,0.01,0.5,1.0\}$ |
| optimizer | {ADAM} | {SGD} |

**Table 7: Hyperparameters used for the Cleanup Shaping and Cleanup Pool experiments.**
| RL Hyperparameter | Cleanup Shaping | Cleanup Pool |  |  |  |  |
| --- | --- | --- | --- | --- | --- | --- |
|  | Coala | Batch Unaware | M-FOS | Coala | Batch Unaware | M-FOS |
| algorithm | PPO | PPO | PPO | A2C | A2C | A2C |
| ppo_nminibatches | $2$ | $2$ | $2$ | - | - | - |
| ppo_nepochs | $4$ | $4$ | $4$ | - | - | - |
| ppo_clipping_epsilon | $0.2$ | $0.2$ | $0.2$ | - | - | - |
| value_coefficient | $0.5$ | $0.5$ | $0.5$ | - | - | - |
| clip_value | True | True | True | True | True | True |
| entropy_regularization | 0 0 | 0 0 | 0 0 | 0 0 | 0 0 | 0 0 |
| advantage_normalization | False | True | True | True | True | True |
| value_normalization | True | True | True | False | False | False |
| reward_rescaling | $1$ | $1$ | $1$ | $0.1$ | $0.1$ | $0.1$ |
| $\gamma$ | $1$ | $0.98$ | $0.999$ | $1$ | $1$ | $1$ |
| $\lambda_{\text{td}}$ | $1$ | $1$ | $1$ | $1$ | $1$ | $1$ |
| $\lambda_{\text{gae}}$ | $1$ | $1$ | $1$ | $1$ | $1$ | $1$ |
| optimizer | ADAM | ADAM | ADAM | SGD | SGD | SGD |
| adam_epsilon | $0.00001$ | $0.00001$ | $0.00001$ | - | - | - |
| learning_rate | $0.003$ | $0.001$ | $0.001$ | $0.03$ | $0.03$ | $0.1$ |
| max_grad_norm | $1$ | $1$ | $1$ | $1$ | $1$ | $1$ |

**Table 8: Naive agent hyperparameters used across different settings**
| RL Hyperparameter | IPD Shaping | IPD Mixed | Cleanup Shaping | Cleanup Mixed |
| --- | --- | --- | --- | --- |
| algorithm | A2C | A2C | A2C | A2C |
| advantages_normalization | True | True | True | True |
| value_normalization | False | False | False | False |
| reward_rescaling | $0.05$ | $0.05$ | $1.$ | $0.1$ |
| value_discount ($\gamma$) | $0.99$ | $0.99$ | $0.99$ | $0.99$ |
| td_lambda ($\lambda_{\text{td}}$) | $1.0$ | $1.0$ | $1.0$ | $1.0$ |
| gae_lambda ($\lambda_{\text{gae}}$) | $1.0$ | $1.0$ | $1.0$ | $1.0$ |
| value_coefficient | $0.5$ | $0.5$ | $0.5$ | $0.5$ |
| entropy_reg | $0.0$ | $0.0$ | $0.0$ | $0.0$ |
| optimizer | ADAM | ADAM | ADAM | SGD |
| adam_epsilon | $0.00001$ | $0.00001$ | $0.00001$ | $-$ |
| learning_rate | $0.005$ | $0.005$ | $0.005$ | $1.$ |
| max_grad_norm | $1.0$ | $1.0$ | $1.0$ | $1.0$ |

## Appendix B The analytical iterated prisoner’s dilemma

For the experiments in Section 4 and 5, we analytically compute the discounted expected return of an infinitely iterated prisoner’s dilemma, and its parameter gradients. Automatic differentiation allows us then to explicitly backpropagate through the learning trajectory of naive learners, to compute the ground-truth meta update. In the following, we provide details on this approach.

For both the naive learners and learning-aware meta agents, we consider tabular policies $\phi^{i}$ taking into account the previous action of both agents:

$$ $\displaystyle\phi^{i}=[\phi^{i}_{0},\phi^{i}_{1},\phi^{i}_{2},\phi^{i}_{3}, \phi^{i}_{4}]^{\top}$ $$

with $\sigma(\phi^{i}_{0})$ the probability of cooperating in the initial state (with sigmoid $\sigma$), and the next 4 parameters the logits of cooperating in states CC, CD, DC and DD respectively (CD indicates that first agent cooperated, and the second agent defected). As we use a tabular policy for the meta agents, they cannot accurately infer the opponent’s parameters from context, but its policy gradient updates still inform it regarding the learning behavior of naive learners. Hence the meta agent can learn to shape naive learners while using a tabular policy, for example through zero-determinant extortion strategies (Press and Dyson, ). Using both policies, we can construct a Markov matrix providing the transition probabilities of one state to the next, ignoring the initial state.

$$ $\displaystyle M=\begin{bmatrix}\sigma(\phi^{1}_{1:4})\odot\sigma(\phi^{2}_{1:4 }),\sigma(\phi^{1}_{1:4})\odot(1-\sigma(\phi^{2}_{1:4})),(1-\sigma(\phi^{1}_{1 :4}))\odot\sigma(\phi^{2}_{1:4}),(1-\sigma(\phi^{1}_{1:4}))\odot(1-\sigma(\phi ^{2}_{1:4}))\end{bmatrix}^{\top}$ $$

with $\odot$ the element-wise product. Given the payoff vectors $r^{1}=[1,-1,2,0]$ and $r^{2}=[1,2,-1,0]$, and initial state distribution $s_{0}=[\sigma(\phi^{1}_{0})\sigma(\phi^{2}_{0}),\sigma(\phi^{1}_{0})(1-\sigma(
\phi^{2}_{0})),(1-\sigma(\phi^{1}_{0}))\sigma(\phi^{2}_{0}),(1-\sigma(\phi^{1}
_{0}))(1-\sigma(\phi^{2}_{0}))]^{\top}$ we can write the expected discounted return of agent $i$ as

$$ $\displaystyle J^{i}(\phi^{1},\phi^{2})=r^{i,\top}\left[\sum_{t=0}^{\infty} \gamma^{t}M^{t}s_{0}\right]$ (16) $$

This discounted infinite matrix sum is a Neumann series of the inverse $(I-\gamma M)^{-1}$ with $I$ the identity matrix. This gives us:

$$ $\displaystyle J^{i}(\phi^{1},\phi^{2})=r^{i,\top}(I-\gamma M)^{-1}s_{0}$ (17) $$

Both $M$ and $s_{0}$ depend on the agent’s policies, and we can compute the analytical gradients using automatic differentiation (we use JAX).

We model naive learners $\phi^{-i}$ as taking gradient steps on $J^{-i}$ with learning rate $\eta_{\text{naive}}$. The co-player shaping objective for meta agent $i$ is now

$$ $\displaystyle\bar{J}(\phi^{i})=\sum_{m=0}^{M}J^{i}\left(\phi^{i},\phi^{-i}+ \sum_{q=1}^{m}\Delta_{q}\phi^{-i}\right)\leavevmode\nobreak\ \leavevmode \nobreak\ \leavevmode\nobreak\ \text{s.t.}\leavevmode\nobreak\ \leavevmode \nobreak\ \Delta_{q}\phi^{-i}=\eta_{\text{naive}}\frac{\partial}{\partial\phi^ {-i}}J^{i}\left(\phi^{i},\phi^{-i}+\sum_{q^{\prime}=1}^{q-1}\Delta_{q^{\prime} }\phi^{-i}\right)$ (18) $$

When a learning-aware meta agent faces a naive learner, we compute the shaping gradient by explicitly backpropagating through $\bar{J}(\phi^{i})$, using automatic differentiation. When a learning-aware meta agent faces another meta agent, we compute the policy gradient as the partial gradient on $J^{i}(\phi^{i},\phi^{-i})$, as with tabular policies, the meta agents deploy the same policy in each inner episode, and hence averaging over inner episodes is equivalent to playing a single episode of meta vs meta. For training the meta agents, we use a convex mixture of the gradients against naive learners and gradients against the other meta agent, with mixing factor $p_{\text{naive}}$. For the gradients against naive learners, we use a batch of randomly initialized naive learners of size metabatch. We use the adamw optimizer from the Optax library to train the meta agents, with default hyperparameters and learning rate $\eta_{\text{meta}}$.

For the LOLA experiments of Section 5, we compute the ground-truth LOLA-DICE updates equation 5 by initializing a naive learner with the opponent’s parameters, simulate $M$ naive updates (look-aheads) following partial derivatives of $J^{i}$, and backpropagating through the final return $J^{i}\left(\phi^{i},\phi^{-i}+\sum_{q=1}^{M}\Delta_{q}\phi^{-i}\right)$, including backpropagating through the learning trajectory. For Figure 4, we train two separate LOLA agents against each other and report the training curves of the first agent (the training curves of the second agent are similar, data not shown). Using self-play instead of other-play resulted in similar results with the same main conclusions (data not shown). For all experiments, we used the following hyperparemeters: $\gamma=0.95$, $\eta_{\text{meta}}=0.005$, $\eta_{\text{naive}}=5$ (except for 1-look-ahead, where we used $\eta_{\text{naive}}=10$). For Figure 4C, we used a convex mixture of the LOLA-DICE gradient and the partial gradient on $J^{i}(\phi^{i},\phi^{-i})$ with mixing factor $p_{\text{naive}}$. We used $p_{\text{naive}}=1,1,0.75,0.6,0.4$ for look-aheads 1, 2, 3, 10 and 20 respectively.

## Appendix C Proofs

###### Theorem C.1 .

Take the expected shaping return $\bar{J}(\phi^{i})=\mathbb{E}_{\bar{P}^{\phi^{i}}}\left[\frac{1}{B}\sum_{b=1}^{
B}\sum_{l=0}^{MT}R^{i,b}_{l}\right]$, with $\bar{P}^{\phi^{i}}$ the distribution induced by the environment dynamics $\bar{P}_{t}$, initial state distribution $\bar{P}_{i}$ and policy $\phi^{i}$. Then the policy gradient of this expected return is equal to

$$ $\displaystyle\nabla_{\phi^{i}}\bar{J}(\phi^{i})=\mathbb{E}_{\bar{P}^{\phi^{i}} }\left[\sum_{b=1}^{B}\sum_{l=1}^{MT}\nabla_{\phi^{i}}\log\pi^{i}(a^{i,b}_{l} \mid h^{i,b}_{l})\left(\frac{1}{B}\sum_{b^{\prime}=1}^{B}\sum_{k=l}^{MT}R_{k}^ {i,b^{\prime}}\right)\right].$ (19) $$

###### Proof.

Applying the policy gradient theorem (Sutton et al., ) to the batched co-player shaping POMDP, for the minibatch-joint policy $\bar{\pi}^{i}(\bar{a}_{l}^{i}\mid\bar{h}_{l}^{i};\phi^{i})$ leads to

$$ $\displaystyle\nabla_{\phi^{i}}\bar{J}(\phi^{i})=\mathbb{E}_{\bar{P}^{\phi^{i}} }\left[\sum_{l=1}^{MT}\nabla_{\phi^{i}}\log\bar{\pi}^{i}(\bar{a}_{l}^{i}\mid \bar{h}_{l}^{i};\phi^{i})\left(\frac{1}{B}\sum_{b^{\prime}=1}^{B}\sum_{k=l}^{ MT}R_{k}^{i,b^{\prime}}\right)\right]$ $$

Factorizing the minibatch-joint policy $\bar{\pi}$ as $\bar{\pi}^{i}(\bar{a}^{i}_{l}\mid\bar{h}^{i}_{l};\phi^{i})=\prod_{b=1}^{B}\pi^
{i}(a^{i,b}_{l}\mid h^{i,b}_{l})$ leads to

$$ $\displaystyle\nabla_{\phi^{i}}\bar{J}(\phi^{i})=\mathbb{E}_{\bar{P}^{\phi^{i}} }\left[\sum_{b=1}^{B}\sum_{l=1}^{MT}\nabla_{\phi^{i}}\log\pi^{i}(a^{i,b}_{l} \mid h^{i,b}_{l})\left(\frac{1}{B}\sum_{b^{\prime}=1}^{B}\sum_{k=l}^{MT}R_{k}^ {i,b^{\prime}}\right)\right]$ $$

thereby concluding the proof.
∎

###### Theorem C.2 .

Assuming that (i) the COALA policy is only conditioned on inner episode histories $x_{m,t}^{i,b}$ instead of long histories $h_{l}^{i,b}$, and (ii) the naive learners are initialized with the current parameters $\phi^{-i}$ of the other agents, then the COALA-PG update on the batched co-player shaping POMDP is equal to

$$ $\displaystyle\nabla_{\phi^{i}}\bar{J}(\phi^{i})=\frac{\mathrm{d}}{\mathrm{d} \phi^{i}}\sum_{m=0}^{M}\mathbb{E}_{\bar{P}^{\phi^{i}}}\left[J^{i}\left(\phi^{i },\phi^{-i}+\sum_{q=1}^{m}\Delta\phi^{-i}(\bar{x}_{q,T})\right)\right]$ (20) $$

with $\Delta\phi^{-i}(\bar{x}_{q,T})$ the naive learner’s update based on the batch of inner-episode histories $\bar{x}_{q,T}$, and $\frac{\mathrm{d}}{\mathrm{d}\phi^{i}}$ the total derivative, taking into account both the influence of $\phi^{i}$ through the first argument of $J^{i}(\phi^{i},\phi^{-i}+\sum_{q=1}^{m}\Delta\phi^{-i}(\bar{x}_{q,T}))$, as well as through the parameter updates $\Delta\phi^{-i}$ by adjusting the distribution over $\bar{x}_{q,T}$.

###### Proof.

We start by restructuring the long-history expected return $\bar{J}$ of the batched co-player shaping POMDP into a sum of inner episode expected returns $J$ from the multi-agent POSG, leveraging the assumptions that (i) the COALA policy is only conditioned on inner episode histories $x_{m,t}^{i,b}$ instead of long histories $h_{l}^{i,b}$, and (ii) the naive learners are initialized with the current parameters $\phi^{-i}$ of the other agents.

$$ $\displaystyle\bar{J}(\phi^{i})$ $\displaystyle=\mathbb{E}_{\bar{P}^{\phi^{i}}}\left[\frac{1}{B}\sum_{b=1}^{B} \sum_{t=0}^{MT}R^{i,b}_{t}\right]$ $\displaystyle=\sum_{m=0}^{M-1}\mathbb{E}_{\bar{P}^{\phi^{i}}}\left[\frac{1}{B} \sum_{b=1}^{B}\sum_{t=mT+1}^{(m+1)T}R^{i,b}_{t}\right]$ $\displaystyle=\sum_{m=0}^{M-1}\mathbb{E}_{\bar{P}^{\phi^{i}}(\bar{h}_{mT})} \left[\frac{1}{B}\sum_{b=1}^{B}\mathbb{E}_{P^{\phi^{i},\phi^{-i}+\sum_{q=1}^{m }\Delta\phi^{-i}(\bar{x}_{q,T})}}\left[\sum_{t=mT+1}^{(m+1)T}R^{i,b}_{t}\right ]\right]$ $\displaystyle=\sum_{m=0}^{M-1}\mathbb{E}_{\bar{P}^{\phi^{i}}}\left[J^{i}\left( \phi^{i},\phi^{-i}+\sum_{q=1}^{m}\Delta\phi^{-i}(\bar{x}_{q,T})\right)\right]$ $$

with $P^{\phi^{i},\phi^{-i}+\sum_{q=1}^{m}\Delta\phi^{-i}(\bar{x}_{q,T})}$ the distribution induced by the environment dynamics of the multi-agent POSG, played with policies $(\phi^{i},\phi^{-i}+\sum_{q=1}^{m}\Delta\phi^{-i}(\bar{x}_{q,T}))$. The step from line two to three is made possible by the assumption that the COALA policy $\pi^{i}$ is only conditioned on inner episode histories $x_{m,t}^{i,b}$ instead of long histories $h_{l}^{i,b}$. This ensures that the distribution $\bar{P}^{\phi^{i}}$ over the batch of inner-episode histories $\bar{x}_{m+1,T}$ only depends on $(\phi^{i},\phi^{-i}+\sum_{q=1}^{m}\Delta\phi^{-i}(\bar{x}_{q,T}))$, as the policy $\pi^{i}$ does not take previous observations from before the current inner episode boundary into account.

A policy gradient takes into account the full effect of the parameters of a policy on the trajectory distribution induced by the policy. In our batched co-player shaping POMDP, the trajectory distribution induced by policy $\phi^{i}$ influences the reward distribution in the concatenated POSG, as well as the naive learner’s current parameters through the inner episode batches they use for their updates. Hence, we have that

$$ $\displaystyle\nabla_{\phi^{i}}\bar{J}(\phi^{i})=\frac{\mathrm{d}}{\mathrm{d} \phi^{i}}\sum_{m=0}^{M}\mathbb{E}_{\bar{P}^{\phi^{i}}}\left[J^{i}\left(\phi^{i },\phi^{-i}+\sum_{q=1}^{m}\Delta\phi^{-i}(\bar{x}_{q,T})\right)\right]$ $$

with $\frac{\mathrm{d}}{\mathrm{d}\phi^{i}}$ the total derivative, taking into account both the influence of $\phi^{i}$ through the first argument of $J^{i}(\phi^{i},\phi^{-i}+\sum_{q=1}^{m}\Delta\phi^{-i}(\bar{x}_{q,T}))$, as well as through the parameter updates $\Delta\phi^{-i}$ by adjusting the distribution over $\bar{x}_{q,T}$, thereby concluding the proof.

∎

###### Theorem C.1 .

###### Proof.

###### Theorem C.2 .

###### Proof.

## Appendix D Deriving prior shaping algorithms from Eq. 1

The general shaping problem due to Lu et al. () presented in Eq. 1, which we repeat below for convenience, captures many of the relevant co-player shaping techniques in the literature.

$$ $\displaystyle\max_{\mu}\mathbb{E}_{\tilde{P}_{i}(\phi^{i}_{0},\phi^{-i}_{0})} \mathbb{E}_{\tilde{P}^{\mu}}\left[\sum_{m=m_{\mathrm{start}}}^{M}J^{i}(\phi_{m }^{i},\phi^{-i}_{m})\right],$ (21) $$

M-FOS solves this co-player shaping problem without making further assumptions (Lu et al., ). Good Shepherd uses a stateless meta-policy $\mu(\phi^{i}_{m};\theta)=\delta(\phi^{i}_{m}=\theta)$, with $\delta$ the Dirac-delta distribution (Balaguer et al., ). Meta-MAPG (Kim et al., ) meta-learns an initialization $\phi^{i}_{0}=\theta$ in the spirit of model-agnostic meta-learning (Finn et al., ), and lets every player learn by following gradients on their respective objectives. The meta-value learning method (Cooijmans et al., ) models the meta-policy $\mu(\phi^{i}_{m+1}\mid\phi^{i}_{m},\phi^{-i}_{m};\theta)$ as the gradient on a meta-value function $V(\phi^{i}_{m},\phi^{-i}_{m})$ parameterized by $\theta$. Finally, we recover a single LOLA update step (Foerster et al., ) by initializing $(\phi^{i}_{0},\phi^{-i}_{0})$ with the current parameters of all agents, taking $M=m_{\mathrm{start}}=1$, using a stateless meta-policy $\mu(\phi^{i}_{m};\theta)=\delta(\phi^{i}_{m}=\theta)$ and taking a single gradient step w.r.t. $\theta$, instead of solving the shaping problem to convergence.

## Appendix E Detail on baseline learning rules

### E.1 Batch-unaware COALA PG

We remind that the policy gradient expression for COALA is as follows

$$ $\displaystyle\nabla_{\phi^{i}}\bar{J}(\phi^{i})=\mathbb{E}_{\bar{P}^{\phi^{i}} }\left[\sum_{b=1}^{B}\sum_{l=1}^{MT}\nabla_{\phi^{i}}\log\pi^{i}(a^{i,b}l\mid h ^{i,b}_{l})\left(\frac{1}{B}\sum_{b^{\prime}=1}^{B}\sum_{k=l}^{MT}R_{k}^{i,b^{ \prime}}\right)\right].$ (22) $$

The batch-unaware COALA PG is the naive baseline, consisting in applying policy gradient methods to individual trajectories in a batch, i.e.

$$ $\displaystyle\hat{\nabla}_{\phi^{i},\text{batch-unaware}}\bar{J}(\phi^{i})= \mathbb{E}_{\bar{P}^{\phi^{i}}}\left[\frac{1}{B}\sum_{b=1}^{B}\sum_{l=1}^{MT} \nabla_{\phi^{i}}\log\pi^{i}(a^{i,b}l\mid h^{i,b}_{l})\sum_{k=l}^{MT}R_{k}^{i, b}\right].$ (23) $$

### E.2 M-FOS

Lu et al. () consider both a policy gradient method and evolutionary search method to optimize the shaping problem of Eq. 1. Here, we focus on the M-FOS policy gradient method, which was used by Lu et al. () in their Coin Game experiments, which is their only experiment that goes beyond tabular policies. M-FOS uses a distinct architecture with a recurrent neural network as inner policy, which receives an extra conditioning vector as input from a meta policy that processes inner episode batches. As shown by Khan et al. (), we can obtain better performance by combining both inner and meta policy in a single sequence model with access to the full history $h_{l}$ containing all past inner episodes. Hence, we use this improved architecture for our M-FOS baseline, which we train by the policy gradient method proposed by Lu et al. (). This allows us to use the same architecture for both M-FOS and COALA.

As the manuscript of (Lu et al., ) does not explicitly mention how to deal with the inner-batch dimension of a naive learner, we reconstruct the learning rule from their publicly available codebase. By denoting by $m_{l}$ the inner episode index corresponding to the meta episode time step $l$, the update is as follows:

$$ $\displaystyle\hat{\nabla}_{\phi^{i},\text{M-FOS}}\bar{J}(\phi^{i})=\mathbb{E}_ {\bar{P}^{\phi^{i}}}\left[\sum_{b=1}^{B}\sum_{l=1}^{MT}\nabla_{\phi^{i}}\log \pi^{i}(a^{i,b}_{l}\mid h^{i,b}_{l})\left(\sum_{k=l}^{Tm_{l}}R_{k}^{i,b}+\frac {1}{B}\sum_{b^{\prime}=1}^{B}\sum_{k=Tm_{l}+1}^{MT}R_{k}^{i,b^{\prime}}\right) \right].$ (24) $$

We note that when taking the inner-episode boundaries into account in the COALA-PG update, due to some terms disappearing from the expectation, the expression becomes

$$ $\displaystyle\nabla_{\phi^{i}}\bar{J}(\phi^{i})=\mathbb{E}_{\bar{P}^{\phi^{i}} }\left[\sum_{b=1}^{B}\sum_{l=1}^{MT}\nabla_{\phi^{i}}\log\pi^{i}(a^{i,b}_{l} \mid h^{i,b}_{l})\left(\frac{1}{B}\sum_{k=l}^{Tm_{l}}R_{k}^{i,b}+\frac{1}{B} \sum_{b^{\prime}=1}^{B}\sum_{k=Tm_{l}+1}^{MT}R_{k}^{i,b^{\prime}}\right)\right].$ (25) $$

One can see that the M-FOS update rule closely resembles COALA-PG, except for the fact that it is lacking a factor $\frac{1}{B}$ in front of the reward of the current inner episode. As we show in our experiments, this biases the policy gradient and introduces inefficiencies in the optimization.

## Appendix F Software

The results reported in this paper were produced with open-source software. We used the Python programming language together with the Google JAX (Bradbury et al., ) framework, and the NumPy (Harris et al., ), Matplotlib (Hunter, ), Flax (Heek et al., ) and Optax (Babuschkin et al., ) packages.

## Peer Reviews

confidence: 4
contribution: 2
initial_rating: 6
presentation: 3
questions: please see the weaknesses
soundness: 3
strengths: 1. The paper is well-written and well-organized. 
2. Theoretical proofs are complete and sound.
summary: This paper introduces a new learning-aware reinforcement learning rule derived as a policy gradient estimator. Instead of using long histories of samples, the policy gradients consider the stochastic minibatch updates used by other agents. The results show improvements in some mixed environments. Overall, the paper is well-written and well-organized. The notations are standard, and the theorems are sound.
weaknesses: 1. The motivation for proposing COALA-PG is unclear. It’s not obvious whether the issue is related to variance or other issues when using mini-batches. The authors suggest that larger mini-batches could pose a problem, but this may lead to higher variance in reward summation. However, these points are not extensively discussed in the manuscript. Additionally, compared to M-FOS, it appears that COALA-PG uses the 1/B term to scale rewards, but it seems that this scaling is still related to controlling the policy gradient’s variance.

2. Why not use a Q-function instead of summing rewards?

3. In Theorem 3.1, what is the advantage of using batches of inner episode histories instead of a long history? Are there any theoretical insights supporting this approach?

---

confidence: 4
contribution: 2
initial_rating: 5
presentation: 2
questions: 1. Given that full history dependency may reduce partially observable settings to fully observable ones in discrete environments, have the authors conducted a sample complexity analysis for handling true partial observability, where agents have limited access to or storage for historical data?
2. Could the authors elaborate on their choice of the Iterated Prisoner´s Dilemma and Cleanup as experimental benchmarks? 
3. Could the authors discuss whether any convergence properties have been considered for COALA-PG? Given the absence of a formal convergence analysis, how do the authors anticipate the framework will behave in non-stationary environments?
soundness: 2
strengths: 1. **History-Dependent Adaptation for Multi-Agent Cooperation:** The paper introduces a promising approach that enables agents to adaptively cooperate by conditioning policy updates on observation histories. This allows agents to respond to non-stationarity in general-sum games, specifically handling the evolving distributions of co-agent strategies as each agent independently learns and adapts over time. By incorporating these historical observations, the framework aims to maintain effective cooperation even as the behaviors of other agents shift dynamically, without explicitly modeling the non-stationarity or learning dynamics of other agents.
2. **Theoretical and Practical Advancements in Policy Gradient Estimation:** Theorems 3.1 and 3.2 present a robust policy gradient estimation method specifically designed for cooperative multi-agent learning. COALA-PG´s use of accumulated gradients and minibatch summation approach improves stability and adaptability without requiring higher-order gradients. This makes COALA-PG more scalable in comparison to methods like LOLA-DICE. Additionally, the use of value function baselines in gradient estimation reduces variance which increases COALA-PG´s practical applicability.
3. **Supporting Results Against Naive Learner Baselines:** Empirical comparisons demonstrate that COALA-PG outperforms naive, non-history-conditioned learners, demonstrating the benefit of history dependency in non-stationary environments.
summary: This study presents a framework for multi-agent cooperation in partially observable general-sum games to enable agents to adaptively cooperate in non-stationary environments by conditioning their policies on past interactions. The COALA-PG method introduces improved policy calculation through accumulated gradients and variance reduction that enhances stability and computational efficiency. The framework is tested on benchmark tasks such as the Iterated Prisoner´s Dilemma and the Cleanup game, demonstrating cooperative behavior among decentralized agents.
weaknesses: 1. **Full History Dependency:** While history dependency enables adaptability, it may approximate full observability, especially in discrete environments. By accumulating state-action information over time, agents in discrete settings could essentially reconstruct the environment as if fully observable, reducing the framework´s applicability in scenarios where true partial observability is intended.
2. **Simplistic Experimental Scenarios:** The chosen experiments, such as the Iterated Prisoner’s Dilemma (IPD) and Cleanup, are relatively simple and do not fully demonstrate the framework´s ability to manage partial observability or complex, dynamic cooperation. IPD lacks multi-step state evolution, and while Cleanup provides more interaction, it still operates in a low-dimensional grid setting, which is easier for agents to handle than high-dimensional or real-world environments.
3. **Lack of Convergence Analysis:** COALA-PG lacks formal guarantees of stability or convergence in non-stationary environments. This leaves open questions about COALA-PG´s ability to adapt as agent strategies evolve. The study would benefit from additional theoretical or empirical validation to support its effectiveness in highly dynamic settings.

---

confidence: 2
contribution: 3
initial_rating: 8
presentation: 4
questions: None
soundness: 3
strengths: 1. Clear writing, clear concept definition.
2. extensive theoratic comparison with prior works and experiments on two non-trivial settings.
3. enough details of implementation in the appendix.
summary: To solve two challenges of general-sum games: 1. Non-stationarity of the environment, hard to choose a good equilibrium. The author propose an unbiased, higher derivative-free policy gradient algorithm for learning-aware RL, which considers how the action will influence the other agent's policy changing: They do policy gradient in meta-episode. They have extensive theoratic comparison of their meta policy gradient with prior works. And have interesting findings in the iterated prisoner's dilemma and a grid-world-like social dilemma "CleanUp".
weaknesses: This may be difficult, but it would be great if you could show the efficiency of your method on more difficult environments of deep MARL beyond matrix game or grid world (like Agar.io[1])

[1]: Discovering Diverse Multi-Agent Strategic Behavior via Reward Randomization, ICLR 2021

---

confidence: 4
contribution: 3
initial_rating: 6
presentation: 3
questions: 1.	What are the key differences between the proposed batched co-player shaping POMDP and a standard POMDP with parallel environments? Equation 3 appears to simply sum rewards across parallel environments, making it unclear what distinct advantages this formulation provides.
2.	The font size in the figures is too small, making it difficult to read. Enhancing font size and clarity would significantly improve readability.
3.	 There are well-known baseline methods in the mixed-motive game literature, particularly within the Cleanup environment. Why does the paper not include comparisons with these established methods?
4.       More information is needed on the simplified Cleanup environment. How does it differ from the standard Cleanup environment, and what are the implications of these differences for the study’s findings?
5.	 While the paper aims to address a mixed-motive game, the problem is formulated as a general-sum game. In my view, general-sum games are not fully equivalent to mixed-motive games. Could you clarify the rationale behind this formulation choice?
soundness: 3
strengths: 1. The paper tackles a core issue in multi-agent learning - fostering cooperation among self-interested agents.
2. The introduction of the first unbiased, higher-derivative-free policy gradient algorithm for learning-aware reinforcement learning is a significant contribution.
3. The proposed algorithm appears to outperform existing methods in achieving cooperation.
4.The paper proposes a novel explanation for cooperation emergence based on learning-awareness and agent heterogeneity in the iterated prisoner's dilemma.
summary: The paper introduces a novel policy gradient algorithm for learning-aware reinforcement learning, which allows agents to model the learning dynamics of other agents. This approach enables cooperative behavior among self-interested agents, even in complex scenarios like temporally extended action coordination. The algorithm avoids higher-order derivatives, and can handle mini-batched learning. Additionally, the paper provides a theoretical explanation for the emergence of cooperation in the iterated prisoner's dilemma based on learning awareness and agent heterogeneity.
weaknesses: In my view, the “elegant” formulation and the batched co-player shaping POMDP appear similar to a parallel environment POMDP setup, while COALA-PG seems more like a delayed optimization applied after several episodes. This raises concerns about the true novelty and contribution of the work. I have a few specific questions regarding this point.

It’s entirely possible that I may not yet have fully understood the paper. However, improving the paper’s clarity and structure would make it more accessible and easier to follow.

I look forward to discussing these points with the authors, and I am open to raising my score if my concerns are addressed satisfactorily.

---

confidence: 4
contribution: 3
initial_rating: 5
presentation: 4
questions: * Why is there no experiment for LOLA?
* Why does batch-unaware COALA-PG perform so similar to M-FOS, while the batch-aware COALA-PG surpasses it? Did you investigate how gradients change and why the batch-aware gradients work so well?
soundness: 2
strengths: * Introduction of a novel unbiased policy gradient formulation to shape naive learners that does not need to know the learners' optimization functions but can infer them by sequence modeling.
* Comparisons showing the effect of how learners are pooled (meta vs naive or meta vs meta etc.) give insight into how shaping is achieved.
* COALA-PG improves performance over M-FOS.
* The figures are informative.
summary: The paper brings sound improvements over the current opponent shaping methods for non-cooperative general-sum games with self-interested learners. The core contributions over the existing methods are introducing a policy-gradient method (COALA-PG) capable of shaping other learners without making any assumptions on learners' optimization functions due to the sequential and batched nature of the expected return to be maximized. The method is evaluated on Iterated Prisoner's Dilemma and CleanUp environments. COALA-PG is compared to M-FOS and variants of itself as a baseline and investigation of how the pool of learners, whether they are meta or naive learners, affect reaching cooperation.
weaknesses: * There is insufficient explanation on why COALA-PG is so much better than batch-unaware COALA-PG which perform very similar to M-FOS. The credit assignment figure is a nice visualization to give intuition, but it does not provide concrete explanation and we have to speculate. Since batch-awareness is the main factor that makes COALA-PG's performance superior, it is difficult to attribute the success to sequence modeling and inferring the learning dynamics. There should be an investigation into how batch-awareness affect and change gradients and why batch-unaware COALA-PG is performs similar to MFOS.
* Baselines are insufficient. The only shaping method compared is the MFOS. Although mentioned in the paper, no comparison to Shaper is done in experiments. There is no comparison to LOLA either; even though MFOS is already expected to outperform LOLA, still a verification should have been done.
* There is no versus for different shaping methods, i.e. there is no experiment on how COALA-PG shapes M-FOS and vice versa.

---

confidence: 3
contribution: 2
initial_rating: 6
presentation: 3
questions: Questions are mentioned in the weaknesses part.
soundness: 3
strengths: - This work addresses a central challenge in MARL.
- The proposed framework (Figures 1 and 2) is important.
- The method parameters are thoroughly detailed in the appendix.
- Finding 1 is especially intriguing.
summary: This work proposes a new paradigm for MARL that enables agents to be aware of inter-episode dynamics and presents compelling experimental results in both the iterated prisoner’s dilemma and a grid-world sequential social dilemma.
weaknesses: - Line 114: The metric used in this work is ambiguous. Could you clarify which metric is applied in subsequent sections? What expectations should we have to claim that the proposed method outperforms other algorithms?
	- In Line 485, it appears the objective is solely the meta-agent's reward rather than equilibrium. Can we then say that this work is aimed at developing an algorithm to exploit naive agents?
	- Or is this an agent-based simulation method?

- Line 191: The definition states that the "state" in this game includes all agents' policy parameters. This creates an exponentially large space, especially when agents are assumed to use neural networks. In this case, the state encompasses the combined network parameters of all agents.
	- To implement a meta-agent in this setting, does the input of its policy network include the policy network parameters of other naive agents? If so, how is this optimized and implemented?
	- According to equation (4) and (5), I suppose that the meta agent does not input the others' parameters to its own policy network, but treats it by sampling the gradient. Then why is this estimation unbiased? Using sampling method does not seem to solve the non-stationarity issue. And this contradicts the motivation of this method.
	- If there are two meta-agents in the training phase, how do they treat each other? Are their gradient chains intertwined, or do they simply treat one another as naive agents?
- Line 998: The proof relies on Sutton’s policy gradient theorem, which assumes a fully observable environment. But Line 72 states that this environment is partially observable. Does the derivation still hold in this case? (I doubt the gradient computation is exact in this context, but I understand it may be an acceptable estimate for experimental purposes.)
	- Equation (4) shouldn’t be an equality but should have a scaling factor.
- Line 370: This experiment begins from a specific initialization point. The maximum expected reward is slightly lower than the cooperation reward of 1. Although this is a challenging case, what would results look like for different initialization points? Can a learning-aware agent achieve better outcomes (with an expected reward greater than 1)?
- Figure 3B and 3C: Does the proposed method require interaction with naive agents to initiate training?
- Why is there no comparison between COALA and M-FOS in Figure 5?

Minors:

- Why are all references in blue font? This formatting seems differ from other submissions.
- In Lines 14, 33, 49, 106, 122, 161, 185, 478, and 479, the single quotation marks should be replaced with double quotation marks.

Meta-review: The reviewers acknowledged that the paper studies an interesting problem of cooperation among self-interested learning agents in multi-agent systems,  and the proposed method of learning-aware policy gradients is novel with significant contributions. However, the reviewers also raised several concerns and questions in their initial reviews. We want to thank the authors for their responses and active engagement during the discussion phase. The reviewers appreciated the responses and have an overall positive assessment of the paper for acceptance. The reviewers have provided detailed feedback, and we strongly encourage the authors to incorporate this feedback when preparing the final version of the paper.

Decision: Accept (Poster)