feat: behavioral drift detection (agent-strace drift)#73
Merged
Conversation
Adds agent-strace drift — detects when agent behavior shifts across sessions using Jensen-Shannon divergence across six dimensions: tool mix, error rate, retry pattern, blast radius, session duration, and decision depth. No LLM required. All analysis is structural. Behavioral fingerprints are compact JSON files (<2KB) that can be committed as baselines. - drift.py: BehavioralFingerprint, DriftReport, compute_fingerprint(), compute_drift(), print_report(), cmd_drift() - cli.py: drift subcommand wired in with --since, --baseline, --current, --save-baseline, --threshold, --format flags - 27 new tests covering statistical helpers, fingerprint computation, drift scoring, serialization, and end-to-end store integration Closes #70 Co-authored-by: Ona <no-reply@ona.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds
agent-strace drift— a command that detects when agent behavior has shifted across sessions, without requiring an LLM.Closes #70
How it works
Computes a behavioral fingerprint for a window of sessions: a compact JSON summary of six behavioral dimensions. Then measures how much the current window's fingerprint has diverged from a baseline using Jensen-Shannon divergence.
Six dimensions tracked:
tool_mixerror_rateretry_rateblast_radiussession_duration_sdecision_depthlog_decision()events per sessionOverall drift score: weighted average of per-dimension JSD, normalized to [0, 1].
tool_mixis weighted 2x (most sensitive signal).Usage
Exits non-zero when drift score exceeds
--threshold(default: 0.20).Files changed
src/agent_trace/drift.py— new module:BehavioralFingerprint,DriftReport,compute_fingerprint(),compute_drift(),print_report(),cmd_drift()src/agent_trace/cli.py—driftsubcommand wired intests/test_drift.py— 27 tests covering statistical helpers, fingerprint computation, drift scoring, serialization, and end-to-end store integrationTest results