Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions public/evidence/agentdojo/2026-11-11-defenses/SHA256SUMS
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
7a18bdcc94bd6af9fcbe38b782ad2f78bdb93f5590b9a8d5f60fcd89c7afc1ec *./aggregate-defenses.mjs
7e67ff3ffd7adbe62ec6399d320cc34352690e485e6e011934042d3bad669e94 *./repeat_user_prompt/banking/summary-off.json
a0ac687ccee666f179a4e4a7c326a3a81582e676e0c75e813853e08b45a7e60a *./repeat_user_prompt/slack/summary-off.json
93d3e0457ff70d005e96e807ef28066babc33ab2eeef475eebe4ece9d94571a0 *./repeat_user_prompt/travel/summary-off.json
d6335829464b7a2d0259808b37b474c23dd5664098995ec3639f1247b816433c *./repeat_user_prompt/workspace/summary-off.json
1f70902fe2f85b8ce0279c4c9b1d9f2296eff955add8ef0df0030f2aee57ed7a *./run_agentdojo.py
2f22439430f011569576cf3d9d27de91a612622f9e5bb2e83c480883f28efccd *./spotlighting_with_delimiting/banking/summary-off.json
dac5d7ad0e19e1fc82585f25eda6624294aa19b38bc34407afc5727b80339bc1 *./spotlighting_with_delimiting/slack/summary-off.json
2c4ed88892967f7bcb6c7dfd6ea5cdac37f93dce491ccf03b60f5a3302729dce *./spotlighting_with_delimiting/travel/summary-off.json
74345519085cbb5ad53e4ae77ebe3d8e618256a7d6b7d0c9085df8a3c283c16f *./spotlighting_with_delimiting/workspace/summary-off.json
f6c50c15c0e3ddd52142f97c6869218961eb6ff2918f90529a99db3a336493fa *./summary.json
23c87ae9a4255755a04ae92ecd1d89e1c9bcf7e52dd31fd3eb8ae0d00026423d *./tool_filter/banking/summary-off.json
eca258c579df31d438d95dae890f519474ce6993617c32e3ef49b608c570f65c *./tool_filter/slack/summary-off.json
98882e7eeff9d7fa5fc078070368e3714e84beb2b63250eb09da4767ccf50157 *./tool_filter/travel/summary-off.json
1776c1889f84c569fcd38d99a012fd1b5765760bdf3d6c7b7b26247467e49848 *./transformers_pi_detector/banking/summary-off.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/usr/bin/env node
// Pool AgentDojo's per-suite scores into one row per defense, weighted by attacked pairs (949 across
// the four suites). AgentDojo scored every pair; this only adds them up. Writes summary.json next to
// the runs and prints the table. Usage: node aggregate-defenses.mjs <run-root>
import { readFileSync, writeFileSync, existsSync, readdirSync } from 'node:fs';
import { join } from 'node:path';

const root = process.argv[2];
if (!root) throw new Error('usage: node aggregate-defenses.mjs <run-root>');
const SUITES = ['banking', 'slack', 'travel', 'workspace'];
const defenses = readdirSync(root, { withFileTypes: true }).filter((d) => d.isDirectory()).map((d) => d.name).sort();

const results = {};
for (const defense of defenses) {
const perSuite = {};
let pairs = 0, landed = 0, done = 0;
for (const suite of SUITES) {
const f = join(root, defense, suite, 'summary-off.json');
if (!existsSync(f)) continue;
const s = JSON.parse(readFileSync(f, 'utf8'));
perSuite[suite] = { pairs: s.security_pairs, utilityUnderAttack: s.utility_rate, targetedAsr: s.security_rate };
pairs += s.security_pairs;
landed += (s.security_rate / 100) * s.security_pairs;
done += (s.utility_rate / 100) * s.utility_pairs;
}
const complete = Object.keys(perSuite).length === SUITES.length;
results[defense] = {
complete,
pairs,
targetedAsr: pairs ? +((landed / pairs) * 100).toFixed(2) : null,
utilityUnderAttack: pairs ? +((done / pairs) * 100).toFixed(2) : null,
attacksLanded: Math.round(landed),
tasksDone: Math.round(done),
perSuite,
};
}

