Skip to main content

Guards

Guards are live 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

- name: impl
  agent: claude-haiku
  guard:
    max_turns: 30
    max_budget: 2.00
  gate: [compile, test]

Available guards

max_turns

Kills the agent if it exceeds a number of cognitive turns (think → act → observe cycles).
guard:
  max_turns: 60
An agent that spins in circles — editing, running tests, editing again — will eventually hit the turn limit. This prevents runaway sessions that burn tokens without progress.

max_budget

Kills the agent if the step cost exceeds a dollar amount. More reactive than max_budget at the workflow level (which checks after each step completes). This guard checks during execution by tracking token costs from the agent stream.
guard:
  max_budget: 3.00

no_write

Kills the agent if it writes files outside .gump/out/. Used to enforce that planning and review agents don’t modify code.
guard:
  no_write: true
This guard is automatically enabled for output: plan, output: artifact, and output: review. You can override it with guard: { no_write: false } if you have a planning agent that legitimately needs to create files.

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 {error} variable is injected with the guard’s reason
  5. on_failure applies — same as a gate failure (retry, escalate, or fatal)
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

GatesGuards
WhenAfter the step finishesDuring execution
WhatCompile, test, lint, schemaTurn count, cost, file writes
MechanismShell commands, file checksStream parsing, process kill
On failureSame on_failure flowSame on_failure flow
LLM involvedNeverNever