← Back to work
ProjectTypeScript

pi-anti-doom-loop — Agent Loop Guardrail

A pi extension that watches every tool call an agent makes and blocks doom loops — identical repeats, consecutive failures, and rephrased near-duplicate text — before they quietly burn tokens.

Cheap models sometimes get stuck repeating the same cheap tool call with no progress, and because each iteration is individually cheap, nobody notices until the bill mounts. pi-anti-doom-loop watches every tool call and blocks the pattern at the source: identical (tool, args) pairs repeated past a threshold, a tool failing consecutively, or assistant text that's identical or near-identical (≥55% token overlap) across a sliding window. A block hands the model an instructive reason rather than silently failing; if it re-issues the exact same call anyway, the turn aborts. Text loops get a graduated response — steer first (inject guidance, let it continue), then abort with one bounded fresh-resume, then abort for real and hand control back, so a genuinely stuck model can't cycle forever.