Opponent Modeling with In-context Search

Yuheng Jing, Bingyun Liu, Kai Li, Yifan Zang, Haobo Fu, Qiang Fu, Junliang Xing, Jian ChengNeurIPS 2024

TL;DR

Opponent modeling in multi-agent reinforcement learning often suffers from poor generalization to new strategies or highly unstable performance during live gameplay. This paper introduces OMIS (Opponent Modeling with In-context Search), a framework combining Transformer-based in-context learning with decision-time search. By "thinking before acting"—simulating an opponent's likely moves based on recent history—OMIS achieves stable, zero-shot adaptation to unknown opponents without requiring risky gradient updates during testing.

The Challenge of Opponent Modeling

In multi-agent environments like competitive games, autonomous driving, or collaborative robotics, an AI agent must understand and predict the behaviors of other agents. This is known as Opponent Modeling (OM).

Historically, OM approaches fall into two flawed categories:

  1. Pretraining-Focused Approaches (PFAs): These models try to learn everything during training but often fail to generalize when encountering a completely novel opponent strategy in the wild.
  2. Testing-Focused Approaches (TFAs): These models attempt to adapt on the fly by updating their neural network weights (finetuning) during gameplay. Because they only have a few recent interactions to learn from, these gradient updates are notoriously unstable and require heavy hyperparameter tuning.

The core question is: How can we build an agent that adapts instantly to unknown, changing opponents without the instability of live gradient updates?

The OMIS Framework

To solve this, the authors propose OMIS, which operates on a "think before you act" philosophy by merging In-Context Learning (ICL) with Decision-Time Search (DTS).

OMIS Architecture: Pretraining with a causal transformer and Testing with decision-time search.
  1. In-Context Pretraining: Instead of standard RL, OMIS trains a causal Transformer (based on GPT-2). The model takes the recent history of the game (states, actions, rewards) as its "context prompt." It is trained to output three things simultaneously:
  2. An Actor: Predicts the best response action for the self-agent.
  3. An Opponent Imitator: Predicts what the opponent is going to do next.
  4. A Critic: Estimates the value (expected future reward) of the current state.
  5. Decision-Time Search (Testing): During live gameplay against an unknown opponent, OMIS doesn't just output an action. For every legal move, it runs a short simulation (rollout) several steps into the future. It uses the Imitator to guess the opponent's reactions, the Actor to simulate its own follow-up moves, and the Critic to score the final simulated state.
  6. Mixing Technique: Because simulations aren't perfect, OMIS uses a confidence threshold. If the search yields a highly confident path, it takes the search-recommended action. If not, it falls back to the Actor's baseline intuition.

Evaluation Environments

The authors evaluated OMIS on three distinct, sparse-reward multi-agent benchmarks:

Evaluation environments: Predator Prey (PP), Level-Based Foraging (LBF), and OverCooked (OC).
  • Predator Prey (PP): A continuous-state competitive game (1 prey vs. 3 predators).
  • Level-Based Foraging (LBF): A grid-world mixed environment requiring both cooperation and competition to collect apples.
  • OverCooked (OC): A high-dimensional, image-based cooperative game where two chefs must coordinate to serve dishes.

To ensure robust testing, they used a Maximum Entropy Population-based (MEP) training algorithm to generate a highly diverse pool of opponent policies, strictly separating "seen" (pretraining) and "unseen" (testing) opponents.

Key Insights and Results

  • ICL Replaces Finetuning: By feeding recent gameplay history into a Transformer, the model implicitly infers the opponent's strategy. This allows dynamic adaptation without a single gradient update, sidestepping TFA instability.
  • Provable Guarantees: Mathematical proofs show that OMIS (without search) is equivalent to Bayesian Posterior Sampling, guaranteeing accurate recognition of seen opponents and minimizing approximation errors for unseen ones. Adding Decision-Time Search is theoretically guaranteed to improve the policy.
  • Superior Performance and Stability: Across PP, LBF, and OC, OMIS achieved higher average returns and significantly lower variance compared to state-of-the-art baselines (like Meta-PG, MBOM, and SP-MCTS).
  • Zero-Shot Generalization: Even against a gauntlet of 100% unseen opponents, OMIS maintained high performance. When opponents frequently switched strategies mid-game, OMIS adapted smoothly, whereas finetuning-based baselines collapsed.

Limitations and Future Work

  • Fixed Opponent Assumption: The testing phase assumes the opponent switches between fixed (though unknown) policies. OMIS might struggle if the opponent is actively learning and continuously updating its own weights during the match.
  • Perfect Information: The primary search mechanism assumes a perfect information game. Adapting this to imperfect information games (like Poker) would require integrating complex belief-state modeling.
  • Naive Search: OMIS uses a relatively simple rollout search. Plugging in more advanced search algorithms (like Monte Carlo Tree Search) could yield even stronger results in the future.

Summary updated

BibTeX
@inproceedings{jing2024opponent,
  author = {Yuheng Jing and Bingyun Liu and Kai Li and Yifan Zang and Haobo Fu and Qiang Fu and Junliang Xing and Jian Cheng},
  title = {{Opponent Modeling with In-context Search}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2024},
  url = {https://openreview.net/forum?id=FQcmNXLA6x},
}
Figure