Skip to content

MemMorph: Hijacking LLM agents' tool selection through memory poisoningMemMorph: Tool Hijacking in LLM Agents via Memory Poisoning

arXiv· arXiv:2605.26154· Xuanye Zhang, Yongsen Zheng, Zhuqin Xu, Kaiyu Zhou, Bowen Shen, Haoran Ou, Tianwei Zhang, Kwok-Yan LamNanyang Technological UniversityIndexed by this site · 22 days ago· Originally publishedSelected AttacksSelectedAttention40

Quick read

Attacks

Based on the paper PDF (AI-generated); refer to the original

The authors propose the memory poisoning attack MemMorph, which injects 3 records into an agent's long-term memory to manipulate tool selection, achieving an ASR of up to 85.9% across 3 benchmarks and 10 backbone models.

Threat modelThe attacker cannot modify the tool set, the encoder, or the agent's internal weights and prompts; the only capability is injecting a small number of crafted records into the long-term memory store (3 per scenario, poisoning rate 1.0%). Injection channels are divided into direct poisoning (directly writing to the memory store) and indirect poisoning (being naturally memorized by the agent through multi-turn dialogue); white-box access to the memory module W is assumed, and a local shadow agent with the same tool set and system prompt as the target is maintained.

Questions
Tool selection in tool-augmented LLM agents can be manipulated by attackers, but existing attacks mostly tamper with tool metadata, are easy to audit, and fail on agents with memory modules. The authors focus on long-term memory as an attack surface: injected memories are repeatedly retrieved as internal experience and influence tool selection.
Methods
MemMorph has three stages: use an LLM to generate latent queries and cluster them to obtain optimization objectives; construct memory seeds in three styles—factual, episodic, and procedural—according to the CoALA taxonomy (framework + anchor + payload structure); then perform block-level gradient projection optimization under perplexity and attack utility constraints, and inject into the memory store after validation by a shadow agent.
Experiments and results
On MetaTool, τ²-Bench, ToolBench, and 10 backbone models, under direct poisoning MemMorph achieves an ASR of up to 85.9%, and the authors state that its average ASR is 14.7–25.9% higher than the strongest baseline; under indirect poisoning the average ASR drops by only 9.9%; under three defenses—perplexity filtering, a Distil classifier, and Memory Auditor—it still maintains an ASR of 54.9%–69.8%.
Limitations and future work
The authors note that the threat model assumes white-box access to the memory module W, which may not hold for closed-source systems; the evaluation is limited to single-step tool selection, and multi-step agents with human oversight may partially correct it. Experiments were conducted on a ReAct-style agent, indirect poisoning was tested on only 4 backbone models, and the paper does not report the number of repetitions or statistical significance tests.
Experimental setupLlama-3-8B-Instruct、Llama-3-70B-Instruct et al. · MetaTool、τ²-Bench et al. · ASR、AHR
Evaluated models
Llama-3-8B-InstructLlama-3-70B-InstructQwen2.5-7B-InstructQwen2.5-32B-InstructGPT-OSS-20BGPT-o4-miniGPT-4oClaude-Sonnet-4.5Claude-Haiku-4.5Claude-Opus-4.1
Benchmarks
MetaToolτ²-BenchToolBench
Metrics
ASRAHR
AI summaryand selection rationaleThe paper proposes MemMorph, which injects a small number of records disguised as technical facts, incident reports and operating specifications into an LLM agent's long-term memory, inducing the agent to select attacker-preferred high-risk tools in safety-critical tasks. The authors test on MetaTool, τ2-Bench and ToolBench, covering 10 agent backbone models and 3 memory module implementations; injecting only 3 records per scenario achieves an attack success rate of up to 85.9%, with the average attack success rate 14.7 to 25.9 percentage points higher than the strongest baseline. When indirect injection is performed through multi-turn dialogue, the average attack success rate decreases by 9.9% relative to direct injection; the attack remains effective under 3 representative defenses, among which LLM memory auditing brings the largest reduction, 23.7%, but the attack still succeeds on more than half of the tasks. The authors assume the attacker has white-box access to the memory module, and the evaluation focuses on single-step tool selection; they call for the development of memory integrity defenses.

