Skip to main content

Guards

Guards are live circuit breakers that monitor an agent during execution. While gates check after a step finishes, guards watch in real-time and kill the agent immediately if a condition is met.

Declaring guards

Available guards

no_write is implicitly true for split and validate step types. Override with guard: { no_write: false } if needed. timeout is an alias for max_time — if both are present, it’s a parsing error.

What happens when a guard triggers

  1. The agent is killed immediately
  2. The worktree is reset to the pre-step state (mutations undone)
  3. Partial metrics are collected (tokens spent, cost so far, turns completed)
  4. The gate runs (it will fail)
  5. Retry applies — same flow as a gate failure
A guard_triggered event is emitted in the ledger with the guard name, reason, and partial metrics.

Guards are reactive, not preventive

Guards react to agent behavior by parsing the NDJSON stream. There’s a small delay between the agent acting and the guard detecting it. File writes are caught and reverted via worktree reset. Network calls or other side effects outside the worktree cannot be undone.

Guards vs Gates