AI Agent Spend Anomaly Detection and Budget Variance Gates A developer outlined a financial control layer for AI agents that detects spend anomalies per workflow rather than from aggregate invoices, building a cost distribution from the first 30 to 50 completed runs and flagging any run above the 90th percentile as a candidate anomaly. The approach enforces gates at dispatch time—downgrading to a distilled model, applying cached context, or pausing for human review when a run exceeds its task-level dollar ceiling—and adds a circuit breaker keyed on identical repeated tool calls, since retry loops can burn money without breaching any single-call budget. The writeup cites trajectory analysis showing token usage on the same task can vary by up to 30x, with accuracy often peaking at intermediate cost, and notes repeatable inefficiencies such as subsumed retrieval and test re-execution account for up to 22.75 percent of task cost. AI agent spend anomaly detection and budget variance gates are the financial control layer that separates normal inference cost from pathological execution loops before they distort a monthly invoice. Aggregated LLM spend hides the signature of a runaway agent: a single workflow that retries the same failing tool call dozens of times looks identical to ten healthy workflows in a monthly summary. Finance teams need per-task baselines, not aggregate invoices. Explore architectural blueprints at rausalbahtiar.dev https://rausalbahtiar.dev . Trajectory analysis of frontier coding agents shows token usage is highly variable and inherently stochastic: runs on the same task can differ by up to 30x in total tokens, and higher token usage does not translate into higher accuracy. Accuracy often peaks at intermediate cost and saturates at higher cost. This means cost is a noisy signal, but variance is not noise: a workflow whose cost distribution widens week over week is degrading even when the mean stays flat. A single cost average cannot flag an anomaly because the same task legitimately costs different amounts per run. Build a per-workflow cost distribution from the first 30 to 50 completed runs, record the median and the 90th percentile as the operating envelope, then treat any run that clears the 90th percentile threshold as a candidate anomaly. A threshold at the percentile rather than the mean captures skewed cost distributions without over-triggering on legitimate hard tasks. Enforce the gate at dispatch time, not after invoice reconciliation. When a run exceeds its task-level dollar ceiling, the router downgrades to a distilled model, applies a cached context, or pauses the workflow for human review. Cost-inefficiency studies of coding agents identify specific repeatable behaviors, such as subsumed retrieval, similar script generation, and test re-execution, that account for up to 22.75 percent of task cost. These are detectable by pattern, not by total spend. Anomaly detection on cost is necessary but not sufficient: a retry loop can spend money without exceeding any single-call budget. Add a hard circuit breaker keyed on identical repeated tool calls within a single task. Recording run state transitions to a low-latency ledger allows real-time accounting without adding inference latency, so the breaker can terminate a loop after a fixed retry count rather than after a dollar amount is burned. Because a monthly invoice aggregates healthy and pathological runs into one number. A single loop can triple its own cost while remaining a small fraction of fleet spend. Per-task variance exposes it; aggregate spend hides it. Roughly 30 to 50 completed runs per workflow give a stable median and percentile envelope. Below that, use the router's global distribution as a provisional baseline. Percentile. Cost distributions are right-skewed, so a mean threshold either over-triggers on legitimate hard tasks or misses early drift entirely.