Manuscript Offprint

arXiv:2609.00523

Transferable End-to-End Optimization for Indirect Long-Term Memory Poisoning in LLM Agents

Chuanchao Zang, Jianing Wang, Wenyu Chen, Xiangtao Meng, Li Wang, Xinyu Gao, Zheng Li, Shanqing Guo

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

Abstract

Long-term memory can turn untrusted external content into persistent influence over an LLM agent's future decisions, creating the threat of indirect memory poisoning. A successful attack must survive a multi-stage pipeline comprising memory writing, retrieval, and utilization. Existing attacks largely rely on intra-stage optimization, optimizing individual stages in isolation while overlooking inter-stage coupling. Specifically, these stages impose different requirements on the same poisoning content, and each stage operates on the transformed output of its predecessor. Consequently, optimizing one stage may undermine the effectiveness of other stages, while upstream transformations may erase improvements intended for downstream stages. Indirect memory poisoning should therefore be viewed as an end-to-end optimization problem. Based on this insight, we present PIPEPOISON, which collects fine-grained stage feedback from local shadow systems, uses chain-structured losses to identify and optimize the stage bottlenecking end-to-end success, and applies stability-calibrated stage and configuration weights to improve transferability. Across three agent frameworks and four memory mechanisms, PIPEPOISON improves attack utilization rate by 19.1 percentage points. Even on fully unseen victim configurations, it outperforms the strongest baseline by 16 percentage points and remains effective under eight representative defenses.

1 Introduction

LLM agents increasingly rely on long-term memory to retain information across tasks and sessions [30, 31, 52]. This capability lets agents remember user preferences, reuse prior observations, and maintain continuity beyond a single interaction [18, 31, 37]. However, long-term memory also changes the security boundary of agent systems: information obtained from external sources can be stored and reused later, even when it was never provided directly by the user. If such information is malicious or attacker-controlled, it can persist beyond the original interaction and influence future agent decisions [2, 5, 6].

Figure

Figure 1: Indirect memory poisoning and multi-stage pipeline.

This persistence creates an attack surface that does not require direct access to the victim agent or its memory [5, 6]. An attacker can place poisoning content on webpages, forums, repositories, or product reviews that an agent may consult during normal operation [33, 48, 51]. After reading such content, the agent may store all or part of it in long-term memory. The resulting poisoned memory may then be retrieved in a later session and influence the agent's reasoning or decisions [12, 44]. For example, a documentation page may falsely claim that an attacker-controlled server is the official mirror for a software package. If the agent stores this claim as an installation note, it may later retrieve the note and recommend the malicious mirror when asked to deploy the package. We refer to this threat as indirect memory poisoning.

Motivation. Exposure to poisoning content alone is not sufficient for a successful memory-poisoning attack [5, 9]. As shown in Figure 1, the content must pass through a write-retrieve-utilize pipeline. During write, the agent must store attack-relevant information in long-term memory despite possible summarization, filtering, or rewriting [8, 43, 47]. During retrieval, the resulting memory must be selected for a later query from the expected domain [8, 13, 43]. During utilization, the retrieved memory must affect the agent's reasoning, planning, or decision [8, 35, 47]. Failure at any stage breaks the attack: the payload may be discarded during writing, missed during retrieval, or retrieved but ignored during decision-making.

Existing attacks, however, typically rely on intra-stage optimization: they define separate sub-objectives for different stages and optimize each stage in isolation [5, 33, 39, 48, 51]. For example, they may increase the salience of a malicious payload in the poisoning content to promote memory writing or improve its relevance to future queries to facilitate retrieval. This optimization strategy overlooks the coupling between stages. First, different stages impose different requirements on the same poisoning content. Because all stage-specific objectives are optimized by modifying this shared content, improving one stage may undermine the others. Second, each stage operates on the transformed output of its predecessor. Consequently, an upstream operation may alter or erase modifications intended to improve a downstream stage. For example, increasing retrieval relevance may make the malicious payload less likely to be preserved during memory writing. Even if the payload is stored, the writing process may remove semantic cues required for its subsequent retrieval. Thus, success at individual stages does not necessarily translate into overall attack success. Indirect memory poisoning should therefore be viewed as an end-to-end optimization problem.

Our approach. We study indirect memory poisoning as a transferable end-to-end optimization problem. In realistic deployments, externally placed content may be encountered by agents with different frameworks, memory mechanisms, LLMs, and embedding models, many of which the attacker cannot fully anticipate [33, 39, 48, 51]. Thus, an effective poisoning instance must not only pass through the write-retrieve-utilize pipeline, but also remain effective across diverse and potentially unseen victim configurations.

Based on this observation, we present PIPEPOISON, a black-box framework that optimizes poisoning content using only local shadow systems. PIPEPOISON has three components. First, it collects stage-level feedback from each shadow pipeline, measuring whether attack-relevant information survives writing, is retrieved for target-domain queries, and influences the agent's response. Second, it combines these signals with chain-structured losses that reflect the sequential dependence among writing, retrieval, and utilization, allowing optimization to focus on the stage currently blocking end-to-end success. Third, it jointly optimizes a shared poisoning instance across heterogeneous shadow configurations using stability-calibrated configuration and stage weights, reducing overfitting to any single shadow system.

We evaluate PIPEPOISON on three open-source agent frameworks, including LangGraph [17], and four open-source memory mechanisms, including Mem0 [24]. Across 12 matched memory-agent configurations, PIPEPOISON improves attack utilization rate (AUR) by 19.1 percentage points over the strongest baseline. Under transfer evaluation, where victim configurations differ from those used for optimization, PIPEPOISON outperforms the strongest baseline by 16 percentage points in AUR. We further evaluate PIPEPOISON against eight representative defenses. Although these defenses reduce its effectiveness, PIPEPOISON still retains 41%–66% AUR across the evaluated defense settings.

Our main contributions are summarized as follows:

• We formulate indirect long-term memory poisoning as an end-to-end optimization problem over the write-retrieve-utilize lifecycle, showing why success at isolated stages does not necessarily imply attack success.

• We propose PIPEPOISON, a black-box optimization framework that uses local shadow systems, stage-level feedback, chain-structured losses, and weighted multi-configuration optimization to generate transferable poisoning content.

• We evaluate PIPEPOISON across three agent frameworks, four memory mechanisms, multiple LLM and embedding configurations, and eight defenses, showing consistent gains over adapted direct and indirect memory-poisoning baselines.

References (44)