Skip to content

// Feedback loops · ~2 min read

Self-Healing / Retry Loop

Reach for it when: failures are expected and a bounded retry with diagnosis beats giving up.

After this lesson you can: Sort a failure into a type, apply the matching fix, and retry within a budget.

// 60-second mental model

How to hold it in your head

Something failed. Do not spam the same call. Diagnose the failure class, pick a fix, retry with a budget — then escalate or stop.

Self-healing / retry loops classify errors (transient, schema, tool, policy), apply a bounded remediation (backoff, fix args, alternate tool), and hard-stop when the budget is spent. Diagnosis before retry — not blind re-prompting.

// Mini architecture

Fail → diagnose → remediate → retry (budgeted)

An action runs. On an error, a Diagnose step classifies it as transient, schema, tool or policy. A Remediate step applies backoff, fixes the arguments, or switches to another tool. If retries are left, the action runs again; if not, the loop escalates or fails safely.

Same error twice with no new diagnosis is a bug in the loop — not persistence.

// Mini-project

Flaky tool with classified retries (stub)

Action runner + diagnose stub + retry budget

Goal: Call a stub tool that fails twice (timeout, then bad args); heal with backoff then arg-fix; succeed on third try or escalate.

  1. Stub `fetch_invoice` fails: attempt 1 = timeout, attempt 2 = schema error, attempt 3 = success.
  2. Diagnose maps error codes → class + remediation.
  3. Transient → exponential backoff with jitter (wait longer each time, plus a random spread; simulated sleep). Schema → fix the arguments once.
  4. Policy errors never retry — escalate immediately.
  5. Hard maxRetries=3; log class → remediation → outcome.
  6. Refuse a blind “call again with the same args” path after a schema error.

Simulated failures are enough. The lesson is diagnose-then-retry with a budget — a pattern to build into your own tool runner.

// Common failure

What goes wrong

Symptom

Retry storms — the agent hammers the same broken call until rate limits or bills explode.

Fix

Classify first. Cap retries. Back off on transient. Never retry policy denials. Escalate with the diagnosis attached.

// Self-reflection

Sit with this

Which of your agents still retries by hope instead of by diagnosis?

Sources

Session only. Nothing is saved.