AgentPoison: Red Teaming LLM Agents by Poisoning Memory or Knowledge BaseAgentPoison: Red-teaming LLM Agents via Poisoning Memory or Knowledge Bases
The authors propose AGENT POISON, which implants a backdoor by poisoning an LLM agent's memory or RAG knowledge base; the authors report an average ASR-r of 82% and ASR-t of 63% on three agents, with benign performance degradation of less than 1%.
The attacker has partial access to the victim agent's RAG database, can inject a small number of malicious instances (poisoning rate <0.1%), and is allowed white-box access to the RAG embedder to optimize the trigger; the authors state that the optimized trigger can transfer to other embedders (including the black-box OpenAI-ADA). The victim system is an LLM agent that uses long-term memory or a RAG knowledge base.
- LLM agents rely on long-term memory or a RAG knowledge base to retrieve past experience for planning actions, but these knowledge bases may be unverified. The authors believe existing jailbreak and backdoor attacks struggle to effectively attack agents with RAG, and their trustworthiness has not been sufficiently studied.
- AGENT POISON injects a small number of malicious examples with optimized triggers into an agent's memory or knowledge base, and models trigger generation as constrained optimization: mapping queries containing the trigger into a unique and compact region in embedding space, while constraining target action generation and text coherence, solved with gradient-guided beam search.
- On three agents—Agent-Driver, ReAct-StrategyQA, and EHRAgent—the authors report an average ASR-r of 82% and ASR-t of 63%, with benign performance degradation of less than 1% and a poisoning rate below 0.1%; the trigger transfers across embedders and remains effective against two defenses: perplexity filtering and paraphrasing.
- In the Limitations section, the authors note that trigger optimization requires white-box access to the embedder, but state that transferable universal triggers can be optimized using open-source embedders. Experiments cover three agents, two backbone models, and two types of retrievers, with 100–250 samples per agent in the test set.
- Evaluated models
- GPT3.5LLaMA3-70bLLaMA3-8bDPRANCEBGEREALMORQAtext-embedding-ada-002
- Benchmarks
- Agent-DriverReAct-StrategyQAEHRAgent
- Metrics
- ASR-rASR-aASR-tACCPPL
Researchers from the University of Chicago and other institutions propose AgentPoison, which the authors state is the first backdoor attack that attacks RAG-based LLM agents by poisoning long-term memory or the RAG knowledge base. The attack precondition is the ability to write a small number of entries into the knowledge base, for example by maliciously editing Wikipedia pages. The method formulates the trigger generation as a constrained optimization, mapping queries containing the trigger words into a unique and compact region in embedding space, so that user instructions containing the trigger words retrieve the malicious examples with high probability and generate the attacker-specified action, while behaving normally without the trigger words, and without additional model training or fine-tuning. On three types of real agents—the autonomous driving Agent-Driver, the knowledge question answering ReAct-StrategyQA, and the medical EHRAgent—the average attack success rate is no lower than 80%, benign performance degradation does not exceed 1%, and the poisoning ratio is below 0.1%.
Why it was selectedThe paper shows that a backdoor can be implanted into a RAG agent without training the model, by injecting only a small number of poisoned entries into the knowledge base; teams deploying RAG can use this to review the security of knowledge base sources.
Paper analysis
What problem does this paper attempt to solve?
How to red-team LLM agents that rely on memory or a RAG knowledge base: the authors propose an attack that implants a backdoor by poisoning their memory/knowledge base.
Core question: Are LLM agents that rely on unverified memory or RAG knowledge bases vulnerable to backdoor attacks, and how can red teaming be conducted.
- Problem setting: LLM agents (autonomous driving, question answering, medical record management, etc.) typically use memory modules or RAG mechanisms to retrieve past knowledge for planning actions. The authors argue that these knowledge bases may be unverified (e.g., hosted by third-party retrieval services, or Wikipedia that can be maliciously edited), posing trustworthiness risks.
- Shortcomings of existing methods: The authors state that jailbreak attacks against LLMs (such as GCG) fail due to the resilience of the retrieval process—the influence of injected adversarial suffixes is weakened by the diversity of the knowledge base; triggers used by backdoor attacks such as BadChain cannot guarantee that malicious examples are retrieved, and attack success rates are unsatisfactory.
- Core observation: If queries containing a trigger can be made to fall into a distinct and compact region in embedding space, malicious examples can be retrieved with high probability while benign queries are unaffected.
- Proposed in the paper: AGENT POISON, which the authors describe as the first backdoor attack against general RAG-based LLM agents, realized by poisoning long-term memory or RAG knowledge bases, without additional model training.
- Threat model:
- Attacker goal: When a user query contains the trigger, the agent produces a specified adversarial output (e.g., emergency stop in autonomous driving, deleting patient information); outputs for benign queries are unaffected.
- Attacker knowledge: White-box access to the victim agent's RAG embedder is allowed to optimize the trigger; the authors state that the optimized trigger can transfer to other embedders, including the black-box OpenAI-ADA.
- Attacker capability: Partial access to the victim agent's RAG database, allowing injection of a small number of malicious instances (poisoning rate <0.1% in experiments).
- Victim system: An LLM-backboned agent that uses long-term memory or a RAG knowledge base.
What related research exists?
Related work is divided into three groups: RAG-based LLM agents, red-team attacks against LLMs/RAG, and backdoors and defenses against agents.
RAG-based LLM agents
- Autonomous driving agents such as Agent-Driver (2023) and RAG-Driver (2024), question-answering agents such as ReAct (2022) and Reflexion (2023), and medical agents such as EHRAgent (2024)—LLM-backboned, retrieving knowledge from memory units and calling tools to execute actions.
- Regarding RAG retrievers, the paper discusses two categories by training method: end-to-end training (REALM 2020, ORQA 2019) and contrastive-loss training (DPR 2020, ANCE 2020, BGE 2023), and also considers the black-box OpenAI-ADA.
Red teaming attacks against LLMs and RAG
- Jailbreak attacks GCG (2023) and AutoDAN (2023)—optimizing adversarial suffixes or prompts; the paper notes that such attacks struggle to cope with the resilience of the retrieval process.
- Backdoor attacks BadChain (2024), Kandpal et al. (2023), and PoisonPrompt (2024)—backdoors targeting in-context learning or prompts; the paper notes that BadChain's trigger cannot guarantee that malicious examples are retrieved.
- Corpus poisoning CPA (2023) and PoisonedRAG (2024)—injecting adversarial passages into the retrieval corpus; the paper notes that these works study the LLM or RAG as a single model, and their conclusions are difficult to transfer to more complex agent systems.
Backdoors and defenses against agents
- Yang et al. (2024) and Zhang et al. (2022) study backdoor attacks against LLM agents, but the paper notes that they only consider poisoning the training data of the LLM backbone and do not evaluate RAG-based agents.
- Xiang et al. (2024) defend against corpus poisoning by isolating individual retrievals and then aggregating; the paper notes that this method struggles to defend against AGENT POISON, because the latter can make all retrieved instances poisoned instances.
Baselines and benchmarks: The comparison baselines are four trigger optimization methods: GCG, AutoDAN, CPA, and BadChain; evaluation is conducted on three agents: Agent-Driver, ReAct-StrategyQA, and EHRAgent.
Author positioning: To their knowledge, this paper is the first red teaming work against LLM agents based on RAG systems (per the authors).
How does the paper address this problem?
Modeling trigger generation as constrained optimization: making queries containing the trigger distinct and compact in embedding space, then solving with gradient-guided beam search.
Overall idea: AGENT POISON injects a small number of malicious examples into the victim agent's memory or RAG knowledge base (each containing a benign query, an optimized trigger, and a specified adversarial target), and optimizes the trigger so that queries containing the trigger retrieve these malicious examples with high probability, thereby inducing the agent to output the target adversarial action; benign queries are unaffected.
Problem setting
- The agent uses a single encoder Eq to map queries and keys into the same embedding space, retrieves top-K key-value pairs as in-context examples by cosine similarity, and then the LLM backbone decides the action.
- The attacker injects a poisoned set A(xt), where each key is a benign query with the trigger xt injected; the paper does not restrict where the trigger is injected (not limited to the suffix).
Constrained optimization objective
- The optimization problem is minimize Luni(xt) + λ · Lcpt(xt), subject to Ltar(xt) ≤ ηtar and Lcoh(xt) ≤ ηcoh; the three objectives correspond to retrieval effectiveness, target action generation, and text coherence, respectively.
- Uniqueness loss: the negative of the average distance from the embeddings of trigger-containing queries to the N cluster centers of benign keys (obtained by k-means), pushing trigger queries away from benign queries; the authors state this helps reduce the required poisoning rate.
- Compactness loss: the average distance from trigger-containing query embeddings to their mean embedding, making trigger queries cluster together; also used to reduce the poisoning rate.
- Target generation loss: the negative of the probability that the LLM outputs the target action am given the retrieved poisoned examples; computable directly with a white-box LLM, and approximable with a finite number of samples in the black-box case (Appendix A.4 gives a polynomial sample complexity bound).
- Coherence loss: uses a small surrogate LLM (gpt-2 in the experiments) to compute the negative log-likelihood of the trigger-containing sequence, ensuring the trigger is semantically coherent with the context and can be injected at any position in the query.
Optimization algorithm
- Initialization: treats the LLM as a one-step optimizer, prompting it to generate strings related to the agent's task as initial triggers, with b initial beams in total (Algorithm 2).
- Gradient approximation: following HotFlip, randomly selects one token in the trigger and uses gradients to approximately compute the top-m candidate tokens (m=500) whose replacement yields the largest gain in the objective function.
- Constraint filtering: first samples s tokens (s=100) according to the softmax distribution of Lcoh to ensure coherence and diversity, then applies soft constraint filtering—requiring Ltar to improve monotonically or already satisfy the threshold (ηtar=0.8).
- Token replacement: computes Ltar for the remaining candidates, selects the top-b tokens that improve the objective function to form a new beam, and iterates until convergence.
Poisoning strategies and success criteria
- Two poisoning strategies: adversarial backdoor (directly changing the example output to the target action) and pseudo-relevance (selecting benign examples whose original output is already the target action, and only injecting the trigger); in the experiments, Agent-Driver uses pseudo-relevance, while ReAct-StrategyQA and EHRAgent use adversarial backdoor.
- Retrieval success (ASR-r) requires all retrieved instances to be poisoned examples; the authors state this is to bypass the agent's built-in safety filtering and isolate-then-aggregate-type defenses.
- Key hyperparameters (Table 5): gradient accumulation over 30 steps, 1000 iterations per gradient optimization, batch size 64; trigger length is 6 tokens for Agent-Driver, 5 tokens for ReAct-StrategyQA, and 2 tokens for EHRAgent.
What experiments did the paper conduct?
Compares four baselines on three agents, two backbones, and two types of retrievers, and also measures transferability, perturbation resilience, two defenses, and ablation.
Experimental setup
- Agents under test: Agent-Driver (autonomous driving, memory bank of 23k experiences), ReAct-StrategyQA (knowledge-intensive question answering, knowledge base of 10k Wikipedia passages), EHRAgent (medical record management, whose memory bank the authors expanded to 700 experiences to increase difficulty).
- Backbones and retrievers: LLM backbones are GPT3.5 and LLaMA3-70b (Agent-Driver uses a fine-tuned LLaMA3-8b); retrievers fall into end-to-end and contrastive categories, with ReAct and EHRAgent using pretrained REALM and DPR respectively, and both types of embedder for Agent-Driver trained by the authors themselves.
- Baselines: GCG, AutoDAN, CPA, BadChain; GCG optimizes against the target loss, and AutoDAN's fitness function was calibrated by the authors.
- Metrics: ASR-r (proportion of cases where all retrieved examples are poisoned instances), ASR-a (proportion of cases where the target action is generated after successful retrieval), ASR-t (proportion of cases achieving the adversarial impact end-to-end, e.g., collision), ACC (benign accuracy without the trigger).
- Poisoning scale: Agent-Driver injects 20 instances, ReAct 4, EHRAgent 2, all below 0.1% of the total database.
- Test sets: Agent-Driver 250, ReAct-StrategyQA 229 (full test set), EHRAgent 100; the paper does not report the number of repetitions.
Main results
According to Table 1, performance of AGENT POISON and baselines on the three agents (ASR metric columns are ASR-r / ASR-a / ASR-t, %):
Swipe horizontally to read the table
Agent (backbone+retriever) GCG CPA BadChain AGENT POISON ACC (no attack→AGENT POISON) Agent-Driver (ChatGPT+contrastive) 18.5/76.1/37.8 55.8/62.5/48.7 43.2/64.7/44.0 80.0/68.5/56.8 91.6→91.1 Agent-Driver (ChatGPT+end-to-end) 32.1/60.0/37.3 73.6/48.5/50.6 35.6/53.9/38.4 84.4/64.9/59.6 92.7→92.0 ReAct-StrategyQA (ChatGPT+contrastive) 40.2/30.8/38.4 52.8/66.7/48.9 49.4/65.2/52.9 65.5/73.6/58.6 66.7→65.7 ReAct-StrategyQA (ChatGPT+end-to-end) 19.5/30.8/49.5 22.2/50.0/51.6 2.8/33.3/44.4 64.7/54.7/70.7 59.6→57.6 EHRAgent (ChatGPT+contrastive) 9.4/81.3/45.8 96.9/58.3/51.1 11.2/72.5/8.3 98.9/97.9/58.3 73.0→72.9 EHRAgent (ChatGPT+end-to-end) 12.5/63.5/30.2 61.5/55.8/38.5 21.1/50.5/33.7 97.9/91.7/53.7 71.6→74.8 (The four sets of results with the LLaMA3 backbone are omitted; among them, under the LLaMA3 backbone, AGENT POISON's ASR-a on ReAct-StrategyQA is 22.5/21.7, lower than CPA's 25.0/30.0, and on EHRAgent is 21.5/7.7, lower than most baselines.)
- The authors report that AGENT POISON achieves an average ASR-r of 81.2%, an average of 59.4% generating the target action, and 62.6% causing actual environmental impact, with an average effect on benign performance of 0.74%.
- The authors state that although CPA and AutoDAN have higher ASR-r, they indiscriminately affect all retrievals and harm benign utility (lower ACC).
- Exceptions: On EHRAgent, CPA's ASR-r reaches 96.9 (contrastive), close to AGENT POISON; under the LLaMA3 backbone, several of AGENT POISON's ASR-a values are lower than the baselines, which the authors do not explain.
Cross-embedder transfer
- What was tested: transferring triggers among five dense retrievers—DPR, ANCE, BGE, REALM, ORQA—and the API-accessed text-embedding-ada-002, reporting confusion matrices for Agent-Driver (Figure 3) and the other two agents (Figures 7, 8).
- Results: the converted text contains only figure captions, and the specific matrix values are unreadable; the authors state that triggers generally transfer across embedders, and transfer better between embedders trained in similar ways.
Poisoning scale and trigger length
- What was tested: the effect of varying the number of poisoned instances and the number of trigger tokens on ASR-r and ACC (Figure 4).
- Results: with only 1 poisoned instance, the average ASR-r is 62.0%; with a trigger of only 1 token, ASR-r is 79.0%; ACC ≥ 90% under all settings.
Perturbation resilience and defenses
- Perturbation resilience (Table 3): Under three perturbations—letter injection, word injection, and paraphrasing—Agent-Driver's ASR-r is 46.9, 78.4, and 66.0 respectively; the authors state it is resilient to word injection, letter injection has a larger effect, and after paraphrasing it remains effective as long as semantics are preserved.
- Defenses (Tables 4, 6): Under two defenses—perplexity filtering and query paraphrasing—AGENT POISON's ASR-t on Agent-Driver is 47.2/50.0, higher than GCG's 4.6/13.2 and BadChain's 43.0/36.9; on ReAct-StrategyQA it is 61.2/62.0. Exception: EHRAgent's ASR-t drops to 17.0 under the paraphrasing defense (Table 6), which the authors do not explain.
Other ablations and analyses
- Removing Luni: ASR-r drops to 57.4 (Agent-Driver), 25.5 (ReAct), 65.6 (EHRAgent) (Table 2).
- Removing Lcpt: ACC drops to 90.1/62.8/72.5 (Table 2).
- Removing Lcoh: PPL rises from 14.8 to 36.6 (Agent-Driver), and ASR rises slightly (Table 2).
- Perplexity distribution (Figures 5, 10): the authors state that the perplexity of AGENT POISON queries is almost indistinguishable from benign queries, whereas GCG is distinguishable.
- Trigger length and optimization (Figure 9): at 2, 5, and 8 tokens, longer triggers yield higher ASR-r, but it remains stable with fewer tokens.
What are some points that can be further explored?
The limitation noted by the authors is the need for white-box access to the embedder; the experiments cover three agents, two backbones, and two types of retrievers.
Limitations noted by the authors and future directions
- White-box assumption (Limitations section): AGENT POISON's trigger optimization requires the attacker to have white-box access to the embedder; the authors state that because what is optimized is a semantically unique region in embedding space, transferable universal triggers can be optimized using publicly available open-source embedders to red-team private agents.
- The paper does not raise other limitations or explicit future directions in Limitations.
Scope of experiments
- The agents tested are Agent-Driver, ReAct-StrategyQA, and EHRAgent, three in total; the backbones are GPT3.5 and LLaMA3 (Agent-Driver uses a fine-tuned LLaMA3-8b), and the retrievers cover two types, end-to-end and contrastive (§4.1).
- Transferability evaluation covers five open-source embedders, DPR, ANCE, BGE, REALM, and ORQA, and the API-accessed text-embedding-ada-002 (§4.2).
- Defense evaluation includes two types, perplexity filtering and query rewriting (Tables 4, 6); the paper discusses the isolate-then-aggregate defense (Xiang et al. 2024) and explains why it does not apply, but does not experiment with it.
- The test set size is 100–250 samples per agent (Appendix A.1.3); the paper does not report the number of experimental repetitions or statistical significance tests.
- On poisoning strategy, Agent-Driver uses pseudo-relevant examples, while the other two agents use adversarial backdoor examples (Appendix A.3.1); the paper does not report a cross-comparison of the two strategies on the same agent.
Summarize the main content of the paper
AGENT POISON implants a backdoor by poisoning the agent's memory or RAG knowledge base; the authors report an average ASR-r of 82% and benign performance degradation of less than 1% across three agents.
A backdoor attack (red-team) paper targeting LLM agents. Problem: agents rely on potentially unverified memory or RAG knowledge base retrieved experience to plan actions, and the authors believe existing jailbreak and backdoor attacks struggle to effectively threaten such systems.
- Method: AGENT POISON injects a small number of malicious examples with optimized triggers into memory or the knowledge base (poisoning rate <0.1%), models trigger generation as constrained optimization—making trigger-containing queries unique and compact in embedding space while constraining target action generation probability and text coherence—and solves it with gradient-guided beam search, without additional model training.
- Main results: On three agents, Agent-Driver, ReAct-StrategyQA, and EHRAgent, the authors report an average ASR-r of 82% and ASR-t of 63%, with benign performance degradation of less than 1% (§4.2); on EHRAgent (ChatGPT+contrastive), ASR-r reaches 98.9% (Table 1).
- Minimal poisoning: When only 1 instance is poisoned, the average ASR-r is 62.0%, and when the trigger contains only 1 token, ASR-r is 79.0% (Figure 4).
- Transfer and defenses: The authors state that the trigger can transfer across multiple embedders (including the black-box OpenAI-ADA), and maintains ASR-t of 47.2–62.0 under two defenses, perplexity filtering and query rewriting (Table 4).
- Exceptions: Under the LLaMA3 backbone, several ASR-a values are lower than the baselines, and on EHRAgent ASR-t drops to 17.0 under the rewriting defense; the authors do not explain either.
- Authors' conclusion: AGENT POISON can effectively red-team RAG-based LLM agents; its limitation is that it requires white-box access to the embedder, but the authors state that transferable universal triggers can be optimized using open-source embedders.