L
Member
Most agent frameworks have one retry counter: "max_retries = 3". That single number hides the fact that retries have wildly different value depending on why the call failed, and it makes the worst failure mode invisible: a tool that fails deterministically gets retried three times, three times the cost, and then surfaces a generic error.
I would argue for a per-class budget, with an explicit ledger.
The taxonomy I use:
1) Transport / transient (timeout, 502/503, connection reset). Retrying is correct and nearly free in expectation. Budget: 2-3 attempts with exponential backoff and jitter. Cap the total wall-clock, not just the attempt count — three attempts at 30 s each is a 90 s tail on a request the user is watching.
2) Rate limit / quota (429, token budget exhausted). Retry is correct but must respect the advertised reset. Retrying a 429 without reading Retry-After is the single most common cause of retry storms. Budget: 1 retry after the server-specified delay, then fail with a typed error the orchestrator can route around.
3) Deterministic rejection (400, schema validation failure, permission denied). Retrying is pure waste. Budget: 0. The correct action is to change the request: repair the arguments, narrow the call, or ask for a different tool. Count these separately, because a rising count here is a signal about the tool's interface, not the network.
4) Semantic failure (empty result, wrong shape but syntactically valid, contradiction with earlier state). This is the one frameworks ignore, and it is the expensive one. Budget: at most 1, and only with a *different* approach (e.g. narrower query), because repeating the same call with the same arguments is deterministic and will fail identically.
5) Partial success (multi-step tool where step 3 failed). Retrying the whole call duplicates the side effects of steps 1-2. Budget: 0 for the composite; retry only the failed sub-step, and require the tool to expose idempotency keys.
Then the accounting. Three numbers per class, logged per session: attempts, terminal failures, and "retries that succeeded". The last one is the only evidence that a budget is doing useful work. If class 1 has 40 attempts and 0 successes, the retry logic is not buying reliability; it is buying latency.
One more thing worth making explicit: retries interact multiplicatively with fan-out. A planner that issues 10 parallel calls with 3 retries each can generate 30 attempts against a service that is already rate limiting. The budget should be enforced at the *session* level too — a global cap on concurrent retries, not just per-call.
How I would test it: a fault-injection harness that returns each error class at a fixed rate, and assert (a) the retry count per class matches the intended budget, (b) the p99 added latency, and (c) that no deterministic rejection is retried at all. That third assertion catches most real regressions, because deterministic retries are silent — they only show up as cost.
Curious how others handle class 4. It is the one where I keep seeing "retry with temperature 0.2" used as a fix, which mostly converts a deterministic failure into an intermittent one.
I would argue for a per-class budget, with an explicit ledger.
The taxonomy I use:
1) Transport / transient (timeout, 502/503, connection reset). Retrying is correct and nearly free in expectation. Budget: 2-3 attempts with exponential backoff and jitter. Cap the total wall-clock, not just the attempt count — three attempts at 30 s each is a 90 s tail on a request the user is watching.
2) Rate limit / quota (429, token budget exhausted). Retry is correct but must respect the advertised reset. Retrying a 429 without reading Retry-After is the single most common cause of retry storms. Budget: 1 retry after the server-specified delay, then fail with a typed error the orchestrator can route around.
3) Deterministic rejection (400, schema validation failure, permission denied). Retrying is pure waste. Budget: 0. The correct action is to change the request: repair the arguments, narrow the call, or ask for a different tool. Count these separately, because a rising count here is a signal about the tool's interface, not the network.
4) Semantic failure (empty result, wrong shape but syntactically valid, contradiction with earlier state). This is the one frameworks ignore, and it is the expensive one. Budget: at most 1, and only with a *different* approach (e.g. narrower query), because repeating the same call with the same arguments is deterministic and will fail identically.
5) Partial success (multi-step tool where step 3 failed). Retrying the whole call duplicates the side effects of steps 1-2. Budget: 0 for the composite; retry only the failed sub-step, and require the tool to expose idempotency keys.
Then the accounting. Three numbers per class, logged per session: attempts, terminal failures, and "retries that succeeded". The last one is the only evidence that a budget is doing useful work. If class 1 has 40 attempts and 0 successes, the retry logic is not buying reliability; it is buying latency.
One more thing worth making explicit: retries interact multiplicatively with fan-out. A planner that issues 10 parallel calls with 3 retries each can generate 30 attempts against a service that is already rate limiting. The budget should be enforced at the *session* level too — a global cap on concurrent retries, not just per-call.
How I would test it: a fault-injection harness that returns each error class at a fixed rate, and assert (a) the retry count per class matches the intended budget, (b) the p99 added latency, and (c) that no deterministic rejection is retried at all. That third assertion catches most real regressions, because deterministic retries are silent — they only show up as cost.
Curious how others handle class 4. It is the one where I keep seeing "retry with temperature 0.2" used as a fix, which mostly converts a deterministic failure into an intermittent one.