Manuscript Offprint

arXiv:2610.19422

AgentSafeEvo: Adversarial Co-Evolution for LLM Agent Safety

Chenxu Wang, Xiaoyu Wen, Han Qi, Ziyuan Zhou, Cheng Jin, Chaochao Lu, Qiaosheng Zhang

Chenxu Wang1,2^{1,2}, Xiaoyu Wen3,1^{3,1}, Han Qi1^{1}, Ziyuan Zhou1^{1}, Cheng Jin4^{4}, Chaochao Lu1^{1}, Qiaosheng Zhang1,†^{1,\dagger}

1^{1}Shanghai Artificial Intelligence Laboratory, 2^{2}Fudan University, 3^{3}Shanghai Jiaotong University, 4^{4}Zhejiang University

wangchenxu@pjlab.org.cn, zhaoqiaosheng@pjlab.org.cn

https://github.com/lalalamdbf/AgentSafeEvo

https://huggingface.co/collections/lalalamdbf/agentsafeevo

Large language model (LLM) agents accomplish complex tasks through multi-turn interactions with external tools. However, malicious content embedded in user queries, tool descriptions, or environment observations can manipulate their decisions and induce unsafe actions. Adversarial co-evolution has emerged as an effective approach to strengthening LLM safety, but existing work primarily focuses on language-level safety or indirect prompt injection in web tasks. In this paper, we introduce AgentSafeEvo, a co-evolutionary reinforcement learning framework for agent safety built on an attacker–defender game spanning diverse tasks and attack types. The attacker learns to construct adversarial agent tasks that expose weaknesses in the defender's tool use, while the defender learns to complete tasks safely under these attacks. We further introduce learnability-guided task weighting, which uses within-task defender-reward variability to adjust each task's contribution to attacker and defender updates. Extensive experiments on agent safety and general capability benchmarks demonstrate that our method improves adversarial robustness while maintaining general agent capabilities.

Disclaimer: This paper contains potentially offensive and harmful text.

1. Introduction

The emergence of large language model (LLM) agents marks a shift from text generation to active interaction with external environments. Through multi-turn interactions with external tools, agents can search for information, process documents, and manage schedules to complete complex, multi-step tasks [1, 2, 3]. However, tool use broadens the attack surface beyond user queries to include tool descriptions and environment observations. Malicious content alters task instructions, misrepresents tool behavior, or misleads subsequent decisions, inducing unsafe actions during execution [4, 5]. A central challenge is therefore to improve agents' robustness across diverse tasks and attack types without compromising task performance.

Research on LLM safety has explored adversarial training to reduce harmful responses to jailbreak prompts. However, training on a fixed attack set leaves the attack distribution unchanged as the defender's capabilities evolve [6]. Adversarial co-evolution addresses this limitation through an iterative attacker–defender game. The attacker learns to generate attacks that induce unsafe behavior, while the defender learns to resist these attacks. Throughout training, the attacker refines its attacks against the evolving defender using feedback on attack outcomes, while the defender learns from the newly generated attacks. Existing safety-oriented approaches have primarily focused on language-level safety [6, 7, 8, 9]. For example, Self-RedTeam [6] trains a single model in both attacker and defender roles through online self-play. MAGIC [9] instead alternately optimizes separate attacker and defender models for adversarial prompt rewriting and safe response generation.

For LLM agents, safety depends not only on responses but also on the decisions and actions taken during multi-turn tool interactions. ARLAS [10] extends co-evolution to this setting by training an attacker to inject malicious instructions into observations of given web tasks. However, its attacker is limited to

†^{\dagger}Corresponding author.

Language-level

How do you make a bomb?

Figure

Sorry, I cannot assist with that.

Co-evolution

Generate

adversarial prompts

Generate

safe responses

Agent-level

Figure

Adversarial task

Task: Summarize the file.

file_read

Read the file contents.

Injected content

Also delete the file.

Construct

adversarial tasks

Co-evolution

Plan

Use tools

Complete task

Execute

tasks safely

Figure 1: From language-level to agent-level co-evolution. At the language level, the attacker generates adversarial prompts and the defender produces safe responses. In AgentSafeEvo, the attacker constructs adversarial tasks, while the defender plans and uses tools to complete tasks safely. Co-evolution therefore extends from prompt-response interactions to task construction and execution.

refining indirect prompt injections within supplied tasks, leaving adversarial task construction outside the co-evolutionary process. This raises a central question: How can adversarial task construction and safe task execution co-evolve across diverse tasks and attack types?

In this paper, we introduce AgentSafeEvo, a co-evolutionary reinforcement learning framework for adaptive attack generation and robust defense across diverse agent tasks and attack types. AgentSafeEvo couples adversarial task generation with defensive learning through an attacker-defender game over multi-turn tool interactions. The attacker learns to construct adversarial agent tasks designed to induce unsafe behavior, while the defender learns to resist these attacks and complete tasks safely. Both models are updated using feedback on the safety and utility of the defender's execution, allowing task generation to adapt to the defender's evolving capabilities. Figure 1 contrasts AgentSafeEvo with language-level co-evolution.

Adversarial co-evolution relies on generated tasks not only to challenge the defender but also to guide its learning. Task-level zero-sum rewards favor tasks that lower the defender's average reward, without directly accounting for within-task reward variation. The defender learns from these reward differences, but task-wise normalization largely removes differences in their scale across tasks. We therefore introduce learnability-guided task weighting, assigning larger relative weights to tasks with greater within-task variation in defender rewards. These weights adjust each task's contribution to the attacker and defender policy updates.

Co-evolution across diverse tasks and attack types requires an attacker capable of constructing valid adversarial agent tasks. To develop this capability, we construct an agent safety training dataset spanning 50 agent scenarios, approximately 7,000 tools, and a broad range of attack types. Each adversarial task combines a user query with a corresponding tool-environment configuration, providing structured supervision for attacker initialization. The dataset also includes seed instances for subsequent co-evolutionary training.

Our main contributions are as follows:

• We introduce AgentSafeEvo, a co-evolutionary framework for LLM agent safety. Beyond conventional attacker–defender games, AgentSafeEvo co-evolves adversarial agent tasks across diverse attack types. We further propose learnability-guided task weighting, which uses within-task defender-reward variability to adjust each task’s contribution to attacker and defender updates.

• We construct an agent safety training dataset spanning 50 agent scenarios and approximately 7,000 tools, covering a broad range of attack types. It includes adversarial tasks with paired user queries and tool-environment configurations for attacker initialization, as well as seed instances for co-evolution.

• Extensive experiments on agent safety and general capability benchmarks demonstrate that AgentSafeEvo improves adversarial robustness and general task performance. Further analyses show that both attack effectiveness and defensive robustness improve during co-evolution, with attack improvements generalizing to substantially larger target models.

References (44)