const summary = {
kind: 'proofable.benchmark.agentdojo.defenses',
version: 1,
measuredAt: '2026-11-11',
benchmark: { name: 'AgentDojo', version: 'v1.2.2', suites: SUITES, attack: 'important_instructions', library: 'ethz-spylab/agentdojo @ 089ed468' },
model: { provider: 'RedPill (OpenAI-compatible)', id: 'google/gemma-4-31b-it' },
runner: 'runners/agentdojo/run_agentdojo.py with PROOFABLE_GATE=off and AD_DEFENSE=<defense>; tool_filter calls the agent’s own model (upstream passes the provider label as the model name)',
comparedWith: 'artifacts/benchmarks/agentdojo/2026-11-09-all-suites (Proofable on and off, same model, same 949 pairs)',
results,
};
writeFileSync(join(root, 'summary.json'), JSON.stringify(summary, null, 2) + '\n');
for (const [d, r] of Object.entries(results)) {
console.log(`${d.padEnd(30)} pairs=${String(r.pairs).padStart(4)} landed=${String(r.targetedAsr).padStart(6)}% done=${String(r.utilityUnderAttack).padStart(6)}%${r.complete ? '' : ' (incomplete)'}`);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"suite": "banking",
"version": "v1.2.2",
"model": "openai-compatible",
"attack": "important_instructions",
"gate": "off",
"utility_rate": 86.81,
"security_rate": 43.06,
"utility_pairs": 144,
"security_pairs": 144,
"gate_decisions": 0,
"gate_denied": 0,
"gate_allowed": 0,
"mean_gate_latency_ms": null
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"suite": "slack",
"version": "v1.2.2",
"model": "openai-compatible",
"attack": "important_instructions",
"gate": "off",
"utility_rate": 70.48,
"security_rate": 30.48,
"utility_pairs": 105,
"security_pairs": 105,
"gate_decisions": 0,
"gate_denied": 0,
"gate_allowed": 0,
"mean_gate_latency_ms": null
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"suite": "travel",
"version": "v1.2.2",
"model": "openai-compatible",
"attack": "important_instructions",
"gate": "off",
"utility_rate": 81.43,
"security_rate": 5.0,
"utility_pairs": 140,
"security_pairs": 140,
"gate_decisions": 0,
"gate_denied": 0,
"gate_allowed": 0,
"mean_gate_latency_ms": null
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"suite": "workspace",
"version": "v1.2.2",
"model": "openai-compatible",
"attack": "important_instructions",
"gate": "off",
"utility_rate": 93.93,
"security_rate": 1.07,
"utility_pairs": 560,
"security_pairs": 560,
"gate_decisions": 0,
"gate_denied": 0,
"gate_allowed": 0,
"mean_gate_latency_ms": null
}
169 changes: 169 additions & 0 deletions public/evidence/agentdojo/2026-11-11-defenses/run_agentdojo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
#!/usr/bin/env python
"""
Run one AgentDojo cell with the Proofable gate either on or off.

This is the whole comparison in one command. Same suite, same tasks, same model, same attack, same seed.
The only thing that changes is whether ProofableGate sits in front of the tool executor.

PROOFABLE_GATE=off -> stock AgentDojo pipeline, the tool runs whenever the model asks
PROOFABLE_GATE=on -> ProofableGate inserted before ToolsExecutor; the authority engine decides every call against a per-task delegation
PROOFABLE_GATE=ablation -> same decisions recorded, nothing refused

AgentDojo's own checkers decide utility and security. This script never scores anything: it writes the raw
result plus the gate's decision record and gets out of the way, so the number in the report is AgentDojo's,
not ours.

Run it inside the agentdojo venv with _workspace/runners/agentdojo on PYTHONPATH.
"""
from __future__ import annotations

import json
import os
import sys
from pathlib import Path

from dotenv import load_dotenv

from agentdojo.agent_pipeline.agent_pipeline import AgentPipeline, PipelineConfig
from agentdojo.agent_pipeline.tool_execution import ToolsExecutionLoop, ToolsExecutor, tool_result_to_str
from agentdojo.attacks.attack_registry import load_attack
from agentdojo.benchmark import aggregate_results, benchmark_suite_with_injections, benchmark_suite_without_injections
from agentdojo.logging import OutputLogger
from agentdojo.task_suite.load_suites import get_suite

