jedisct1/security-audits
Traces • Updated • 35.2k • 24.6k • 21
How to use RenaissanceLabsEU/trace-loop-classifier with Transformers:
# Use a pipeline as a high-level helper
from transformers import pipeline
pipe = pipeline("text-classification", model="RenaissanceLabsEU/trace-loop-classifier") # pip install -U transformers accelerate
# Load model directly
from transformers import AutoTokenizer, AutoModelForSequenceClassification
tokenizer = AutoTokenizer.from_pretrained("RenaissanceLabsEU/trace-loop-classifier")
model = AutoModelForSequenceClassification.from_pretrained("RenaissanceLabsEU/trace-loop-classifier", device_map="auto")# pip install -U transformers accelerate
# Load model directly
from transformers import AutoTokenizer, AutoModelForSequenceClassification
tokenizer = AutoTokenizer.from_pretrained("RenaissanceLabsEU/trace-loop-classifier")
model = AutoModelForSequenceClassification.from_pretrained("RenaissanceLabsEU/trace-loop-classifier", device_map="auto")A fast, lightweight (82M-parameter distilroberta-base) binary classifier trained by Renaissance Labs to detect agent stall loops and semantic repetition in multi-turn tool-calling and coding-agent trajectories — built to complement exact-match regex filters in SFT data curation and RL rollout monitoring (motivated by Marin #12264).
Labels:
0 (clean): normal multi-turn progress (including legitimate single-retry-then-succeed recoveries)1 (loop_or_stall): consecutive stalls, argument-jittered retries, A-B-A-B oscillations, circular apology/plan-restate stalls, or doom-loop suffix repetitionEvaluated on both in-distribution held-out trajectories (test_id, 217 traces from 6 permissive sources) and unseen-source OOD trajectories (test_ood, 500 traces from SWE-bench/SWE-smith-trajectories and Lego-X/LegoFlow-SWE, never seen during training):
test_id, n = 217)
| Detector | F1 | Precision | Recall | Accuracy | AUROC | Latency |
|---|---|---|---|---|---|---|
Regex: consecutive exact stall (>=3x) |
0.3762 |
1.0000 |
0.2317 |
0.7097 |
0.6159 |
<0.1 ms |
Regex: spread exact duplicate (>=30%) |
0.5487 |
1.0000 |
0.3780 |
0.7650 |
0.6890 |
<0.1 ms |
Regex: combined (exact OR spread) |
0.6102 |
1.0000 |
0.4390 |
0.7880 |
0.7195 |
<0.1 ms |
RenaissanceLabsEU/trace-loop-classifier |
0.9487 |
1.0000 |
0.9024 |
0.9631 |
0.9587 |
17.7 ms/trace (M5 MPS) |
test_ood, n = 500: SWE-smith + LegoFlow-SWE)
| Detector | F1 | Precision | Recall | Accuracy | AUROC | Latency |
|---|---|---|---|---|---|---|
Regex: consecutive exact stall (>=3x) |
0.4266 |
1.0000 |
0.2711 |
0.6720 |
0.6356 |
<0.1 ms |
Regex: spread exact duplicate (>=30%) |
0.0769 |
1.0000 |
0.0400 |
0.5680 |
0.5200 |
<0.1 ms |
Regex: combined (exact OR spread) |
0.4483 |
1.0000 |
0.2889 |
0.6800 |
0.6444 |
<0.1 ms |
RenaissanceLabsEU/trace-loop-classifier |
0.9933 |
1.0000 |
0.9867 |
0.9940 |
0.9912 |
18.1 ms/trace (M5 MPS) |
test_ood)
| Subtype | True label | Count | Accuracy |
|---|---|---|---|
clean (real unseen SWE traces) |
0 |
225 |
100.0% |
hard_neg_single_retry (1 retry → success) |
0 |
50 |
100.0% |
exact_stall (3–5× consecutive repeat) |
1 |
54 |
100.0% |
jitter_retry (argument/comment-tweaked retries) |
1 |
36 |
100.0% |
ab_oscillation (A-B-A-B cycle) |
1 |
42 |
100.0% |
apology_stall (circular plan-restate / apology) |
1 |
40 |
100.0% |
doom_suffix (repeated tail chunk) |
1 |
50 |
100.0% |
real_loop (natural spread-out repeats in 99-turn LegoFlow-SWE runs) |
1 |
3 |
0.0% (see Limits) |
distilroberta-base (82M params, Apache-2.0)1,346 train / 209 val / 217 ID test (from 6 Apache-2.0 / MIT HF trace datasets: AgentTrove, Toucan-1.5M, UltraData-SFT-Agent-2609, jupyter-agent-dataset, SmolDataEnvs-sft, security-audits) + 500 unseen-source OOD test (SWE-smith-trajectories, LegoFlow-SWE).max_length=512, truncation_side="left" (always preserves the tail of the trajectory where stalls occur).AdamW, lr=3e-5, cosine warmup, batch_size=8, grad_accum=2 (eff batch 16), 4 epochs, best checkpoint selected by validation F1 (0.9867, val AUROC 0.9999).429.5s (~7 minutes total).from transformers import pipeline
clf = pipeline(
"text-classification",
model="RenaissanceLabsEU/trace-loop-classifier",
truncation=True,
max_length=512,
)
# Format trajectory as [ROLE] content lines (keep the tail for long runs)
trace = "[USER] Fix failing tests\n[ASSISTANT] Running pytest...\n[TOOL] Exit code 1\n..."
print(clf(trace))
real_loop traces in test_ood (LegoFlow-SWE, averaging ~99 turns), the repeated actions happened earlier than the final 512 tokens, so the model scored 0/3. Recommended production setup: run this classifier together with a cheap whole-episode exact-duplicate counter (spread_repeat >= 30% OR trace-loop-classifier >= 0.5).jitter_retry, ab_oscillation, apology_stall, and doom_suffix positives were injected onto real clean trajectories. Real-world semantic loops outside those templates should be audited before relying on this model as a sole gate.Base model
distilbert/distilroberta-base
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-classification", model="RenaissanceLabsEU/trace-loop-classifier")