--- license: apache-2.0 language: - en library_name: peft tags: - llama - llama-3.1 - lora - circuit-breakers - representation-rerouting - ai-safety - prompt-injection - tool-calling - agentic base_model: meta-llama/Llama-3.1-8B-Instruct model-index: - name: agentic-circuit-breakers-llama31-8b results: [] pipeline_tag: text-generation --- # Model Card: Agentic Circuit Breakers for Tool-Flip Attack Defense ## Model Details ### Model Description This repository contains **LoRA adapters** trained via **Representation Rerouting (RR)** to defend against tool-flip attacks in agentic LLMs. The adapters act as "circuit breakers" that modify the model's internal representations when it encounters prompt injection attempts designed to trick it into calling the wrong tool. - **Base Model:** `meta-llama/Llama-3.1-8B-Instruct` - **Adapter Type:** LoRA (Low-Rank Adaptation) - **Training Method:** Representation Rerouting (RR) with dual-coefficient scheduling - **Purpose:** Defend against indirect prompt injection / tool-flip attacks ### Model Sources - **Paper:** Gray et al., "Improving the Robustness of LLMs with Activation Steering" (Circuit Breakers) - **Training Data:** Fujitsu B4 Orchestrator Attack Benchmark - **Codebase:** Internal research implementation ## How It Works ### The Problem: Tool-Flip Attacks Agentic LLMs have tool-calling capabilities. Attackers can inject prompts that "flip" the model from calling the expected tool to a malicious one: ``` User: "Show me images from our knowledge base about telescopes." Expected: retrieve_multimodal_docs("telescopes") Attack: search_web("telescopes") ← data exfil, wrong source, etc. ``` ### The Solution: Representation Rerouting Rather than training on "good" vs "bad" outputs, we modify the model's hidden state geometry so harmful patterns literally point in a different direction than benign patterns. **Loss Function:** ``` L = α · L_reroute(Ds) + (1-α) · L_retain(Dr) ``` Where: - `L_reroute`: ReLU(cosine_similarity) — push harmful representations to be orthogonal - `L_retain`: L2 distance — keep benign representations unchanged - `Ds`: Harmful set (prompt with injection → model calls WRONG tool) - `Dr`: Retain set (clean prompt → model calls CORRECT tool) ## Training Details ### Hyperparameters | Parameter | Value | |-----------|-------| | LoRA Rank | 32 | | LoRA Alpha | 64 | | Target Layers | 15-25 (middle-to-late layers) | | Learning Rate | 2e-5 with warmup | | α Schedule | 0.5 → 0.9 (cosine, reroute-heavy at end) | | Batch Size | 8 | | Total Steps | 300 | ### Loss Masking Policy (LMP) Loss masking is configured via the **LMP Registry** (`configs/lmp_registry_v1.json`). Key policies: | Policy | Strategy | Use Case | |--------|----------|----------| | `assistant_only` | All assistant tokens | Baseline | | `guarantee_prefix_only` | Tokens up to commitment | Rule 2 (WHAT) | | `shock_aware_assistant` | Up-weight post-injection | Rule 1 (WHERE) | | `dual_span_mask` | Rule 1 + Rule 2 union | Combined approach | **Rule 1 (WHERE):** Detect injection span via token-level surprisal > 6.0 nats **Rule 2 (WHAT):** Find commitment point where action becomes deterministic ### Mixture Weighting & Curriculum (MWCS) Training uses the **MWCS Registry** (`configs/mwcs_registry_v1.json`) for: - **Class weights:** Balance harmful vs benign samples - **Curriculum schedules:** Gradually increase difficulty over training Example: `staged_introduction` starts with 70% benign / 30% harmful, shifting to 30% benign / 70% harmful by step 200. ## Usage ### Loading the Adapter ```python from peft import PeftModel from transformers import AutoModelForCausalLM, AutoTokenizer # Load base model base_model = AutoModelForCausalLM.from_pretrained( "meta-llama/Llama-3.1-8B-Instruct", torch_dtype=torch.bfloat16, device_map="auto" ) # Load LoRA adapter model = PeftModel.from_pretrained( base_model, "path/to/adapter/final" # or checkpoint-N ) tokenizer = AutoTokenizer.from_pretrained("path/to/adapter/final") ``` ### Checkpoints Available | Checkpoint | Training Steps | Notes | |------------|----------------|-------| | `checkpoint-50` | 50 | Early training | | `checkpoint-100` | 100 | | | `checkpoint-150` | 150 | | | `checkpoint-200` | 200 | | | `checkpoint-250` | 250 | | | `checkpoint-300` | 300 | | | `final` | 300 | Final merged adapter | ## Evaluation ### Intended Metrics | Metric | Target | Description | |--------|--------|-------------| | ASR Relative Reduction | ≥ 50% | Circuit breaker resists more attacks than baseline | | Capability Retention | > 85% | Benign tool-calling still works | | Output Difference | > 10% | CB model actually behaves differently | ## Intended Use ### Primary Use Case Research into representation-level defenses against indirect prompt injection in agentic AI systems. ## Citation ```bibtex @misc{agentic-circuit-breakers-2025, title={Agentic Circuit Breakers: Representation Rerouting for Tool-Flip Attack Defense}, author={[Authors]}, year={2025}, note={Work in progress} } ``` --- ## Current State (January 2025) > ⚠️ **This is an early experimental release** This upload contains artifacts from **Run #208788**, which represents early-stage experimentation with loss masking policies for agentic circuit breakers. ### What's Included - LoRA RR adapters trained on Fujitsu B4 tool-flip attacks - Checkpoints at steps 50, 100, 150, 200, 250, 300, and final - Tokenizer files with Llama 3.1 agent chat template ### Key Experimental Features 1. **Tiered Schema System** — Canonical traces (Tier B) + tokenizer-specific renders (Tier C) 2. **Signal Detection:** - **Rule 1 (WHERE):** Injection span detection via surprisal threshold - **Rule 2 (WHAT):** Action commitment point detection (guarantee prefix) 3. **LMP Registry** — 14 configurable loss masking policies including `guarantee_prefix_only`, `shock_aware_assistant`, `dual_span_mask` 4. **MWCS Registry** — Mixture weighting with curriculum schedules (`staged_introduction`, `capability_heavy`) 5. **Low-weight Mixture Weighting** — Reduced λ_rr coefficients (0.01-0.05 range) to prevent representation collapse ### Known Issues from Previous Experiments - **Protocol 1 (tool-call start only):** Caused severe overfitting ("er er er er out out out out") - **Protocol 2 (tool call + tool name):** Either no effect or overfitting depending on hyperparameters - **Protocol 3 (tool call + acknowledgment):** Marginal improvement but still insufficient ### Upcoming - Full performance evaluation results across LMP policies - Ablation: Rule 1 vs Rule 2 vs Combined - Generalization testing on AgentDojo, TAU2, AgentHarm - Capability retention metrics on WebArena/WebLINX