Retry layering in abt
abt separates three retry layers. Mixing them causes confusing logs and double-spend on model calls — use the right layer for each failure mode.
Layer 1 — Structural guardrails (never retry)
Owner: agent frontmatter, scoped abt.yaml config:, env.
Examples: recursion_limit, model_call_limit middleware, token_budget middleware,
wall-clock timeouts, loop_detection.enabled.
These are config-only (no CLI flags). When a guardrail fires, the run stops. Do not wrap guardrail exits in application-level retry loops — tune config instead.
See Config precedence and
abt config show --agent NAME.
Layer 2 — Transient infrastructure (declarative retry)
Owner: the built-in model-stream retry (stream blips), MCP tool-list loading, HTTP adapters where configured.
Examples: MCP list timeout, HTTP 5xx from a provider, transient stream disconnect before the first token.
Retries are bounded (max_attempts, jittered backoff) and logged at DEBUG.
They do not reset guardrail budgets — a retried stream pass may consume
another model-call credit.
Project defaults live in env / Settings (ABT_LLM_STREAM_* variables, see
Environment variables). There is no retry key in
abt.yaml: a top-level workflows: block is ignored, and retry is not an
accepted key under agents.<name>.config.
Per agent, two middlewares add bounded retries on top of that:
model_retryretries failed model calls.tool_retryretries failed tool calls. A tool is retried on any transient error only when it is known to be safe to repeat: an MCP tool whose server setsreadOnlyHintoridempotentHint, a built-in read tool (read_file,grep,glob,ls, ...), or a project tool that declares itself idempotent (below). Every other tool is retried only when the request never left (connection refused, DNS failure, connect timeout); a timeout, a dropped connection or an HTTP error status (including 429 and 503) after the request was sent fails the call once, because the service may already have applied it. It is dropped for any agent that has a tool withconfirmation_required: true, because a retry would re-execute an approved call without asking again.
When retries run out on a failure that clears by itself (a 5xx, 408/429, a timeout, a dropped connection),
the error the model receives says how many attempts were made and asks it not to repeat the call right away
and to note in its answer that the data was unavailable. Other errors (a 4xx, a bad argument) keep their own
"correct the call" text, and so does a call that was never retried, such as a write that failed after being
sent. With on_failure: error the exception is raised into the tool-error formatter instead, and the note
is not added.
Declare a tool of your own idempotent by setting metadata on it (see Tools):
fetch_logs.metadata = {"idempotent": True}
Both accept max_retries (default 2), backoff_factor (default 2.0),
initial_delay (default 1.0), and on_failure (continue by default, or
error). See Declarative middleware.
Layer 3 — Quality / logic (route, don't blindly retry)
Owner: transformers, deterministic recovery handlers, test assertions.
Examples: invalid JSON from the model, schema validation failure, blocked exposure payload.
Prefer routing: run a transformer, fire on_failure handlers, or return a
structured error. Blind LLM retries on bad output usually waste budget without
fixing the root cause.
Quick reference
| Failure | Layer | Action |
|---|---|---|
model_call_limit middleware exhausted |
1 — guardrail | Stop; raise limits in config |
MCP list_tools 503 |
2 — infra | Automatic bounded retry |
| Model returns non-JSON | 3 — quality | Transformer / handler / fail |
| Agent handler raises | 3 — quality | Lenient: log, and the handler record is kept in run_results.json |
Related docs
- Handlers — agent handler
fail_fastpolicy - Sources —
--mock-sourcesfor partial stubs (not retries) - Configuration — scoped
agents:tier