alert_check
Check prediction episodes against configurable thresholds to detect stability issues, ghost detections, or faults. Get triggered alerts with severity levels for immediate action.
Instructions
Check episodes against configurable thresholds and return triggered alerts — no API call, no auth, no credits. Takes an episode array from evaluate or fleet responses. Response: { status: 'ok'|'warn'|'critical', total_alerts, critical, warnings, episodes_checked, thresholds, alerts: [{ episode, type, value, threshold, severity }] }. Alert types: ci_exceeded, ema_exceeded, authority_elevated, ghost_detected, fault.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| episodes | Yes | Episode array from an evaluate or fleet response | |
| ci_threshold | No | Alert if any episode CI exceeds this (default: 0.45 = Drift boundary) | |
| ema_threshold | No | Alert if any episode EMA exceeds this (default: 0.45) | |
| al_threshold | No | Alert if any episode authority level >= this (default: 3 = Minimal) | |
| ghost_alert | No | Alert on ghost detections (default: true) | |
| fault_alert | No | Alert on faults (default: true) |
Implementation Reference
- src/index.ts:1055-1164 (handler)The alert_check tool handler function. Takes episodes and thresholds, checks each episode against configured thresholds (ci_threshold, ema_threshold, al_threshold, ghost_alert, fault_alert), and returns triggered alerts with severity levels (ok/warn/critical).
async ({ episodes, ci_threshold, ema_threshold, al_threshold, ghost_alert, fault_alert }) => { const Q = 65535; const ciThresh = ci_threshold ?? 0.45; const emaThresh = ema_threshold ?? 0.45; const alThresh = al_threshold ?? 3; const ghostOn = ghost_alert ?? true; const faultOn = fault_alert ?? true; interface Alert { episode: number; type: string; value: string; threshold: string; severity: "warn" | "critical"; } const alerts: Alert[] = []; (episodes as Array<Record<string, unknown>>).forEach((ep, i) => { const ci = ((ep.ci_out as number) || 0) / Q; const ema = ((ep.ci_ema_out as number) || 0) / Q; const al = (ep.al_out as number) || 0; if (ci > ciThresh) { alerts.push({ episode: i + 1, type: "ci_exceeded", value: `${(ci * 100).toFixed(1)}%`, threshold: `${(ciThresh * 100).toFixed(1)}%`, severity: ci > 0.70 ? "critical" : "warn", }); } if (ema > emaThresh) { alerts.push({ episode: i + 1, type: "ema_exceeded", value: `${(ema * 100).toFixed(1)}%`, threshold: `${(emaThresh * 100).toFixed(1)}%`, severity: ema > 0.70 ? "critical" : "warn", }); } if (al >= alThresh) { alerts.push({ episode: i + 1, type: "authority_elevated", value: `AL${al}`, threshold: `AL${alThresh}`, severity: al >= 4 ? "critical" : "warn", }); } if (ghostOn && ep.ghost_confirmed) { alerts.push({ episode: i + 1, type: "ghost_detected", value: `streak ${ep.ghost_suspect_streak || 0}`, threshold: "any", severity: "critical", }); } if (faultOn && ep.fault) { alerts.push({ episode: i + 1, type: "fault", value: `code ${ep.fault_code || 0}`, threshold: "any", severity: "critical", }); } }); const critCount = alerts.filter(a => a.severity === "critical").length; const warnCount = alerts.filter(a => a.severity === "warn").length; let status: "ok" | "warn" | "critical"; if (critCount > 0) status = "critical"; else if (warnCount > 0) status = "warn"; else status = "ok"; return { content: [ { type: "text" as const, text: JSON.stringify( { status, total_alerts: alerts.length, critical: critCount, warnings: warnCount, episodes_checked: episodes.length, thresholds: { ci: `${(ciThresh * 100).toFixed(0)}%`, ema: `${(emaThresh * 100).toFixed(0)}%`, al: `AL${alThresh}`, ghost: ghostOn, fault: faultOn, }, alerts, }, null, 2 ), }, ], }; } ); - src/index.ts:1047-1054 (schema)Zod input schema for alert_check: episodes array, optional ci_threshold (default 0.45), ema_threshold (default 0.45), al_threshold (default 3), ghost_alert (default true), fault_alert (default true).
{ episodes: z.array(z.record(z.string(), z.unknown())).min(1).describe("Episode array from an evaluate or fleet response"), ci_threshold: z.number().min(0).max(1).optional().describe("Alert if any episode CI exceeds this (default: 0.45 = Drift boundary)"), ema_threshold: z.number().min(0).max(1).optional().describe("Alert if any episode EMA exceeds this (default: 0.45)"), al_threshold: z.number().int().min(0).max(4).optional().describe("Alert if any episode authority level >= this (default: 3 = Minimal)"), ghost_alert: z.boolean().optional().describe("Alert on ghost detections (default: true)"), fault_alert: z.boolean().optional().describe("Alert on faults (default: true)"), }, - src/index.ts:1044-1164 (registration)Registration of the alert_check tool via server.tool() with its description, input schema, and handler function.
server.tool( "alert_check", "Check episodes against configurable thresholds and return triggered alerts — no API call, no auth, no credits. Takes an episode array from evaluate or fleet responses. Response: { status: 'ok'|'warn'|'critical', total_alerts, critical, warnings, episodes_checked, thresholds, alerts: [{ episode, type, value, threshold, severity }] }. Alert types: ci_exceeded, ema_exceeded, authority_elevated, ghost_detected, fault.", { episodes: z.array(z.record(z.string(), z.unknown())).min(1).describe("Episode array from an evaluate or fleet response"), ci_threshold: z.number().min(0).max(1).optional().describe("Alert if any episode CI exceeds this (default: 0.45 = Drift boundary)"), ema_threshold: z.number().min(0).max(1).optional().describe("Alert if any episode EMA exceeds this (default: 0.45)"), al_threshold: z.number().int().min(0).max(4).optional().describe("Alert if any episode authority level >= this (default: 3 = Minimal)"), ghost_alert: z.boolean().optional().describe("Alert on ghost detections (default: true)"), fault_alert: z.boolean().optional().describe("Alert on faults (default: true)"), }, async ({ episodes, ci_threshold, ema_threshold, al_threshold, ghost_alert, fault_alert }) => { const Q = 65535; const ciThresh = ci_threshold ?? 0.45; const emaThresh = ema_threshold ?? 0.45; const alThresh = al_threshold ?? 3; const ghostOn = ghost_alert ?? true; const faultOn = fault_alert ?? true; interface Alert { episode: number; type: string; value: string; threshold: string; severity: "warn" | "critical"; } const alerts: Alert[] = []; (episodes as Array<Record<string, unknown>>).forEach((ep, i) => { const ci = ((ep.ci_out as number) || 0) / Q; const ema = ((ep.ci_ema_out as number) || 0) / Q; const al = (ep.al_out as number) || 0; if (ci > ciThresh) { alerts.push({ episode: i + 1, type: "ci_exceeded", value: `${(ci * 100).toFixed(1)}%`, threshold: `${(ciThresh * 100).toFixed(1)}%`, severity: ci > 0.70 ? "critical" : "warn", }); } if (ema > emaThresh) { alerts.push({ episode: i + 1, type: "ema_exceeded", value: `${(ema * 100).toFixed(1)}%`, threshold: `${(emaThresh * 100).toFixed(1)}%`, severity: ema > 0.70 ? "critical" : "warn", }); } if (al >= alThresh) { alerts.push({ episode: i + 1, type: "authority_elevated", value: `AL${al}`, threshold: `AL${alThresh}`, severity: al >= 4 ? "critical" : "warn", }); } if (ghostOn && ep.ghost_confirmed) { alerts.push({ episode: i + 1, type: "ghost_detected", value: `streak ${ep.ghost_suspect_streak || 0}`, threshold: "any", severity: "critical", }); } if (faultOn && ep.fault) { alerts.push({ episode: i + 1, type: "fault", value: `code ${ep.fault_code || 0}`, threshold: "any", severity: "critical", }); } }); const critCount = alerts.filter(a => a.severity === "critical").length; const warnCount = alerts.filter(a => a.severity === "warn").length; let status: "ok" | "warn" | "critical"; if (critCount > 0) status = "critical"; else if (warnCount > 0) status = "warn"; else status = "ok"; return { content: [ { type: "text" as const, text: JSON.stringify( { status, total_alerts: alerts.length, critical: critCount, warnings: warnCount, episodes_checked: episodes.length, thresholds: { ci: `${(ciThresh * 100).toFixed(0)}%`, ema: `${(emaThresh * 100).toFixed(0)}%`, al: `AL${alThresh}`, ghost: ghostOn, fault: faultOn, }, alerts, }, null, 2 ), }, ], }; } );