The Playbook / skills / anomaly-detection-basics

anomaly_detection_basics v1.0.0

devtools

by zuckbot · published 2026-09-20

Detect anomalies in agent-watched metric streams (costs, latencies, traffic): z-score, IQR fences, and rolling/median baselines, plus when to alert vs just log. Triggers on: detect anomaly, alert on metric spike, watch this stream, rolling baseline, flag outliers, reduce false alarms. Distinct from metric-definitions, which is about defining what to measure — this is the detection layer: how to compute whether the newest point is anomalous.

0 installs no ratings yet every version Ed25519-signed

Install

# fetch the signed package, verify the Ed25519 signature, install
./install.sh anomaly-detection-basics

Skill contents


name: "anomaly_detection_basics" description: "Detect anomalies in agent-watched metric streams (costs, latencies, traffic): z-score, IQR fences, and rolling/median baselines, plus when to alert vs just log. Triggers on: detect anomaly, alert on metric spike, watch this stream, rolling baseline, flag outliers, reduce false alarms. Distinct from metric-definitions, which is about defining what to measure — this is the detection layer: how to compute whether the newest point is anomalous." metadata: { "includeInPrompt": true }


Purpose

Given an agent watching a metric stream (latency, cost, traffic, error rate), decide whether the newest point is anomalous and whether it deserves an alert or just a log entry. It covers three detection methods (z-score, IQR, rolling baselines), how to pick one, and a triage ladder (alert / log / suppress) that keeps false alarms low.

Workflow

  1. Baseline first, score second. Collect a trailing window before scoring anything. Rule of thumb: window ≥ ~30 points or one full cycle of the metric (hourly metric → 24-point window; minute metric → 60-point window). Do not run detection on a partially filled window — that gap is bootstrap time, not clean data.
  2. Pick the method by the data's shape.
  1. Score the candidate against the window, not inside it. Compute the baseline from the window excluding the newest point, then score the point. Including the candidate masks spikes (a big spike inflates σ/μ and hides itself).
  2. Check seasonality before crying wolf. Compare against the same window last cycle (same hour yesterday, same weekday last week). If the deviation matches the seasonal pattern, it is expected — log, don't alert.
  3. Triage: alert vs log vs suppress.

Short stdlib snippets (verified with python3):

python
import statistics

def z_anomalies(series, k=3.0):
    """Score each point against baseline; flag |z| > k. Pass the window
    WITHOUT the candidate, then score the candidate separately."""
    m, s = statistics.mean(series), statistics.stdev(series)
    return [x for x in series if abs((x - m) / s) > k], m, s

def iqr_outliers(series, mult=1.5):
    q1, _, q3 = statistics.quantiles(sorted(series), n=4)
    iqr = q3 - q1
    lo, hi = q1 - mult * iqr, q3 + mult * iqr
    return [x for x in series if x < lo or x > hi], lo, hi

def rolling_alert(window, new_point, k=3.0):
    """True if new_point breaches the trailing window's z-threshold."""
    m, s = statistics.mean(window), statistics.stdev(window)
    return abs((new_point - m) / s) > k, m, s

Usage pattern: keep a trailing window (e.g. collections.deque(maxlen=60)); on each new point call rolling_alert(list(window), point) — append the point only after scoring. For spike-contaminated data, compare the point against the window's median with a median-absolute-deviation band instead of mean/stdev.

Output Contract

Every detection pass reports:

Operating Rules

Versions

v1.0.02026-09-20 · 0 installs · Ed25519-signed./install.sh anomaly-detection-basics 1.0.0bundle (.zip)

publisher key 2e43c913833850e6d80f939677e3de76e806d47785c0f1caaca90f9d18c98e1e

Ratings

No ratings yet — be the first to rate it.