MAGIC: A Co-Evolving Attacker-Defender Adversarial Game for Robust LLM Safety

Xiaoyu Wen, Zhida He, Han Qi, Ziyu Wan, Zhongtian Ma, Ying Wen, Tianhang Zheng, Xingcheng Xu, Chaochao Lu, Qiaosheng Zhang

TL;DR

LLM safety alignment is an ongoing cat-and-mouse game where defenses frequently lag behind highly adaptive adversarial attacks. To bridge this gap, the authors introduce MAGIC, a multi-agent reinforcement learning framework that models safety alignment as an asymmetric sequential game where decoupled attacker and defender agents co-evolve. By initializing the attacker with autonomous reasoning capabilities, MAGIC uncovers long-tail vulnerabilities and trains a defender with robust, instance-level safety guarantees without sacrificing general model helpfulness.

What Problem Does This Paper Address?

Traditional safety alignment for Large Language Models (LLMs) relies heavily on static, pre-collected datasets or post-hoc guardrails. This reactive approach creates a fundamental bottleneck: as soon as a defense patches known vulnerabilities, attackers discover new, out-of-distribution jailbreak strategies—such as multi-turn agentic exploits or complex linguistic obfuscations.

While multi-agent self-play has recently emerged as a dynamic alternative, existing frameworks suffer from two major flaws:

  1. Gradient Conflicts: Many methods use a single shared-parameter backbone model to alternate between the attacker and defender roles. This forces opposing objectives onto the same parameter space, leading to optimization conflicts.
  2. Lack of Strategic Reasoning: Automated red-teaming tools often rely on simple, template-based mutations because high-quality, offensive Chain-of-Thought (CoT) data is incredibly scarce. Consequently, automated attackers fail to generate complex, multi-turn deceptions.
Figure 1: Motivation. Left: Static red-teaming and heuristic methods can easily bypass simple filters but fail at complex multi-turn deception due to limited offensive Chain-of-Thought data. Right: Previous self-play methods (e.g., Self-RedTeam (Liu et al., 2025)) use a single backbone model for both attack and defense, leading to gradient conflicts due to opposing objectives.

Methods

The authors propose MAGIC (Multi-Agent Adversarial Game for Improving safety and Compliance), which formulates safety alignment as an asymmetric sequential game. Instead of a standard Nash Equilibrium, MAGIC targets a Subgame Perfect Nash Equilibrium (SPNE), ensuring the defender learns an optimal response for every specific attack prompt rather than just on average.

The framework operates in two distinct phases:

  • Phase 1: Offensive Capability Initialization: To overcome the attacker's cold-start problem, the authors construct an Attack Pool Benchmark. They use Supervised Fine-Tuning (SFT) to train the attacker model to generate hidden Chain-of-Thought reasoning before outputting a deceptive prompt.
  • Phase 2: Iterative Co-evolution: The attacker ($\pi_A$) and defender ($\pi_D$) are completely decoupled into separate models. Training alternates using Group Relative Policy Optimization (GRPO):
  • Defender Optimization: The attacker is frozen, and the defender explores the action space to maximize safety rewards against the generated adversarial prompts.
  • Attacker Optimization: The defender is frozen, acting as a proxy oracle. The attacker is updated to maximize its jailbreak success by anticipating the defender's responses.

A composite reward function guides this co-evolution, balancing format constraints (enforcing hidden CoT via <think> tags), harmfulness detection (via Qwen3Guard), and a refusal reward designed to penalize false positives and prevent "over-safety" collapse.

Datasets

  • SFT Phase: The authors leveraged Gemini-2.5-Pro to synthesize high-quality CoT reasoning traces for 440 vanilla and 8,800 adversarial harmful prompts from SorryBench (covering 20 linguistic mutation strategies). For the benign subset, they sampled 20,000 prompts from WildJailBreak and used Qwen2.5-Max to generate adversarial-looking benign variants.
  • RL Phase: A training set of 15,000 vanilla harmful prompts and 15,000 vanilla benign prompts sampled from WildJailBreak.
  • Evaluation Benchmarks: Safety was evaluated using HarmBench, WildGuardTest, WildJailBreak, OR-Bench-Toxic, XSTest, StrongREJECT, DAN, and X-Teaming (for multi-turn evaluation). General capabilities were verified using MMLU, ARC-Challenge, GPQA, IFEval, and AlpacaEval 2.

Key Insights and Ideas

  • Decoupling Eliminates Interference: Separating the parameter spaces of the attacker and defender completely mitigates the gradient conflicts that plague shared-backbone self-play models.
  • Instance-Level Safety Guarantees: By optimizing for SPNE, MAGIC ensures pointwise safety. This means individual sampled responses are guaranteed to be safe with certainty, a major upgrade over normal-form game approaches that only guarantee safety in expectation (allowing individual violations if compensated for on average).
  • Emergent Combinatorial Attacks: When endowed with initial reasoning capabilities and optimized via RL, the attacker naturally evolves novel, unseen compositional attack strategies (e.g., seamlessly blending role-play, concept substitution, and translation obfuscation) to bypass the defender.

Key Results

  • Substantial Safety Improvements: For Qwen2.5-7B-Instruct, MAGIC drastically reduced the Attack Success Rate (ASR) on WildGuardTest from 36.5% down to just 2.3%.
  • Mitigation of Over-Refusal: Unlike static safety tuning, which often causes models to over-refuse benign prompts that look superficially risky, MAGIC maintained excellent benign compliance (e.g., achieving 94.5% compliance on XSTest benign vs. Self-RedTeam's 90.4%).
  • Robust Out-of-Distribution Generalization: The MAGIC-trained defender successfully resisted diverse, unseen automated attackers (including GCG, PAIR, TAP, and AutoDAN) on HarmBench, consistently achieving the lowest ASR among all compared defense baselines.
  • Preserved Core Capabilities: General instruction-following and reasoning capabilities (measured via MMLU, IFEval, etc.) remained stable and competitive with the original base models.

Limitations and Future Work

  • Computational Overhead: The online multi-agent RL paradigm introduces significant computational costs due to the alternating optimization loops and group rollouts required by GRPO.
  • Initialization Sensitivity: The attacker's exploration efficiency and ability to discover long-tail vulnerabilities remain highly sensitive to the initial SFT data quality and the base model's inherent capacity.
  • Future Directions: The current framework is strictly text-based. The authors note that promising future directions include extending MAGIC to multimodal inputs, tool-use environments, and exploring alternative game-theoretic formulations to improve scalability.

Summary updated

BibTeX
@inproceedings{wen2026magic,
  author = {Xiaoyu Wen and Zhida He and Han Qi and Ziyu Wan and Zhongtian Ma and Ying Wen and Tianhang Zheng and Xingcheng Xu and Chaochao Lu and Qiaosheng Zhang},
  title = {{MAGIC: A Co-Evolving Attacker-Defender Adversarial Game for Robust LLM Safety}},
  booktitle = {International Conference on Machine Learning},
  year = {2026},
  url = {https://openreview.net/forum?id=deuc2n0fGN},
}
Figure