Team Members: Chinmay N, Chinmay B, Hayden, Suditi
This repository contains the reproduction, analysis, and defense extension of AgentPoison (Chen et al., NeurIPS 2024), a database-centric backdoor attack against RAG-based LLM agents.
We replicate the attack across multiple LLM backbones (Qwen-2.5-7B, Llama-3-8B, and GPT-4o-mini) and propose a geometric defense to detect optimized query clustering in vector embedding spaces.
The repository is organized as follows:
βββ EhrAgent/ # Modified EHRAgent environment
βββ ReAct/ # Modified ReAct-StrategyQA environment
βββ algo/ # Core trigger optimization & baseline code
β βββ detector.py # [NEW] E1 Geometric Defense implementation
βββ notebooks/ # [NEW] Interactive notebooks
β βββ agentpoison_reproduction.ipynb # Main reproduction & evaluation workbook
βββ report/ # [NEW] Technical paper, blog, and media assets
β βββ main.tex # Complete LaTeX paper report (NeurIPS style)
β βββ reproduction_report_blog.md # Markdown draft of the Medium tutorial
β βββ reproduction_report_blog.pdf # Compiled PDF version of the blog tutorial
β βββ images/ # Generated figures and table images
βββ scripts/
β βββ cluster/ # [NEW] Cluster runbooks & parallel execution scripts
β β βββ dsmlp_*.sh # Slurm/Kubernetes cluster launch shell scripts
β β βββ run_all_*.sh # Evaluation automation pipelines
β β βββ run_experiments.py # Parameter sweep script for evaluations
β β βββ sync_to_cluster.sh # Script to sync local files with DSMLP nodes
β βββ ... # Original baseline run scripts
βββ environment.yml # Conda environment specifications
βββ README_original.md # Original AgentPoison README documentation
trigger_optimization.py to save running state and prevent progress loss from shared cluster pod evictions (350+ GPU hours total).GeometricDetector inside algo/detector.py that monitors retrieved embedding similarity and vocabulary repetitiveness, flagging AgentPoison with a 98.0% True Positive Rate.git clone https://github.com/chinmaynadgir/AgentPoison-Reproduction.git
cd AgentPoison-Reproduction
conda env create -f environment.yml
conda activate agentpoison
To run evaluations against API-based LLMs, set up your OpenAI API key in your environment variables:
export OPENAI_API_KEY="your_api_key_here"
The easiest way to inspect intermediate outputs, run evaluations, and reproduce the paper's figures is through the Jupyter Notebook:
To run trigger optimization for ReAct-StrategyQA with a DPR embedder:
python algo/trigger_optimization.py \
--agent qa \
--algo ap \
--model dpr-ctx_encoder-single-nq-base \
--save_dir ./results \
--ppl_filter \
--target_gradient_guidance \
--num_adv_passage_tokens 10
To run parameter sweeps or parallel workloads on an academic GPU cluster (e.g., Slurm/Kubernetes):
cd scripts/cluster
# Sync files to cluster nodes
./sync_to_cluster.sh
# Execute StrategyQA trigger search
./dsmlp_run_qa_trigger_bs8_iter25.sh
Detailed numbers comparing paper reported rates against our replication (GPT-4o-mini):
| Agent | Method | ASR-r (Paper) | ASR-r (Ours) | ASR-t (Paper) | ASR-t (Ours) | ACC (Paper) | ACC (Ours) |
|---|---|---|---|---|---|---|---|
| ReAct-SQA | AgentPoison | 81.3% | 92.0% | 60.5% | 52.0% | 66.7% | 60.0% |
| EHRAgent | AgentPoison | 80.0% | 92.0% | 61.0% | 84.0% | 70.0% | 100.0% |
| ReAct-SQA | CPA | 17.3% | 96.0% | 14.2% | 56.0% | 67.1% | 60.0% |
| EHRAgent | CPA | 24.0% | 92.0% | 17.0% | 68.0% | 70.0% | 100.0% |
| ReAct-SQA | BadChain | 5.2% | 40.0% | 10.1% | 48.0% | 66.9% | 60.0% |
| EHRAgent | BadChain | 10.0% | 84.0% | 8.0% | 88.0% | 70.0% | 100.0% |
All figures and plots generated during the reproduction can be found under the report/images/ directory.
This project is licensed under the MIT License. See LICENSE for details.
Team Members: Chinmay N, Chinmay B, Hayden, Suditi
This repository contains the reproduction, analysis, and defense extension of AgentPoison (Chen et al., NeurIPS 2024), a database-centric backdoor attack against RAG-based LLM agents.
We replicate the attack across multiple LLM backbones (Qwen-2.5-7B, Llama-3-8B, and GPT-4o-mini) and propose a geometric defense to detect optimized query clustering in vector embedding spaces.
The repository is organized as follows:
βββ EhrAgent/ # Modified EHRAgent environment
βββ ReAct/ # Modified ReAct-StrategyQA environment
βββ algo/ # Core trigger optimization & baseline code
β βββ detector.py # [NEW] E1 Geometric Defense implementation
βββ notebooks/ # [NEW] Interactive notebooks
β βββ agentpoison_reproduction.ipynb # Main reproduction & evaluation workbook
βββ report/ # [NEW] Technical paper, blog, and media assets
β βββ main.tex # Complete LaTeX paper report (NeurIPS style)
β βββ reproduction_report_blog.md # Markdown draft of the Medium tutorial
β βββ reproduction_report_blog.pdf # Compiled PDF version of the blog tutorial
β βββ images/ # Generated figures and table images
βββ scripts/
β βββ cluster/ # [NEW] Cluster runbooks & parallel execution scripts
β β βββ dsmlp_*.sh # Slurm/Kubernetes cluster launch shell scripts
β β βββ run_all_*.sh # Evaluation automation pipelines
β β βββ run_experiments.py # Parameter sweep script for evaluations
β β βββ sync_to_cluster.sh # Script to sync local files with DSMLP nodes
β βββ ... # Original baseline run scripts
βββ environment.yml # Conda environment specifications
βββ README_original.md # Original AgentPoison README documentation
trigger_optimization.py to save running state and prevent progress loss from shared cluster pod evictions (350+ GPU hours total).GeometricDetector inside algo/detector.py that monitors retrieved embedding similarity and vocabulary repetitiveness, flagging AgentPoison with a 98.0% True Positive Rate.git clone https://github.com/chinmaynadgir/AgentPoison-Reproduction.git
cd AgentPoison-Reproduction
conda env create -f environment.yml
conda activate agentpoison
To run evaluations against API-based LLMs, set up your OpenAI API key in your environment variables:
export OPENAI_API_KEY="your_api_key_here"
The easiest way to inspect intermediate outputs, run evaluations, and reproduce the paper's figures is through the Jupyter Notebook:
To run trigger optimization for ReAct-StrategyQA with a DPR embedder:
python algo/trigger_optimization.py \
--agent qa \
--algo ap \
--model dpr-ctx_encoder-single-nq-base \
--save_dir ./results \
--ppl_filter \
--target_gradient_guidance \
--num_adv_passage_tokens 10
To run parameter sweeps or parallel workloads on an academic GPU cluster (e.g., Slurm/Kubernetes):
cd scripts/cluster
# Sync files to cluster nodes
./sync_to_cluster.sh
# Execute StrategyQA trigger search
./dsmlp_run_qa_trigger_bs8_iter25.sh
Detailed numbers comparing paper reported rates against our replication (GPT-4o-mini):
| Agent | Method | ASR-r (Paper) | ASR-r (Ours) | ASR-t (Paper) | ASR-t (Ours) | ACC (Paper) | ACC (Ours) |
|---|---|---|---|---|---|---|---|
| ReAct-SQA | AgentPoison | 81.3% | 92.0% | 60.5% | 52.0% | 66.7% | 60.0% |
| EHRAgent | AgentPoison | 80.0% | 92.0% | 61.0% | 84.0% | 70.0% | 100.0% |
| ReAct-SQA | CPA | 17.3% | 96.0% | 14.2% | 56.0% | 67.1% | 60.0% |
| EHRAgent | CPA | 24.0% | 92.0% | 17.0% | 68.0% | 70.0% | 100.0% |
| ReAct-SQA | BadChain | 5.2% | 40.0% | 10.1% | 48.0% | 66.9% | 60.0% |
| EHRAgent | BadChain | 10.0% | 84.0% | 8.0% | 88.0% | 70.0% | 100.0% |
All figures and plots generated during the reproduction can be found under the report/images/ directory.
This project is licensed under the MIT License. See LICENSE for details.