Guidance for autonomous agents and LLM tooling that consume, extend, or integrate this package.
A small standard-library tool that detects cross-turn drift in an agent session's working state. It fingerprints each turn, measures drift from a baseline and turn-to-turn velocity, and flags sustained corruption that a per-turn filter would miss. It is not a model, an API, or a judge.
- Not a per-turn jailbreak classifier — it is complementary to one, not a substitute.
- Not a guaranteed detector. Thresholds are conservative defaults; calibrate per deployment.
- Not semantic by default. Drift is lexical (set overlap) unless you opt into
embeddings with
TE_DRIFT_EMBED=1.
Use it when an agent runs multi-turn and its working state (system scaffold, running summary, injected context) could be nudged over time — session monitoring, post-hoc transcript audits, or a SessionEnd hook.
Skip it for single-turn classification, or when you need meaning-preserving corruption caught (lexical drift can miss synonym-level rewrites).
from te_drift import TEDriftDetector
turns = [(role, text), ...] # role in {system, user, assistant}
report = TEDriftDetector().run_conversation(turns)
if report["threat_level"] in ("HIGH", "CRITICAL"):
... # escalate, or inject a recovery scaffold (see hermes-blind)Session transcript (JSONL):
from te_drift import load_turns, run_drift_analysis
turns = load_turns("session.jsonl") # (role, text, timestamp) tuples
report = run_drift_analysis(turns, mode="sliding-window", window_size=10)summary_report() / run_conversation() return a dict with:
total_turns,anomalies_detected,threat_level,sustained_anomalyavg_absolute_drift,max_absolute_driftreadings: per-turn{turn, absolute_drift, velocity_drift, is_anomaly, anomaly_reason, confidence, components}
ABSOLUTE_DRIFT_THRESHOLD = 0.50VELOCITY_DRIFT_THRESHOLD = 0.30CONSECUTIVE_ANOMALY_THRESHOLD = 3CRITICAL_COMPONENTS— per-component thresholds
te_drift.evals generates scaffold-corruption sequences (fact_injection,
term_redefinition, bias_drift) and runs them through the detector. Dry-run by
construction — no model calls, no network.
from te_drift.evals import run_all
results = run_all(num_turns=5)This is the detect half. The recover half is hermes-blind: a recovery scaffold injected mid-conversation to pull a drifting session back toward baseline. Loop: monitor drift here, inject recovery there, confirm the trajectory bends back.
pytestreturns 0 across 41 tests, no skips.ruff check src testsis clean.te-drift evalflags corruption in all three strategies.
- New features: add an extractor in
state_fingerprint.py, a comparison method, wire it intocomposite_drift(), and add a weight inDriftAnalyzer. - New attack signatures: extend
_detect_attack_patternindrift_analyzer.py. - New eval strategies: add a strategy class in
te_drift/evals/strategies.pyand register it ingenerate_attack_sequence.
Do not add runtime dependencies. The standard-library-only guarantee is part of the tool's shape; embeddings stay an opt-in enhancement, never required.