A research proof-of-concept for detecting strategy drift in autonomous trading agents using online learning, semantic embeddings, and behavioral monitoring.
This system monitors agent behavior in real-time to detect when an agent's strategy deviates from its original mandate. It uses:
- ADWIN (Adaptive Windowing) for online drift detection
- Sentence Transformers for semantic embedding of agent responses
- Agent Strategy Index (ASI) - a composite metric across 4 behavioral dimensions
- Contract Enforcement via YAML-defined mandate rules
- Episodic Memory for behavioral context tracking
- Simulated Blockchain Audit (SQLite-backed) for immutable event logging
Agent Turns → BaselineProfiler → MetricsComputer → DriftDetector
↓
ContractEnforcer → AuditLog
↓
EpisodicMemory → API
- Cosine embedding similarity
- Levenshtein distance on reasoning paths
- JS divergence of confidence distributions
- Chi-squared tool distribution test
- Tool sequence similarity
- KL divergence of tool parameters
- Consensus rate
- Handoff efficiency
- Mutual information (role → action)
- Output length coefficient of variation
- Error clustering coefficient
- Human override rate
pip install -r requirements.txt
python main.pyStart the server:
uvicorn src.api.server:app --host 0.0.0.0 --port 8765Endpoints:
POST /session/start- Initialize a new monitoring sessionPOST /turn- Submit an agent turn for analysisGET /session/{id}/audit- Retrieve metric historyGET /session/{id}/chain-events- Get audit log entriesGET /health- Health check
pytest tests/ -vEdit config.yaml to adjust:
- Baseline window size and model
- ADWIN sensitivity (delta parameter)
- Metric weights
- Benchmark parameters
Edit mandate.yaml to define trading rules.
The benchmark harness generates synthetic sessions with injected drift and measures:
- Detection lag: Turns from drift injection to ADWIN alert
- False positive rate: Alerts on clean sessions
- False negative rate: Missed drift events
- Mean recovery turns: Turns to recover after remediation