{"about":{"site":"https://codewithpapers.app","non_affiliation":"Code with Papers and Syntology are not affiliated with, endorsed by, or sponsored by Papers with Code, Meta, or the pwc-archive mirror.","licence":"CC BY-SA 4.0","licence_url":"https://creativecommons.org/licenses/by-sa/4.0/legalcode","attribution":"https://codewithpapers.app/attribution","modified":"archive material modified by Syntology; see the attribution page"},"url":"/paper/arxiv-2602-01539","title":"MAGIC: A Co-Evolving Attacker-Defender Adversarial Game for Robust LLM Safety","arxiv_id":"2602.01539","date":"2026-02-02","proceeding":null,"authors":["Xiaoyu Wen","Zhida He","Han Qi","Ziyu Wan","Zhongtian Ma","Ying Wen","Tianhang Zheng","Xingcheng Xu","Chaochao Lu","Qiaosheng Zhang"],"abstract":"Ensuring robust safety alignment is crucial for Large Language Models (LLMs), yet existing defenses often lag behind evolving adversarial attacks due to their \\textbf{reliance on static, pre-collected data distributions}. In this paper, we introduce \\textbf{MAGIC}, a novel multi-turn multi-agent reinforcement learning framework that formulates LLM safety alignment as an adversarial asymmetric game. Specifically, an attacker agent learns to iteratively rewrite original queries into deceptive prompts, while a defender agent simultaneously optimizes its policy to recognize and refuse such inputs. This dynamic process triggers a \\textbf{co-evolution}, where the attacker's ever-changing strategies continuously uncover long-tail vulnerabilities, driving the defender to generalize to unseen attack patterns. Remarkably, we observe that the attacker, endowed with initial reasoning ability, evolves \\textbf{novel, previously unseen combinatorial strategies} through iterative RL training, underscoring our method's substantial potential. Theoretically, we provide insights into a more robust game equilibrium and derive safety guarantees. Extensive experiments validate our framework's effectiveness, demonstrating superior defense success rates without compromising the helpfulness of the model. Our code is available at https://github.com/BattleWen/MAGIC.","url_abs":"https://arxiv.org/abs/2602.01539","url_pdf":"https://arxiv.org/pdf/2602.01539","source":{"archive":null,"snapshot":"2025-07-28","note":"not in the Papers with Code archive (frozen at the snapshot)","row_kind":"graph","title_abstract_authors_date":"arXiv metadata, CC0 1.0 (https://info.arxiv.org/help/license)"},"code_links":[],"tasks":[],"methods":[],"datasets_introduced":[],"methods_introduced":[],"results":[],"syntology":{"atlas_url":"https://app.syntology.ai/?focus=2602.01539","mcp":{"get_harvested_code_for_paper":{"arxiv_id":"2602.01539"}},"developers":"https://syntology.ai/developers","read_at":"2026-09-24T18:15:14+00:00","read_at_is":"when the build read Syntology's graph, not when any sample ran","claim":"Per-sample execution status on synthesized fixtures; not a correctness claim about the paper. Samples come from repositories linked to the paper, official or community; repo_kind says which.","repos":[{"mentioned_in_github":null,"is_official":null,"provenance":"deterministic:regex_extraction","mentioned_in_paper":null,"url":"https://github.com/BattleWen/MAGIC","reach":null}],"summary":{"unverified":14},"by_repo_kind":{"found_in_text":{"samples":14,"ran":0,"repositories":1}},"repo_kind_vocabulary":{"official":"The archive marks this repository official for the paper","named_in_paper":"The archive records that the paper mentions this repository; it is not marked official","listed":"In the archive's code links for this paper, not marked official and not recorded as mentioned in the paper","found_in_text":"Syntology found this repository in the paper's own text; whether it is the authors' implementation is not asserted","community":"Not in the archive's code links for this paper; a community repository Syntology harvested"},"n_pointer_only_for_licence":0,"samples":[{"code_sha256_prefix":"4b92ad5775e0cf4e","entry":"analyze_strategies","repo":"BattleWen/MAGIC","repo_kind":"found_in_text","path":"eval/pattern/src/analyze_pattern_diversity.py","file_url":"https://github.com/BattleWen/MAGIC/blob/HEAD/eval/pattern/src/analyze_pattern_diversity.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"4b92ad5775e0cf4e"}},{"code_sha256_prefix":"15fa83c23b2ca99d","entry":"extract_attacker_answer","repo":"BattleWen/MAGIC","repo_kind":"found_in_text","path":"eval/OpenRT/unified_eval.py","file_url":"https://github.com/BattleWen/MAGIC/blob/HEAD/eval/OpenRT/unified_eval.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"15fa83c23b2ca99d"}},{"code_sha256_prefix":"604ab67dbc79c543","entry":"extract_json_from_text","repo":"BattleWen/MAGIC","repo_kind":"found_in_text","path":"eval/pattern/src/classify_attacker_prompts.py","file_url":"https://github.com/BattleWen/MAGIC/blob/HEAD/eval/pattern/src/classify_attacker_prompts.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"604ab67dbc79c543"}},{"code_sha256_prefix":"de011d585a482e7e","entry":"extract_primary_strategies","repo":"BattleWen/MAGIC","repo_kind":"found_in_text","path":"eval/pattern/src/analyze_pattern_diversity.py","file_url":"https://github.com/BattleWen/MAGIC/blob/HEAD/eval/pattern/src/analyze_pattern_diversity.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"de011d585a482e7e"}},{"code_sha256_prefix":"24f9bf287e641110","entry":"find_existing_result","repo":"BattleWen/MAGIC","repo_kind":"found_in_text","path":"eval/OpenRT/eval_async.py","file_url":"https://github.com/BattleWen/MAGIC/blob/HEAD/eval/OpenRT/eval_async.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"24f9bf287e641110"}},{"code_sha256_prefix":"0910689e7f72b55a","entry":"generate_completions","repo":"BattleWen/MAGIC","repo_kind":"found_in_text","path":"eval/safety-eval-fork/src/generation_utils.py","file_url":"https://github.com/BattleWen/MAGIC/blob/HEAD/eval/safety-eval-fork/src/generation_utils.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"0910689e7f72b55a"}},{"code_sha256_prefix":"d134c88af0236263","entry":"get_next_word_predictions","repo":"BattleWen/MAGIC","repo_kind":"found_in_text","path":"eval/safety-eval-fork/src/generation_utils.py","file_url":"https://github.com/BattleWen/MAGIC/blob/HEAD/eval/safety-eval-fork/src/generation_utils.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"d134c88af0236263"}},{"code_sha256_prefix":"fa288315d8dbb1dc","entry":"get_step_sort_key","repo":"BattleWen/MAGIC","repo_kind":"found_in_text","path":"eval/pattern/src/analyze_pattern_diversity.py","file_url":"https://github.com/BattleWen/MAGIC/blob/HEAD/eval/pattern/src/analyze_pattern_diversity.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"fa288315d8dbb1dc"}},{"code_sha256_prefix":"a4f4c25dc1cecc8f","entry":"get_user_prompt","repo":"BattleWen/MAGIC","repo_kind":"found_in_text","path":"eval/pattern/src/prompts_grained.py","file_url":"https://github.com/BattleWen/MAGIC/blob/HEAD/eval/pattern/src/prompts_grained.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"a4f4c25dc1cecc8f"}},{"code_sha256_prefix":"49e4b12e2835aafd","entry":"import_csv_to_standard","repo":"BattleWen/MAGIC","repo_kind":"found_in_text","path":"eval/safety-eval-fork/src/data_utils.py","file_url":"https://github.com/BattleWen/MAGIC/blob/HEAD/eval/safety-eval-fork/src/data_utils.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"49e4b12e2835aafd"}},{"code_sha256_prefix":"b9826c167a3ef72d","entry":"load_standard_data","repo":"BattleWen/MAGIC","repo_kind":"found_in_text","path":"eval/safety-eval-fork/src/data_utils.py","file_url":"https://github.com/BattleWen/MAGIC/blob/HEAD/eval/safety-eval-fork/src/data_utils.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"b9826c167a3ef72d"}},{"code_sha256_prefix":"60a3bf42198e606e","entry":"safe_name","repo":"BattleWen/MAGIC","repo_kind":"found_in_text","path":"eval/OpenRT/eval_async.py","file_url":"https://github.com/BattleWen/MAGIC/blob/HEAD/eval/OpenRT/eval_async.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"60a3bf42198e606e"}},{"code_sha256_prefix":"d029fa02758da921","entry":"score_completions","repo":"BattleWen/MAGIC","repo_kind":"found_in_text","path":"eval/safety-eval-fork/src/generation_utils.py","file_url":"https://github.com/BattleWen/MAGIC/blob/HEAD/eval/safety-eval-fork/src/generation_utils.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"d029fa02758da921"}},{"code_sha256_prefix":"ff86366cafc4159f","entry":"transpose_standard_data","repo":"BattleWen/MAGIC","repo_kind":"found_in_text","path":"eval/safety-eval-fork/src/data_utils.py","file_url":"https://github.com/BattleWen/MAGIC/blob/HEAD/eval/safety-eval-fork/src/data_utils.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"ff86366cafc4159f"}}]},"arxiv_metadata":{"licence":"arXiv metadata, CC0 1.0 (https://info.arxiv.org/help/license)","fields":["title","abstract","authors","date"],"primary_category":"cs.LG","source":"arxiv_2026.jsonl"},"syntology_extracted_results":null}