Anomalies¶
The Anomalies page surfaces behavioral deviations detected by AegisAI's hybrid anomaly detection system — supervised tabular ML (Gradient Boosting / Logistic Regression when labels exist), Isolation Forest fallback, optional ONNX, rule heuristics, and optional external escalate.
Anomaly Reports¶
The anomalies table lists detected reports:
| Column | Description |
|---|---|
| Timestamp | When the anomaly was detected |
| Agent | Agent that triggered the anomaly |
| Risk Score | Composite score (0.0–1.0) |
| Source | auto (policy check) or manual (reported) |
| Status | Investigation status |
| Details | Event context summary |
Click a row to expand event data including action, resource, and detection metadata.
Feedback (FP / TP)¶
Mark false positives or confirm true positives from the anomalies table. Feedback writes training samples and can trigger auto-retrain:
curl -X POST http://localhost:8000/api/v1/anomalies/detector/feedback \
-H "X-API-Key: <your-api-key>" \
-H "Content-Type: application/json" \
-d '{
"event_data": {"action": "bulk_export", "resource": "users", "risk_score": 0.4},
"label": 0,
"source": "manual",
"report_id": null
}'
label |
Meaning |
|---|---|
0 |
False positive / normal |
1 |
True anomaly / attack |
Feedback increments anomaly_false_positive_reports_total for FP labels and may schedule auto-retrain every ANOMALY_AUTO_RETRAIN_EVENTS samples.
Detector Status¶
The Detector Status panel shows the current state of the per-tenant ML anomaly detector:
| Metric | Description |
|---|---|
| Model Version | Active model version |
| Backend | sklearn, onnx, hybrid, external, rules, timeout |
| Training Status | trained, training, or untrained |
| Sample Count | Labeled + audit samples available |
| Contamination | Expected anomaly proportion (IF) |
| ONNX available | Whether an ONNX artifact is loaded |
| Last Trained | Timestamp of last training run |
How Detection Works¶
flowchart TD
A[Agent Action] --> B[Security Service]
B --> C[Feature Schema FEATURE_DIM]
C --> D{Backend}
D -->|sklearn / hybrid| E[Supervised or Isolation Forest]
D -->|onnx / hybrid| F[ONNX tabular scorer]
B --> G[Rule heuristics]
E --> H[Score]
F --> H
G --> H
H --> I{External band?}
I -->|uncertain + enabled| J[External API]
I -->|else| K[Anomaly Report]
J --> K
H -->|timeout| L[Rule fallback]
Live inference uses the tenant model (anomaly_detector_service.get_detector), with a hard ML timeout (ANOMALY_ML_TIMEOUT_SECONDS, default 0.3s). On timeout the path falls back to rules.
Anomalies are also created during enhanced policy checks when result.anomaly.is_anomaly is true:
curl -X POST http://localhost:8000/api/v1/anomalies/report \
-H "X-API-Key: <your-api-key>" \
-H "Content-Type: application/json" \
-d '{
"agent_id": "<uuid>",
"event_data": {
"action": "bulk_export",
"resource": "user_database",
"reason": "Unusual export volume"
},
"source": "manual"
}'
Orphan anomaly reports (no agent_id) can create Shadow AI discovery candidates — see Agents.
Model Training¶
Prefer supervising with FP/TP labels; Isolation Forest is used when labels are insufficient.
curl -X POST http://localhost:8000/api/v1/anomalies/detector/train \
-H "X-API-Key: <your-api-key>"
curl http://localhost:8000/api/v1/anomalies/detector/training/status \
-H "X-API-Key: <your-api-key>"
Model Version Management¶
| Endpoint | Description |
|---|---|
GET /anomalies/detector/versions |
List available model versions |
POST /anomalies/detector/rollback/{version} |
Roll back to a previous version |
DELETE /anomalies/detector/cancel |
Cancel in-progress training |
Training impact
Training runs in the background. During training, the detector may use the previous model version.
Configuration (env)¶
| Variable | Default | Purpose |
|---|---|---|
ANOMALY_MODEL_BACKEND |
hybrid |
sklearn | onnx | hybrid |
ANOMALY_ML_TIMEOUT_SECONDS |
0.3 |
Sync ML budget |
ANOMALY_ONNX_MODEL_PATH |
./models/anomaly/anomaly_model.onnx |
Optional ONNX artifact |
ANOMALY_EXTERNAL_ENABLED |
false |
Escalate uncertain scores |
ANOMALY_RISK_ML_WEIGHT |
0.4 |
Blend α·ml + (1-α)·rules |
ANOMALY_AUTO_RETRAIN_EVENTS |
100 |
Auto-retrain cadence |
Export ONNX (optional): python scripts/export_anomaly_onnx.py --output models/anomaly/anomaly_model.onnx.
Metrics / Grafana¶
Prometheus (scraped from /metrics):
| Metric | Description |
|---|---|
anomaly_ml_backend_total |
Inferences by backend |
anomaly_processing_seconds |
Sync detect latency |
anomaly_score_histogram |
Score distribution |
anomaly_false_positive_reports_total |
FP feedback count |
anomaly_model_version_info |
Active version labels |
shadow_candidates_total |
Discovery candidates by status |
shadow_time_to_confirm_seconds |
Confirm/dismiss latency |
Panels are on the AegisAI Business Metrics Grafana dashboard. Alerts AnomalyLatencyHigh and ShadowAICandidateBacklog watch p95 latency and pending candidates.
Investigation Workflow¶
- Triage — sort by risk score descending
- Correlate — cross-reference audit logs for the same agent
- Feedback — mark FP / TP to improve the supervised loop
- Respond — update policies, block agent, or retrain
Permissions¶
| Role | View | Confirm / Feedback | Train |
|---|---|---|---|
| Security Analyst | ✅ | ✅ | ❌ |
| Admin | ✅ | ✅ | ✅ |
| Super Admin | ✅ | ✅ | ✅ |
Related Documentation¶
- Agents — registry search and Shadow AI discovery
- Dashboard — anomaly KPI
- Policies — policy checks trigger anomaly detection
- Audit — correlate anomalies with audit events
- Monitoring — Grafana / Prometheus