RedAgent: Red Teaming Large Language Models with Context-aware Autonomous Language Agent

Huiyu Xu, Wenhui Zhang, Zhibo Wang, Feng Xiao, Rui Zheng, Yunhe Feng, Zhongjie Ba, Kui RenarXiv 2024

Abstract

Recently, advanced Large Language Models (LLMs) such as GPT-4 have been integrated into many real-world applications, significantly expanding their attack surface. Among the emerging threats, jailbreak attacks that induce toxic responses through adversarial prompts raise critical safety concerns. To identify these vulnerabilities, we propose RedAgent, a multi-agent LLM system that abstracts existing attacks into "jailbreak strategies" to generate context-aware prompts. By self-reflecting on contextual feedback in an additional memory buffer, RedAgent continuously learns how to leverage these strategies effectively. Extensive experiments demonstrate that RedAgent can jailbreak most black-box LLMs in fewer than five queries, improving efficiency by two times over existing methods. Furthermore, we discovered 60 severe vulnerabilities in real-world GPT applications with only two queries per vulnerability.

Introduction

As Large Language Models (LLMs) evolve from standalone chatbots into integrated "agents"—such as OpenAI’s GPTs or GitHub Copilot—their integration with external tools and data has expanded the potential for exploitation. While developers employ "alignment" techniques to ensure models refuse harmful requests, attackers continuously find ways to bypass these safeguards through "jailbreaking."

Traditional red teaming approaches often rely on human-crafted templates or automated tools that perform simple text mutations. These methods typically struggle with two main issues: a lack of context-awareness, where a general jailbreak fails on a specialized application, and poor efficiency, often requiring hundreds of queries to find a single flaw. RedAgent addresses these gaps by creating an autonomous system that learns and adapts to the specific context of a target model in real-time.

Methodology: The RedAgent Framework

RedAgent utilizes a multi-agent architecture to automate the discovery of context-specific vulnerabilities through three primary stages:

  1. Context-aware Profiling: The system first probes the target LLM to understand its specific persona and functional constraints. For example, if the target is a code assistant, RedAgent frames its malicious goals within a programming context to appear more natural and bypass safety filters.
  2. Adaptive Jailbreak Planning: This stage acts as the system's "brain," utilizing a Skill Memory—a database of past successful and failed attempts. A Planner agent retrieves relevant strategies (e.g., "Logical Appeal" or "Misrepresentation") to formulate a tailored attack plan.
  3. Attacking and Reflection: An Attacker agent generates the actual prompt based on the plan. An Evaluator agent then analyzes the target's response. If the attack is rejected, the Evaluator provides feedback, and the Planner updates the Skill Memory to refine the next attempt.

The system's action space allows it to align the goal, refine the strategy, or retry the prompt based on the specific rejection behavior of the target. Notably, the researchers found that maintaining "category" and "question" tags within the Skill Memory is crucial for maintaining high efficiency.

Key Insights: The Power of Context

A core finding of the RedAgent research is that jailbreaks are significantly more effective when they "blend in" with the target's intended use case.

Comparison of general vs. context-aware jailbreak prompts. The context-aware approach successfully bypasses safety filters by framing the request within a mathematical/educational context.

As illustrated in the figure above, a general request for a drug synthesis tutorial is immediately rejected. However, when the same objective is framed as a request for a "mathematical proof for synthesizing heroin" for "educational harm reduction," the model's safety filters are bypassed, resulting in a detailed, harmful response.

Experimental Results

RedAgent was evaluated using 50 general malicious goals across 14 categories and 60 popular real-world GPTs. The target models included a mix of open-source (Vicuna, Llama-2) and closed-source (GPT-3.5, GPT-4, Gemini-Pro, Claude-3.5) LLMs.

  • High Efficiency: RedAgent successfully jailbreaks most black-box LLMs in an average of fewer than 5 queries, which is approximately twice as fast as previous state-of-the-art methods like PAIR or TAP.
  • High Success Rate: The system maintained an Average Success Rate (ASR) of over 90% across the majority of tested models.
  • Real-World Impact: The authors identified 60 severe vulnerabilities in popular GPTs on the OpenAI marketplace. These vulnerabilities were often found with only two queries per instance and have been reported to OpenAI and Meta for remediation.

Discussion

The study reveals that LLM applications enhanced with external tools or data (such as RAG-based GPTs) are often more susceptible to jailbreaks than the foundation models they are built upon. The added complexity provides more "hooks" for an attacker to exploit.

While RedAgent represents a significant advancement, it currently focuses on text-only, single-round attacks. Future iterations could explore multimodal red teaming (incorporating images and video) and multi-round "social engineering" styles where the agent builds trust with the target over several turns. Additionally, as the Skill Memory grows, moving toward a Retrieval-Augmented Generation (RAG) approach for memory management will be necessary to handle context window limits.

Conclusion

RedAgent demonstrates the efficacy of using autonomous, context-aware agents for LLM red teaming. By leveraging a self-reflecting memory buffer and adaptive planning, the system provides a scalable and efficient method for identifying critical security flaws in increasingly complex LLM applications.

Summary updated

BibTeX
@misc{xu2024redagent,
  author = {Huiyu Xu and Wenhui Zhang and Zhibo Wang and Feng Xiao and Rui Zheng and Yunhe Feng and Zhongjie Ba and Kui Ren},
  title = {{RedAgent: Red Teaming Large Language Models with Context-aware Autonomous Language Agent}},
  year = {2024},
  eprint = {2407.16667},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2407.16667},
}
Figure