What guardrails do
When a configured threshold is crossed, AgentDbg:Records evidence
Writes the event or warning that triggered the guardrail using the normal trace format, so you have full context in the timeline.
Raises a typed exception
Raises
AgentDbgLoopAbort (for loop detection) or AgentDbgGuardrailExceeded (for count and duration limits).ERROR payload includes guardrail, threshold, actual, error_type, and message — so the UI and raw trace both tell you not just that the run failed, but which guardrail fired and what the actual value was.
Available guardrails
| Parameter | Type | Default | What it does |
|---|---|---|---|
stop_on_loop | bool | False | Abort when loop detection emits LOOP_WARNING |
stop_on_loop_min_repetitions | int | 3 | Minimum repeated pattern count required before stop_on_loop fires |
max_llm_calls | int | None | None | Abort after more than N LLM calls |
max_tool_calls | int | None | None | Abort after more than N tool calls |
max_events | int | None | None | Abort after more than N total events |
max_duration_s | float | None | None | Abort when elapsed run time reaches this limit |
Count-based guardrails (
max_llm_calls, max_tool_calls, max_events) trigger at N+1, not N — the event that crosses the limit is recorded before the run is aborted. max_duration_s triggers when elapsed time is greater than or equal to the configured value.Exceptions
AgentDbgLoopAbort
Raised when stop_on_loop=True and loop detection fires above the stop_on_loop_min_repetitions threshold. This is a subclass of AgentDbgGuardrailExceeded, so you can catch either.
AgentDbgGuardrailExceeded
Raised for all count and duration guardrails. Exposes the following attributes:
| Attribute | Type | Description |
|---|---|---|
guardrail | str | Which guardrail fired, e.g. "max_llm_calls" |
threshold | int | float | The configured limit |
actual | int | float | The value that exceeded the limit |
message | str | Human-readable description |
How guardrails appear in traces
Loop guardrail
Whenstop_on_loop=True and the loop detector fires:
- AgentDbg writes
LOOP_WARNING - Raises
AgentDbgLoopAbort - Writes
ERROR - Writes
RUN_END(status="error")
Count and duration guardrails
Formax_llm_calls, max_tool_calls, max_events, and max_duration_s:
- AgentDbg writes the event that crossed the limit (e.g. the LLM call that put you at N+1)
- Raises
AgentDbgGuardrailExceeded - Writes
ERROR - Writes
RUN_END(status="error")
Configuration
Guardrails can be configured in four places. The highest-precedence source wins:- Arguments passed directly to
@trace(...)ortraced_run(...) - Environment variables
- Project YAML:
.agentdbg/config.yaml - User YAML:
~/.agentdbg/config.yaml