Runtime safety for debugging loops and caps

Guardrails: stop runaway agent runs early.

Guardrails are optional development-time safety rails that abort runs when behavior crosses your limits, then preserve a full evidence trail so root cause is obvious.

Protect budget

Abort loop-heavy runs before they expand API costs.

Keep evidence intact

Guardrail-triggering events are still recorded for investigation.

Tune per workflow

Set thresholds in decorators, context managers, YAML, or env vars.

Available guardrails

Start minimal, then tighten thresholds as your run profile becomes clear.

Guardrail Purpose Typical starter value
stop_on_loop Abort when repeated event patterns are detected true for iterative debugging
stop_on_loop_min_repetitions Minimum repetitions required to trigger loop abort 3
max_llm_calls Cap model invocations per run 25-100
max_tool_calls Cap tool invocations per run 25-100
max_events Cap total timeline events 100-300
max_duration_s Cap wall-clock run duration in seconds 30-120

What happens when a guardrail fires

  1. The triggering event is recorded.
  2. An ERROR event captures guardrail reason and values.
  3. RUN_END(status=error) is written.
  4. A catchable guardrail exception is raised.

You keep the full timeline to the exact abort point.

Behavior snapshot

Guardrails stopping a run in the AgentDbg viewer

Turn guardrails on for your next debugging run.

Use safe defaults first, then narrow thresholds to match expected behavior.