Heuristic:42 evey Hermes plugins Exponential Backoff Retry
| Knowledge Sources | |
|---|---|
| Domains | Resilience, LLM_Delegation, Error_Handling |
| Last Updated | 2026-10-29 00:00 GMT |
Overview
Retry transient LLM failures up to 3 times with exponential backoff (1s, 2s) and treat empty responses as failures requiring retry.
Description
The delegate-with-model plugin wraps each ctx.llm.complete() call in a retry loop. On any exception, it waits 2 ** (attempt - 1) seconds (1s, then 2s) before the next attempt. Crucially, an empty response (content = (result.text or "").strip() being falsy) is also treated as a failure and triggers a retry — not just exceptions. This catches the case where an LLM returns an empty string without erroring, which happens with some providers under load.
The retry loop tracks the attempt count and logs successful retries: "model succeeded on retry N". After all retries are exhausted, it raises RuntimeError with the last error message.
Usage
Use this heuristic when making any LLM API call that may fail transiently. Apply it especially to delegation and embedding calls where network timeouts, rate limits, or model unavailability are expected.
The Insight (Rule of Thumb)
- Action: Set
MAX_RETRIES_PER_MODEL = 3. On failure,time.sleep(2 ** (attempt - 1))before retrying. - Value: Backoff schedule: 1s (attempt 2), 2s (attempt 3). Total worst-case wait: 3 seconds.
- Trade-off: Adds up to 3 seconds latency on transient failures. The trade-off is worth it: a 3-second delay is better than a failed delegation that requires a full re-run.
- Compatibility: Treats empty responses as failures (not just exceptions). This catches a common provider bug where the API returns 200 OK with an empty body.
Reasoning
LLM API calls fail for many transient reasons: rate limits (429), network timeouts, model server restarts, and provider-side bugs. A simple retry with backoff handles all of these. The exponential schedule (1s, 2s) is gentle enough to not add significant latency but gives the provider time to recover.
Treating empty responses as failures is a key insight: some providers return an empty string when the model is overloaded, without raising an exception. Without this check, the agent would accept an empty delegation result as "success" and proceed with no data.