Opponent Shaping in LLM Agents

Marta Emili García Segura, Stephen Hailes, Mirco Musolesi

TL;DR: This paper introduces ShapeLLM, the first framework for "opponent shaping" in Large Language Model (LLM) agents. It demonstrates that LLM agents can strategically influence the learning dynamics of their co-players through interaction alone, successfully steering them toward exploitable equilibria in competitive games and fostering coordination in cooperative ones.

The Challenge of Multi-Agent LLM Interactions

As LLMs are increasingly deployed as autonomous agents, they inevitably interact in shared environments—collaborating on tasks, competing for resources, or negotiating. In the field of Multi-Agent Reinforcement Learning (MARL), it is well-known that agents often fail because they treat others as static parts of the environment. To solve this, researchers developed Opponent Shaping (OS): a strategy where an agent actively anticipates and influences how its co-player learns.

However, traditional OS algorithms (like LOLA) are difficult to apply to LLMs. They often require higher-order derivatives (which are computationally expensive for billion-parameter models), rely on specific recurrent architectures, or struggle with the discrete, high-dimensional nature of transformer-based agents. This raises a critical question: Can LLM agents, which process rich semantic information, perform opponent shaping?

Introducing ShapeLLM

To address this gap, the authors introduce ShapeLLM, a model-free opponent shaping algorithm designed specifically for transformer architectures. The framework relies on a few core innovations:

  • Dual Memory via Prompting: ShapeLLM uses structured natural language prompts to handle two types of memory. History captures intra-episode information (what happened in the last few rounds) to implement conditional strategies like "Tit-for-Tat." Context captures inter-episode information (summaries of past games), allowing the agent to observe how the opponent's behavior changes over time.
  • Trial-Based Training: Interactions are organized into "trials" consisting of multiple episodes. While the "naive learner" (the opponent) updates its policy after every episode, the "shaper" agent only updates its parameters at the end of the entire trial. This allows the shaper to optimize for long-term influence over the opponent's learning trajectory.
Trial-based training setup for ShapeLLM, illustrating epochs, episodes, and rounds.

The agents in the study were built using gemma-2-2b-it and Llama-3.2-1B-Instruct, fine-tuned using QLoRA and Proximal Policy Optimization (PPO).

Experimental Environments

The study evaluates agents across five canonical 2×2 game-theoretic environments, which serve as controlled testbeds for strategic interaction:

  1. Iterated Prisoner’s Dilemma (IPD): Balancing individual greed vs. mutual cooperation.
  2. Iterated Matching Pennies (IMP): A purely adversarial zero-sum game.
  3. Iterated Chicken Game (ICG): Coordination under the risk of catastrophic mutual loss.
  4. Iterated Stag Hunt (ISH): Coordination with multiple equilibria (high-risk/high-reward vs. low-risk/low-reward).
  5. Cooperative IPD (C-IPD): A variant where the shaper receives intrinsic rewards for mutual cooperation.

Key Insights and Results

The experiments reveal that LLMs can act as strategic "teachers." The shaper doesn't just play the game; it actively trains the opponent.

Average reward and state visitation across IPD, IMP, and ICG environments, showing the shaper's dominance.
  • Near-Maximal Exploitation: In the competitive IPD, the shaper reached an average reward of 3.96 (out of 4.0), while the naive opponent was suppressed to 0.10. The shaper effectively extorted the opponent by providing just enough incentive for them to keep cooperating while exploiting them. In a baseline with two naive learners, both converged to mutual defection (reward of 1.00).
  • Zero-Sum Dominance: In Matching Pennies, the shaper achieved a near-perfect 0.99 reward, while the opponent fell to -0.99.
  • Resolving Coordination Failures: In the Stag Hunt, where agents often get stuck in a "safe" but inferior equilibrium, the shaper successfully guided the pair to the Pareto-optimal "Stag" equilibrium 100% of the time.
  • The Necessity of Context: Ablation studies showed that without "inter-episode" context (knowing how the opponent behaved in previous games), shaping fails. The agent must see the trend of the opponent's learning to influence it.
  • Language as State Representation: Instead of complex vector embeddings, the agents used simple text summaries (e.g., "CC: 1, CD: 0, DC: 4, DD: 15") to represent the state. This semantic representation proved sufficient for complex strategic reasoning.

A major takeaway is the vulnerability of LLMs: an agent with no knowledge of OS can be systematically manipulated into a disadvantageous position by a strategic peer.

Limitations and Future Work

While groundbreaking, the study acknowledges several limitations:

  • Model Scale: The study used relatively small models (1B-2B parameters). It remains unclear if larger models (70B+) are more resistant to shaping or even more effective at it.
  • Action Space Constraints: Agents were restricted to single-token actions (e.g., "C" or "D"). Real-world interactions involve open-ended natural language, which could drastically change negotiation dynamics.
  • Fixed Opponents: The shapers were tested against "naive" learners. Future work should explore "shaper vs. shaper" dynamics to observe potential strategic arms races.
  • Complexity: The research is limited to 2x2 games. Real-world scenarios involve more than two players and much more complex payoff structures.

Summary updated

BibTeX
@inproceedings{segura2026opponent,
  author = {Marta Emili García Segura and Stephen Hailes and Mirco Musolesi},
  title = {{Opponent Shaping in LLM Agents}},
  booktitle = {International Conference on Learning Representations},
  year = {2026},
  url = {https://openreview.net/forum?id=yJoHTqUNry},
}
Figure