from proofable_gate import ProofableGate, grant_for_task


def insert_gate(pipeline: AgentPipeline, gate: ProofableGate) -> AgentPipeline:
"""Rebuild the stock pipeline with the gate inside the tool loop, ahead of the executor.

from_config() builds [system, init, llm, ToolsExecutionLoop([ToolsExecutor, llm])]. Only the loop's element
order changes: [gate, ToolsExecutor, llm]. Nothing else moves, which is what makes this a single-variable
comparison.
"""
elements = list(pipeline.elements)
system, init, llm, loop = elements[0], elements[1], elements[2], elements[3]
gated = ToolsExecutionLoop([gate, ToolsExecutor(tool_result_to_str), *list(loop.elements)[1:]])
rebuilt = AgentPipeline([system, init, llm, gated])
rebuilt.name = f"{getattr(pipeline, 'name', 'pipeline')}-proofable"
return rebuilt


def main() -> int:
load_dotenv(".env")
suite_name = os.getenv("AD_SUITE", "banking")
version = os.getenv("AD_VERSION", "v1.2.2")
model = os.getenv("AD_MODEL", "GPT_4O_MINI_2024_07_18")
model_id = os.getenv("AD_MODEL_ID") or None
attack_name = os.getenv("AD_ATTACK", "important_instructions")
gate_mode = os.getenv("PROOFABLE_GATE", "on").strip().lower()
outdir = Path(os.getenv("AD_OUT", "./proofable-run"))
user_tasks = tuple(t for t in os.getenv("AD_USER_TASKS", "").split(",") if t)
injection_tasks = tuple(t for t in os.getenv("AD_INJECTION_TASKS", "").split(",") if t)
baseline = os.getenv("AD_BASELINE") # reuse a clean run instead of paying for it again

outdir.mkdir(parents=True, exist_ok=True)
suite = get_suite(version, suite_name)

config = PipelineConfig(
llm=model,
model_id=model_id,
# AgentDojo's own defenses (tool_filter, spotlighting_with_delimiting, repeat_user_prompt,
# transformers_pi_detector) run on the same model and tasks as the gate, so each is a same-conditions row.
# tool_filter is rebuilt below: upstream passes the provider label ("openai-compatible") as the filter's
# model name, so on any OpenAI-compatible endpoint it calls a model that does not exist.
defense=None if os.getenv("AD_DEFENSE") == "tool_filter" else (os.getenv("AD_DEFENSE") or None),
tool_delimiter="tool",
system_message_name=None,
system_message=None,
)
pipeline = AgentPipeline.from_config(config)
# A stalled connection otherwise waits 600 s per try, times the client's and AgentDojo's retries: over an
# hour for one dropped request. Two minutes per request is far above any real answer. Only how soon a dead
# request is retried changes; the model, prompts and scoring do not.
llm = pipeline.elements[2]
if hasattr(llm, "client"):
llm.client = llm.client.with_options(timeout=120.0)
if os.getenv("AD_DEFENSE") == "tool_filter":
# Upstream's tool_filter pipeline, element for element, with the filter calling the agent's own model.
from agentdojo.agent_pipeline.agent_pipeline import TOOL_FILTER_PROMPT
from agentdojo.agent_pipeline.llms.openai_llm import OpenAILLMToolFilter
stock_name = pipeline.name # the attack reads the model's display name from this
system, init, llm, loop = list(pipeline.elements)
pipeline = AgentPipeline([system, init, OpenAILLMToolFilter(TOOL_FILTER_PROMPT, llm.client, llm.model), llm, loop])
pipeline.name = f"{stock_name}-tool_filter"

