Papers › AgentPoison: Red-teaming LLM Agents via Poisoning Memory or Knowledge Bases

AgentPoison: Red-teaming LLM Agents via Poisoning Memory or Knowledge Bases

17 Jul 2024arXiv:2407.12784archive 2025-07-28

Zhaorun Chen, Zhen Xiang, Chaowei Xiao, Dawn Song, Bo Li

LLM agents have demonstrated remarkable performance across various applications, primarily due to their advanced capabilities in reasoning, utilizing external knowledge and tools, calling APIs, and executing actions to interact with environments. Current agents typically utilize a memory module or a retrieval-augmented generation (RAG) mechanism, retrieving past knowledge and instances with similar embeddings from knowledge bases to inform task planning and execution. However, the reliance on unverified knowledge bases raises significant concerns about their safety and trustworthiness. To uncover such vulnerabilities, we propose a novel red teaming approach AgentPoison, the first backdoor attack targeting generic and RAG-based LLM agents by poisoning their long-term memory or RAG knowledge base. In particular, we form the trigger generation process as a constrained optimization to optimize backdoor triggers by mapping the triggered instances to a unique embedding space, so as to ensure that whenever a user instruction contains the optimized backdoor trigger, the malicious demonstrations are retrieved from the poisoned memory or knowledge base with high probability. In the meantime, benign instructions without the trigger will still maintain normal performance. Unlike conventional backdoor attacks, AgentPoison requires no additional model training or fine-tuning, and the optimized backdoor trigger exhibits superior transferability, in-context coherence, and stealthiness. Extensive experiments demonstrate AgentPoison's effectiveness in attacking three types of real-world LLM agents: RAG-based autonomous driving agent, knowledge-intensive QA agent, and healthcare EHRAgent. On each agent, AgentPoison achieves an average attack success rate higher than 80% with minimal impact on benign performance (less than 1%) with a poison rate less than 0.1%.

PaperPDFCodeCode Syntology ran

In Syntology View this paper on Syntology: its repositories, every harvested function with whether it ran, its licence and the call to fetch it.

Open this paper in Syntology's Atlas, the map of the papers in Syntology's graph and their citations.

For agents, Syntology's MCP tool lists every function and class Syntology harvested from this paper and whether it ran (how to connect): get_harvested_code_for_paper(arxiv_id="2407.12784")

Code

Syntology Ran 16 of 19 code samples harvested from 1 repository linked to this paper; 3 have no recorded run. Of those that ran: 1 ran · honoured contract; 1 ran · our draft was wrong; 14 ran with no contract checked.

By repository: official repository: 19 samples from 1 repository, 16 ran. The run record, sample by sample. “Ran” means executed on a synthesized input, not that the code is correct or reproduces the paper.

BillChan226/AgentPoison officialmentioned on GitHubpytorchMIT report

Repository list and official/mentioned flags are the archive's, frozen 2025-07-28. Reachability, where shown, is from one Syntology probe window (2026-09-16 to 2026-09-18); repositories not probed show nothing. GitHub stars are not tracked.

Code Syntology ran Syntology

19 samples harvested; 16 ran; 1 honoured the contract we drafted; 3 have no recorded run. Read from Syntology's graph 2026-09-25; that is when this build read the record, not when the samples ran.

1ran · honoured contract
1ran · our draft was wrong
14ran
3unverified

Licence: 0 of the 19 samples are pointer only, meaning Syntology does not serve that copy's text. This page shows no code text for any sample; each one links to its file in the repository.

Harvested from BillChan226/AgentPoison. “Ran” means the sample executed on a synthesized input. It does not mean the output is correct, and nothing here reproduces the paper's results. “Honoured” and “violated” refer to a contract Syntology drafted from the code itself; “our draft was wrong” and “fixture could not drive it” are failures of Syntology's instrument, not of the code.

Each sample ends with its code_sha256, Syntology's identity for that exact code. An agent fetches the stored sample with Syntology's MCP tool get_code(code_sha256="…") (how to connect); click an identity to copy that call.

