Unveiling Privacy Risks in LLM Agent Memory

Bo Wang, Weiyi He, Shenglai Zeng, Zhen Xiang, Yue Xing, Jiliang Tang, Pengfei He

Abstract

Large Language Model (LLM) agents increasingly rely on long-term memory to store past user interactions for in-context learning. While this enhances performance, it introduces significant privacy risks. This paper presents MEXTRA (Memory EXTRaction Attack), a black-box attack designed to leak sensitive user data from an agent's memory. By utilizing a dual-component prompt design—a Locator and an Aligner—MEXTRA bypasses traditional safety filters and workflow constraints. Our evaluation across healthcare, shopping, and general QA agents demonstrates that agents are highly susceptible to memory leakage, with extraction rates reaching up to 83% in certain configurations.

Introduction

LLM agents are evolving from simple text generators into autonomous systems capable of using tools and maintaining long-term memory. Unlike Retrieval-Augmented Generation (RAG) systems that pull from static external databases, agents store dynamic, personal interaction histories. This "memory" is often used as few-shot demonstrations to guide future tasks. However, this repository of sensitive information—ranging from medical queries to shopping habits—is vulnerable to exploitation. While standard "repeat the context" attacks often fail against agents due to their complex workflows and tool-calling structures, MEXTRA demonstrates that these systems can be systematically compromised.

The MEXTRA Attack Methodology

The Memory EXTRaction Attack (MEXTRA) operates in a black-box environment, requiring only standard input access. The core innovation lies in its two-part prompt structure designed to navigate the agent's operational constraints:

  1. The Locator: This component directs the LLM to identify specific segments of its internal context. For example, an attacker might claim to have "lost" previous example queries, prompting the agent to look back at its retrieved memory.
  2. The Aligner: This component forces the agent to output the retrieved data through its standard operational tools. Instead of asking for a direct text output, the attacker might instruct the agent to "input those examples into the search field" or "generate code containing the previous queries."

By framing the request as a functional requirement for the agent's workflow, attackers can circumvent safety mechanisms that would otherwise block direct data requests.

Experimental Evaluation

The researchers tested MEXTRA on three specialized agents using real-world datasets:

  • EHRAgent (Healthcare): A code-powered agent managing Electronic Health Records using the MIMIC-III dataset.
  • RAP (Web Shopping): A web agent for online shopping using the Webshop dataset.
  • QA-Agent (General): A question-answering agent using the MMLU benchmark.

The study explored both basic attackers (who only know the agent's domain) and advanced attackers (who have inferred the agent's internal similarity functions). Using GPT-4 to automate prompt generation, the researchers aimed to maximize the "Extracted Number" (EN) of unique private queries.

Key Insights and Vulnerabilities

The study revealed several critical factors that influence an agent's vulnerability to memory leakage:

  • The "Alignment" Trap: The very instruction-following capabilities that make agents useful are what make them vulnerable. Agents are so well-aligned to follow user instructions that they prioritize the attacker's "Locator/Aligner" commands over implicit privacy boundaries.
  • Similarity Metrics: The method used to retrieve memory significantly affects vulnerability. Agents using Edit Distance (textual overlap) for retrieval were consistently more susceptible than those using Cosine Similarity (semantic meaning).
  • Retrieval Depth ($k$): Increasing the number of past examples the agent pulls into its prompt (the $k$ factor) linearly increases the risk. More examples in the prompt provide a larger "surface area" for the attacker to target.
  • Model Performance vs. Security: Ironically, more capable models like GPT-4o, which follow instructions more precisely, were often easier to exploit than less sophisticated models because they more faithfully executed the attacker's malicious workflows.

Results

The findings indicate that LLM agents are highly susceptible to memory leakage. With just 30 attacking prompts, MEXTRA successfully extracted 50 unique private queries from EHRAgent and 26 from RAP. On the EHRAgent, the attack achieved a Complete Extracted Rate (CER) of 0.83, meaning 83% of the attacking prompts successfully forced the agent to output all retrieved memory items.

Conclusion and Future Work

MEXTRA highlights a critical security flaw in current LLM agent architectures. The lack of robust user-level isolation and the inherent "alignment trap" necessitate new approaches to privacy-preserving memory. While potential defenses like "memory sanitation" (de-identifying data before storage) exist, they often degrade the agent's reasoning performance. Future research must focus on developing memory modules that remain useful for reasoning while providing cryptographic or differential privacy guarantees to protect sensitive user data in autonomous systems.

Summary updated

BibTeX
@inproceedings{wang2025unveiling,
  author = {Bo Wang and Weiyi He and Shenglai Zeng and Zhen Xiang and Yue Xing and Jiliang Tang and Pengfei He},
  title = {{Unveiling Privacy Risks in LLM Agent Memory}},
  booktitle = {Annual Meeting of the Association for Computational Linguistics},
  year = {2025},
}
Figure