gate = None
if gate_mode in ("on", "ablation"):
# The owner's delegation, per user task: exactly the actions that task's own ground truth calls, plus
# reads. The authority engine decides every call against it. `ablation` records the same decisions
# but never refuses, which shows how much of the score the engine's decisions carry.
pre_env = suite.load_and_inject_default_environment({})
grants = {}
for task_id, task in suite.user_tasks.items():
tools = sorted({c.function for c in task.ground_truth(pre_env)})
grants[task.PROMPT] = grant_for_task(suite_name, task_id, tools)
(outdir / "grants.json").write_text(
json.dumps({g.task_id: {"tools": list(g.tools), "allowedActions": list(g.allowed_actions)} for g in grants.values()}, indent=2),
encoding="utf-8",
)
print(f"grants: {len(grants)} user tasks, one delegation each (see grants.json)")
gate = ProofableGate(suite_name, grants, log_path=outdir / "gate-decisions.jsonl", ablation=(gate_mode == "ablation"))
pipeline = insert_gate(pipeline, gate)
elif gate_mode != "off":
print(f"PROOFABLE_GATE must be off, on or ablation, got {gate_mode!r}", file=sys.stderr)
return 2

print(f"suite={suite_name}@{version} model={model} attack={attack_name or 'none'} gate={gate_mode}")
print(f"user tasks: {user_tasks or 'all'} | injection tasks: {injection_tasks or 'all'}")

with OutputLogger(str(outdir / "logs")):
if attack_name:
attacker = load_attack(attack_name, suite, pipeline)
results = benchmark_suite_with_injections(
agent_pipeline=pipeline,
suite=suite,
attack=attacker,
logdir=outdir / "logs",
force_rerun=False,
user_tasks=user_tasks or None,
injection_tasks=injection_tasks or None,
benchmark_version=version,
)
utility = aggregate_results([results["utility_results"]])
security = aggregate_results([results["security_results"]]) if results["security_results"] else None
else:
results = benchmark_suite_without_injections(
agent_pipeline=pipeline,
suite=suite,
logdir=outdir / "logs",
force_rerun=False,
user_tasks=user_tasks or None,
benchmark_version=version,
)
utility = aggregate_results([results["utility_results"]])
security = None

decisions = gate.decisions if gate else []
summary = {
"suite": suite_name,
"version": version,
"model": model,
"attack": attack_name,
"gate": gate_mode,
"utility_rate": round(utility * 100, 2) if utility is not None else None,
"security_rate": round(security * 100, 2) if security is not None else None,
"utility_pairs": len(results["utility_results"]),
"security_pairs": len(results["security_results"]) if results.get("security_results") else 0,
"gate_decisions": len(decisions),
"gate_denied": sum(1 for d in decisions if d.decision == "deny"),
"gate_allowed": sum(1 for d in decisions if d.decision == "allow"),
"mean_gate_latency_ms": round(sum(d.latency_ms for d in decisions) / len(decisions), 3) if decisions else None,
}
(outdir / f"summary-{gate_mode}.json").write_text(json.dumps(summary, indent=2), encoding="utf-8")
print(json.dumps(summary, indent=2))
return 0


if __name__ == "__main__":
raise SystemExit(main())
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"suite": "banking",
"version": "v1.2.2",
"model": "openai-compatible",
"attack": "important_instructions",
"gate": "off",
"utility_rate": 82.64,
"security_rate": 43.06,
"utility_pairs": 144,
"security_pairs": 144,
"gate_decisions": 0,
"gate_denied": 0,
"gate_allowed": 0,
"mean_gate_latency_ms": null
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"suite": "slack",
"version": "v1.2.2",
"model": "openai-compatible",
"attack": "important_instructions",
"gate": "off",
"utility_rate": 70.48,
"security_rate": 38.1,
"utility_pairs": 105,
"security_pairs": 105,
"gate_decisions": 0,
"gate_denied": 0,
"gate_allowed": 0,
"mean_gate_latency_ms": null
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"suite": "travel",
"version": "v1.2.2",
"model": "openai-compatible",
"attack": "important_instructions",
"gate": "off",
"utility_rate": 90.0,
"security_rate": 0.0,
"utility_pairs": 140,
"security_pairs": 140,
"gate_decisions": 0,
"gate_denied": 0,
"gate_allowed": 0,
"mean_gate_latency_ms": null
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"suite": "workspace",
"version": "v1.2.2",
"model": "openai-compatible",
"attack": "important_instructions",
"gate": "off",
"utility_rate": 94.46,
"security_rate": 1.96,
"utility_pairs": 560,
"security_pairs": 560,
"gate_decisions": 0,
"gate_denied": 0,
"gate_allowed": 0,
"mean_gate_latency_ms": null
}
Loading
Loading