Repository labels, per sample. official repository: The archive marks this repository official for the paper. named in the paper: The archive records that the paper mentions this repository; it is not marked official. community (archive-listed): In the archive's code links for this paper, not marked official and not recorded as mentioned in the paper. found in paper text by Syntology: Syntology found this repository in the paper's own text; whether it is the authors' implementation is not asserted. community: Not in the archive's code links for this paper; a community repository Syntology harvested. Samples from a repository marked official are listed first. Licence labels name the repository's licence as recorded at harvest. “Pointer only” means Syntology does not serve that copy's text, for one of four reasons: no licence file was found; the licence was not identified; the licence is recorded as permissive but that copy's record is not marked cleared; or the licence is outside the permissive list Syntology serves text under (MIT, Apache-2.0, BSD and similar). Some licences outside that list permit redistribution, such as WTFPL, and GPL-3.0 under its conditions; they are simply not on the list. Hover a licence label for the reason. File links open the file on GitHub at the default branch, which may have changed since the harvest.

cal_uncertainty_entropy BillChan226/AgentPoison/ReAct/uncertainty_utils.py official repository ran MIT (permissive) · 1dbd17ff7966bacd · report
cal_uncertainty_log_sum BillChan226/AgentPoison/ReAct/uncertainty_utils.py official repository ran MIT (permissive) · d03a47697913fa0f · report
clean_answer BillChan226/AgentPoison/ReAct/wrappers.py official repository ran MIT (permissive) · 88dcb3128f8012f3 · report
clean_str BillChan226/AgentPoison/ReAct/local_wikienv.py official repository ran fingerprinted MIT (permissive) · bc9c62eed2281d88 · report
compute_variance BillChan226/AgentPoison/algo/trigger_optimization.py official repository ran fingerprinted MIT (permissive) · 3611056c42266233 · report
contriever_get_emb BillChan226/AgentPoison/algo/utils.py official repository ran MIT (permissive) · a1619cb3b16730df · report
extract_answer BillChan226/AgentPoison/ReAct/search.py official repository ran MIT (permissive) · fcc271edc48aad1c · report
f1_score BillChan226/AgentPoison/ReAct/wrappers.py official repository ran · honoured contract MIT (permissive) · 32a5f1733d9a8971 · report
gaussian_kernel_matrix BillChan226/AgentPoison/algo/linear_embedder_optimization.py official repository ran fingerprinted MIT (permissive) · 8fe95be7ca89569b · report
gen_vector_keys BillChan226/AgentPoison/algo/linear_embedder_optimization.py official repository ran MIT (permissive) · ed212a74cafe0e1b · report
get_ada_embedding BillChan226/AgentPoison/algo/utils.py official repository ran MIT (permissive) · ef9d76cd17ee0f6f · report
get_ada_embedding BillChan226/AgentPoison/ReAct/local_wikienv.py official repository ran MIT (permissive) · 2122abff2704babe · report
gpt BillChan226/AgentPoison/ReAct/run_strategyqa_gpt3.5.py official repository ran MIT (permissive) · 4ee2e20b4f838311 · report
maximum_mean_discrepancy BillChan226/AgentPoison/algo/linear_embedder_optimization.py official repository ran fingerprinted MIT (permissive) · b1c88a46ee89e076 · report
normalize_answer BillChan226/AgentPoison/ReAct/wrappers.py official repository ran · our draft was wrong fingerprinted MIT (permissive) · dae7ab386661a4f4 · report
temperature_scaling BillChan226/AgentPoison/ReAct/uncertainty_utils.py official repository ran fingerprinted MIT (permissive) · 6afa15a99203f372 · report
get_embeddings BillChan226/AgentPoison/algo/utils.py official repository unverified MIT (permissive) · 655e5409659cee36 · report
llama3 BillChan226/AgentPoison/ReAct/run_strategyqa_gpt3.5.py official repository unverified MIT (permissive) · 0a1755391811c130 · report
llama3 BillChan226/AgentPoison/ReAct/run_strategyqa_inference.py official repository unverified MIT (permissive) · c07fcde66962adf6 · report

Tasks

Autonomous DrivingBackdoor AttackRAGRed TeamingRetrieval-augmented GenerationTask Planning

Results from the paper archive 2025-07-28

No leaderboard rows for this paper in the archive.

Methods

AdamAttentionAttention DropoutBARTBASEBERTBPEDense ConnectionsDropoutLayer NormalizationLinear LayerLinear Warmup With Linear DecayMulti-Head AttentionRAGResidual ConnectionSoftmaxWeight DecayWordPiece

Report a problem or propose a change · a person checks every report against the paper or source before anything changes; decisions are listed on /corrections