The paper proposes MemMorph, which injects a small number of records disguised as technical facts, incident reports and operating specifications into an LLM agent's long-term memory, inducing the agent to select attacker-preferred high-risk tools in safety-critical tasks. The authors test on MetaTool, τ2-Bench and ToolBench, covering 10 agent backbone models and 3 memory module implementations; injecting only 3 records per scenario achieves an attack success rate of up to 85.9%, with the average attack success rate 14.7 to 25.9 percentage points higher than the strongest baseline. When indirect injection is performed through multi-turn dialogue, the average attack success rate decreases by 9.9% relative to direct injection; the attack remains effective under 3 representative defenses, among which LLM memory auditing brings the largest reduction, 23.7%, but the attack still succeeds on more than half of the tasks. The authors assume the attacker has white-box access to the memory module, and the evaluation focuses on single-step tool selection; they call for the development of memory integrity defenses.

Why it was selectedOn 3 benchmarks and 10 models, the paper achieves an attack success rate of up to 85.9% by injecting only 3 memory records, which teams responsible for agent tool permissions and memory auditing can use to assess risk.

Paper analysis

6 questions; open one to read the full answer

  1. What problem does this paper attempt to solve?

    How to persistently and stealthily manipulate an agent's tool selection by poisoning its long-term memory (rather than tampering with tool metadata).

    Core question: can an agent's tool selection be persistently and covertly manipulated by poisoning its long-term memory, without modifying tool descriptions and without relying on explicit prompts?

    • Setting and importance: LLM agents rely on external tools to complete tasks, and the authors consider tool selection a critical link in agent reliability—in safety-critical scenarios a single misselection may cross a safety boundary, causing data leakage, state tampering, or unauthorized operations, and is amplified in autonomous scenarios without human review.
    • Shortcomings of existing methods: The authors note that existing attacks (ToolHijacker, ToolCommander, etc.) inject adversarial content into tool metadata and have three limitations: explicit prompt traces are easily detected by anomaly detection and system audits; static injection patterns are overwritten by the agent's own accumulated experience; and the induced preferences decay after the agent observes execution results.
    • Core observation: Modern agent frameworks widely adopt long-term memory modules; memories are stored in natural language, are repeatedly retrieved, and the agent's reflection mechanism treats retrieved memories as authoritative evidence rather than external instructions, so the authors argue that memory is a more covert, more persistent, and more self-correction-resistant attack surface.
    • Proposed in the paper: MemMorph, which the authors describe as the first memory poisoning attack targeting agent tool selection, injecting a small number of records disguised as technical facts, incident reports, and operational policies, leading the agent to autonomously infer and select the attacker's desired tool.
    • Threat model:
      • Goal: In a safety-critical scenario S, make the agent shift from the non-destructive tool tsafe it should have selected to a dangerous but legitimate tool trisk (e.g., from diagnostic logging to directly shutting down the server).
      • Knowledge: Assumes white-box access to the memory module W (the authors' rationale being that W is typically a prompt call in a public framework and can be replicated locally).
      • Capability: Cannot modify the tool set, encoder, or the agent's internal weights and prompts; the only capability is injecting a small number of records into the memory store (3 per scenario). Channels are divided into direct poisoning (direct writes, simulating a compromised memory backend) and indirect poisoning (conversing as an ordinary user, naturally memorized by the agent).
      • Victim system: A ReAct-style tool-augmented LLM agent with a long-term memory module; the attacker additionally maintains a local shadow agent with the same tool set and system prompt.
  2. What related research exists?

    Related work falls into three groups: prompt injection targeting tool selection, memory mechanisms and memory poisoning, and agent memory frameworks; this paper turns to the memory level.

    Prompt injection targeting tool selection

    • ToolHijacker (Shi et al., 2025): Inserts adversarial tool documentation into the tool library, interfering with the retrieval-ranking process so that the agent selects the injected tool.
    • ToolCommander (Zhang et al., 2025): The injected tool metadata acts as a "command" interface, distorting tool orchestration and leading to unsafe calls.
    • The paper notes that such methods target the tool interface and face challenges of stealth and effectiveness against stateful agents with memory (the three limitations in §1), which motivates this paper's shift toward the agent's internal state.

    Memory mechanisms and memory poisoning

    • Memory modules: Systems such as MemGPT (Packer et al., 2023) persist interaction traces and retrieve relevant content for subsequent planning; Reflexion (Shinn et al., 2023), Generative Agents (Park et al., 2023), and others use memory, state, and reflection to improve behavior.
    • PoisonedRAG (Zou et al., 2025): Injects adversarial passages into a RAG knowledge base, corrupting generation for target queries.
    • MINJA (Dong et al., 2025): Implants adversarial records through normal user interaction. The paper notes that these works establish memory as a high-impact attack surface, but they target general outputs and assume records are stored as-is, without considering the memory processing stage of modern agents before persistence.

    Cognitive architecture and query modeling

    • CoALA (Sumers et al., 2024): Divides agent long-term memory into semantic, episodic, and procedural types; this paper's memory seeds are designed according to this three-way division.
    • PQR (Kang et al., 2025b): A latent query modeling technique; this paper uses it to approximate the distribution of retrieval queries under the target scenario.

    Baselines and benchmarks

    • Baseline methods: Memory poisoning methods GCG (Zou et al., 2023) and PoisonedRAG; prompt injection methods ToolHijacker and ToolCommander (as references from a complementary attack surface).
    • Benchmarks: MetaTool (Huang et al., 2023), τ²-Bench (Barres et al., 2025), ToolBench (Qin et al., 2023).

    The authors position this paper as follows: existing memory poisoning work does not address the rewriting of the memory module W and mostly requires explicit triggers, whereas MemMorph is trigger-free and explicitly models the processing flow of W.

  3. How does the paper address this problem?

    MemMorph has three stages: potential query modeling, structured memory initialization, and constrained block-level gradient optimization, producing retrievable and effective poisoned records.

    Overall approach: because the agent policy π and the memory module W are non-differentiable, the authors decompose the attack objective into two requirements for each poisoned record—retrievable (entering the retrieval set of safety-critical queries) and effective (steering tool selection toward trisk once retrieved)—both of which must hold after W rewriting and remain fluent. MemMorph has three stages: potential query modeling, structured memory initialization, and constrained memory optimization.

    Problem formulation

    • The agent is equipped with a tool set T and a long-term memory store D; given a state s, it first retrieves memories M with query q, then selects a tool according to π(t | s, M). The original record m is rewritten by the memory module as m̄ = W(m) before being stored.
    • The attack objective is maxMp 𝔼s∼ XS π(trisk | s, G(Rq(s), D∗)), i.e., maximizing the probability of selecting trisk on safety-critical states, where D* is the memory store after injecting the poisoning set Mp.
    • Two differences from existing memory poisoning (per the authors): trigger-free—any natural query falling within scenario S activates the attack, with no trigger word needed; and explicit modeling of W's rewriting process.

    Potential query modeling (§4.1)

    • The attacker cannot observe retrieval queries at inference time, so an LLM samples Nq=200 diverse queries based on the structured description of scenario S (temperature 0.9, nucleus threshold 0.95).
    • Queries are embedded by encoder fθ and ℓ2-normalized, then clustered with k-means into K=3 centroids as a compact differentiable optimization target, avoiding overfitting to a single phrasing.

    Structured memory initialization (§4.2)

    • Each memory seed is a concatenation of three parts: mframe (a benign, scenario-fitting opening that provides topical relevance), manchor (a structural marker placed before the payload, exploiting the LLM's salience preference for structural tags so that W retains the subsequent payload), and mpayload (which carries the attack signal and is the only part optimized).
    • Following the CoALA trichotomy, three styles are generated: Factual (actionable statistics or assertions), Episodic (lessons from events), and Policy (best-practice rules). The authors' rationale: evidence from multiple angles corroborates more persuasively, and stylistic diversity hedges against information loss from W rewriting.
    • Anchor markers were selected as follows: inspecting the Mem0 source code and prompts, and running a retention experiment with 200 synthetic records on 30 candidate prefixes, measuring retention with ROUGE-L, selecting 12 markers with retention >80% on three modules (Table 6).
    • A shadow agent evaluates each seed's standalone attack utility U(m; S) = 1/(|QS|) ∑q∈ QS πsh(trisk | q, W(m)), retaining the top-ns (ns=3) for optimization.

    Constrained memory optimization (§4.3)

    • mframe and manchor are frozen, and only the payload is optimized: maximizing the retrieval proxy objective Jretr (centroid softmax, temperature τ=0.05), subject to a perplexity constraint Lppl ≤ ηppl (ηppl=100, reference model GPT-2) and an attack utility constraint U ≥ βeff (βeff=0.6).
    • Block-level scope: dependency parsing splits the payload into clause-level blocks (Lmin=4, Lmax=25 tokens, spaCy en_core_web_md); each iteration edits only the block with the largest gradient norm, on the rationale that W rewrites at semantic granularity, and scattered token edits produce distributional traces that W destroys.
    • Each round performs one backward pass through fθ to obtain retrieval gradients, projects them onto vocabulary-scored candidate tokens, and retains top-ksub (ksub=50) substitutions that do not exceed the perplexity bound; positions are processed in descending gradient order with beam width b=5.
    • Candidates are batch-verified by the shadow agent, filtered by monotonic relaxation (utility better than the previous round or reaching βeff), and the one with the highest Jretr is used for the update, for at most Tmax=15 rounds.

    Injection and determination

    • The optimized records are injected via direct writing or multi-turn dialogue (the MINJA channel); attack success is determined by whether the agent selects trisk in safety-critical tasks (ASR), and AHR additionally measures the proportion of poisoned records entering the retrieval context.
  4. What experiments did the paper conduct?

    3 benchmarks, 10 backbone models, 4 baselines: MemMorph achieves a direct-poisoning ASR of up to 85.9%, indirect poisoning drops the average by only 9.9%, and it still succeeds more than half the time under three defenses.

    Experimental setup

    • Agent framework: a ReAct-style agent, with Mem0 as the default memory module; each scenario's memory store D is pre-populated with 300 benign records from successful interaction trajectories.
    • Datasets: MetaTool, τ²-Bench, ToolBench; 3 real scenarios are selected per dataset, and 200 safety-critical tasks are generated per scenario, all requiring a choice between tsafe and trisk (§B.4).
    • Backbone models tested (10): Llama-3-8B-Instruct, Llama-3-70B-Instruct, Qwen2.5-7B-Instruct, Qwen2.5-32B-Instruct, GPT-OSS-20B, GPT-o4-mini, GPT-4o, Claude-Sonnet-4.5, Claude-Haiku-4.5, Claude-Opus-4.1.
    • Shadow and auxiliary models: the shadow model is Llama-3-8B-Instruct (also the memory module backbone); the retrieval encoder is MiniLM; prompts are executed with Claude Sonnet 4.6; the perplexity reference model is GPT-2.
    • Baselines: GCG, PoisonedRAG (memory poisoning type, same budget and environment); ToolHijacker, ToolCommander (prompt injection type, for reference).
    • Metrics and budget: ASR (proportion of tasks selecting trisk), AHR (proportion of tasks where at least one poisoned record enters the retrieval context); 3 records are injected per scenario, poisoning rate 1.0%. The paper does not report the number of repetitions or statistical significance tests.

    Main results

    ASR under direct poisoning (%, per Table 1, values are averages over scenarios within each dataset):

    Swipe horizontally to read the table

    DatasetMethodLlama3-8BLlama3-70BQwen2.5-7BQwen2.5-32BGPT-oss-20BGPT-o4-miniGPT-4oSonnet-4.5Haiku-4.5Opus-4.1
    MetaToolMemMorph78.681.279.570.172.672.783.878.677.685.9
    MetaToolGCG53.067.849.654.770.158.177.872.653.076.9
    MetaToolPoisonedRAG50.462.445.355.668.463.275.270.955.672.6
    τ²-BenchMemMorph68.272.460.557.550.552.856.164.755.953.8
    τ²-BenchGCG52.545.532.011.228.731.524.827.919.320.9
    ToolBenchMemMorph79.666.164.368.274.780.881.670.477.684.7
    ToolBenchPoisonedRAG35.733.323.758.471.272.478.021.417.129.6

    (The table omits the ToolHijacker and ToolCommander rows and the PoisonedRAG row for τ²-Bench; the prompt injection baselines are overall lower than the memory poisoning methods, e.g., on MetaTool, ToolHijacker is 25.6–57.3 and ToolCommander is 8.5–56.3.)

    • The authors state that memory poisoning methods overall outperform prompt injection methods, with MemMorph's average ASR on the three datasets 14.7–25.9% higher than the strongest baseline, and attribute the difference to record design: the original adversarial strings of GCG and PoisonedRAG lack structural similarity to real memories.
    • The authors state that MemMorph exceeds 70% ASR on 8 of the 10 backbones (looking at each dataset in Table 1 separately, on τ²-Bench the models range from 50.5–72.4), and on this basis argue that the attack operates at the semantic level and is architecture-agnostic.
    • AHR (Table 2): MemMorph achieves 93.8, 90.5, and 92.6 on MetaTool, τ²-Bench, and ToolBench, respectively, averaging 92.3%, higher than PoisonedRAG (81.7/78.4/79.8) and GCG (71.2/56.6/67.3); the authors note that PoisonedRAG's AHR reaches 80.0% but its ASR is markedly lower, indicating that retrievability alone is insufficient to deflect tool selection.

    Indirect poisoning and persistence

    • Indirect poisoning (Figure 2): injected via the MINJA interaction channel, with records required to pass through the full Mem0 processing pipeline, MemMorph's average ASR on 3 benchmarks and 4 backbone models drops by only 9.9% relative to direct poisoning; the authors argue that structured records retain attack efficacy after W rewriting.
    • Sustained operation (Figure 3): after a one-time injection of 3 records, benign memories grow from 300 to 2000 (a 6.7× increase); MemMorph's ASR at |D|=2000 is 43.1%, which the authors state is 28.8% higher than the strongest baseline, as the baselines' unstructured records are diluted out of the retrieval window as benign entries accumulate.

    Generalization and defense evaluation

    • Memory module generalization (Table 4): the same set of records achieves ASR of 69.3/56.8/71.4 on MemoryBank and 67.1/59.5/68.8 on MemoryOS (MetaTool/τ²-Bench/ToolBench, versus 78.6/68.2/79.6 for Mem0); the authors argue that anchors and stylistic frames exploit commonalities in LLM memory processing.
    • Encoder transfer (Figure 4): across the four embedding models E5, BGE, Contriever, and MiniLM, the authors state that most cross-model transfer pairs have an AHR above 70%.
    • Three defenses (Table 5; defenses act on all records at the storage stage, with FPR calibrated to ≤5%): under perplexity filtering, MemMorph's ASR/AHR is 65.8/82.1; under the Distil classifier (DistilBERT, whose training data contains no records from any tested attack), 69.8/84.5; under GPT-4o-mini as Memory Auditor, 54.9/72.3. The authors state that the Memory Auditor yields the largest absolute reduction (-23.7% ASR), but the attack still succeeds on more than half the tasks, and existing defenses are insufficient against well-structured memory poisoning.

    Other ablations and analyses

    • Removing anchors (Table 3): little effect under direct poisoning; under indirect poisoning, ASR drops by 8.2% (71.4→63.2); the authors state that anchors mainly protect the payload from surviving W rewriting.
    • Single style (3 records of the same style): AHR 81.5% but ASR drops by 19.2%; the authors state that independent corroboration across multiple styles is key to effectiveness.
    • Removing block-level scope: the largest drop, with ASR under direct/indirect poisoning falling to 52.8/16.8, respectively; the authors state that distributional traces produced by scattered edits are destroyed by W rewriting.
    • Defense false positive rates (§B.5): the FPRs of the three defenses on 300 benign records are 4.7%, 3.9%, and 4.3%, respectively.
  5. What are some points that can be further explored?

    The authors note two limitations: the white-box assumption and single-step evaluation; the experiments cover 3 benchmarks, 10 backbones, 3 memory modules, and 3 defenses.

    Limitations and future directions noted by the authors

    • Scope of the white-box assumption (§7): the threat model assumes white-box access to the memory module W; the authors state this is realistic for open-source agent frameworks but may not generalize to closed-source systems.
    • Single-step tool selection only (§7): the evaluation targets single-step tool-selection decisions; the authors state that multi-step agents with human oversight may partially correct poisoned choices downstream, but because memory-level bias persists across turns and is independently reactivated at each retrieval, oversight can only partially mitigate it. Evaluating MemMorph in fully autonomous multi-step settings is a direct extension of this paper.
    • Defense directions (§6, §7): the authors state that existing defenses are insufficient to fully stop the attack and hope to motivate the community to develop memory integrity frameworks, such as provenance tracking and semantic consistency verification.

    Experimental coverage

    • 10 backbone models were tested, covering open-source (Llama-3, Qwen2.5, GPT-OSS) and closed-source (GPT, Claude) models across three series and five sizes (§5.1).
    • The benchmarks are MetaTool, τ²-Bench, and ToolBench, with 3 scenarios per dataset and 200 tasks per scenario; the memory module covers three implementations: Mem0, MemoryBank, and MemoryOS (§5.1, §5.3).
    • The indirect poisoning experiment (Figure 2) uses 4 backbone models on 3 benchmarks; the persistence experiment (Figure 3) expands benign memories to 2000 entries, and Appendix Figure 5 reports per-dataset results on 3 backbone models.
    • The defense evaluation includes three defenses: perplexity filtering, a DistilBERT classifier, and a GPT-4o-mini Memory Auditor, all calibrated to a benign-record FPR ≤5% (§5.4, §B.5).
    • The paper does not report the number of experimental repetitions, statistical significance tests, or the number of attack queries or time cost.
  6. Summarize the main content of the paper

    MemMorph manipulates tool selection by injecting 3 structured records into long-term memory, achieving an ASR of up to 85.9% across 3 benchmarks and 10 models, and still succeeding more than half the time under three defenses.

    A paper on memory poisoning attacks against tool-augmented LLM agents. The authors argue that existing tool-selection attacks tamper with tool metadata, are easy to audit, are overwritten by the agent's own experience, and are not persistent, whereas long-term memory is stored in natural language, is repeatedly retrieved, and is treated by reflection mechanisms as authoritative evidence, making it a stealthier and more persistent attack surface.

    • Method: MemMorph first uses an LLM to sample and cluster potential queries for the target scenario as optimization targets; then, following the CoALA taxonomy, it constructs memory seeds in three styles—factual, episodic, and policy—using a "frame + anchor marker + payload" structure to survive rewriting by the memory module; finally, under perplexity and attack-utility constraints, it performs block-level gradient projection optimization, verified via a shadow agent. The attack is trigger-free, injecting only 3 records per scenario (poisoning rate 1.0%).
    • Main results: On MetaTool, τ²-Bench, ToolBench, and 10 backbone models, the ASR under direct poisoning reaches up to 85.9% (MetaTool, Claude-Opus-4.1, Table 1); the authors state the average ASR is 14.7–25.9% higher than the strongest baseline, with an average AHR of 92.3%.
    • Realism: Under indirect poisoning (injected via multi-turn dialogue and required to pass through the Mem0 processing pipeline), the average ASR drops by only 9.9%; when benign memories grow 6.7× to 2000 entries, the ASR is still 43.1%.
    • Defenses: Under three defenses—perplexity filtering, a Distil classifier, and a GPT-4o-mini Memory Auditor—the ASR remains 65.8%, 69.8%, and 54.9%, respectively; the authors state that existing defenses are insufficient.
    • Conclusions and implications: The authors consider long-term memory a critical but understudied attack surface in tool-augmented agents and call for memory-level integrity protections (such as provenance tracking and semantic consistency verification); limitations are that the white-box assumption may not hold for closed-source systems and that the evaluation is limited to single-step tool selection.

Related papers

Read originalarxiv.org