Özer Cem KELAHMETKELAHMET
AI Simulations · Agents

Tool-call retries with exponential backoff, success rate, waiting time and extra load

Agents call tools that fail now and then with rate limits, server errors and timeouts. Set a retry policy for fourteen tools from a day of traces and see how many calls recover, how long the agent waits in backoff and how much extra load the retries put on each service.

Download Markdown

Interactive simulation. It needs JavaScript; the text below explains what it shows.

What you are looking at

Each row is one tool that an agent used during a day: a web search, a page fetch, the GitHub API, a SQL database, a vector store, a sub-agent that calls another model, a code sandbox and so on. The white columns come from traces: how many calls the tool received, the share of first attempts that failed with a retryable error (p_fail) and how long one attempt takes. The orange columns apply your retry policy to each tool: the chance a call eventually succeeds, the expected number of attempts, the expected time spent waiting between attempts and the expected time per call in all.

The chart puts every tool on the curve of the model. The dashed line is what happens without retries: a tool that fails 20% of the time succeeds 80% of the time. The solid line is the same tool with up to M attempts. The bars show the expected seconds per call, which is where retries become visible to the user.

The algorithm

A retry policy has three parts: how many attempts to make, how long to wait between them and which errors to retry. The simulation follows the parameters of LangGraph's RetryPolicy (see LangGraph): max_attempts counts every attempt including the first and defaults to 3, initial_interval is 0.5 seconds, backoff_factor is 2.0, max_interval is 128 seconds and jitter is on.

Success. If each attempt fails independently with probability p, a call fails for good only if all M attempts fail:

P = 1 − p^M

Expected attempts. Attempt k is made only if the first k − 1 failed, so

E[A] = 1 + p + p² + … + p^(M−1) = (1 − p^M) / (1 − p)

Backoff. Retry k waits b × f^(k−1) seconds: 0.5, 1, 2 and so on. Jitter replaces each wait with a random value. Here a jitter share j draws the wait uniformly between (1 − j) and 1 times the backoff, so the mean wait is (1 − j/2) times the backoff, and j = 1 is the "full jitter" of the AWS article. The expected waiting time per call is

E[W] = (1 − j/2) × (p·b + p²·b·f + … + p^(M−1)·b·f^(M−2))

The simulation leaves out the 128-second cap: with the defaults the longest wait is 1 second, so it never applies, but with many attempts and a large factor it would.

Task level. An agent task strings many tool calls together. If any call fails for good the agent has to recover or stop, so the chance that a task of K calls sees no unrecovered tool error is roughly P̄^K, where P̄ is the call-weighted success rate.

Worked example. With the defaults (3 attempts, 0.5 s, factor 2, full jitter) the day has 13,750 tool calls and 95.4% succeed at the first attempt. After retries the success rate is 99.94%, and only about 8.5 calls a day still fail. The weather API, which fails 25% of the time, goes from 75% to 1 − 0.25³ = 98.4%. The price is small: 1.050 attempts per logical call (5% more load) and 3.1 minutes of backoff across the whole day. For a task with 20 tool calls the difference is large: without retries only 39.2% of tasks avoid every tool error (0.954^20), with retries 98.8% do.

Things to try

  • Set max attempts to 1. The success rate falls to 95.4%, about 628 calls a day fail, and a 20-call task is clean only 39.2% of the time.
  • Raise max attempts to 5. Calls still failing drop to about 0.26 a day and the worst tool reaches 99.9%, while load rises only to 1.051 attempts per call: most of the gain comes from the second and third attempts.
  • Set the jitter share to 0. The success rate does not change, but the time spent in backoff doubles from 3.1 to 6.3 minutes. Jitter is not about waiting less, it is about clients not retrying in lockstep; this model shows only the mean.
  • Raise the task to 60 tool calls and compare the two task-level numbers: long agent runs make small per-call error rates add up.
  • Look at the bars: the sub-agent call (tool 6) dominates the time per call because each attempt takes 8.5 seconds. For slow tools a retry costs a full attempt, not just the backoff.

How it works in real systems

The independence assumption is the weak point of this model. Rate-limit errors and outages come in bursts: if a service is down, the third attempt fails as surely as the first. Real policies therefore respect a retry-after header when the server sends one, cap the total time spent retrying and stop retrying once errors persist.

Retries also multiply load. The AWS Builders' Library notes that if several layers of a stack each retry independently, the load on the bottom layer can grow by orders of magnitude, so it recommends retrying at a single point in the stack and limiting retries locally with a token bucket. In an agent that means choosing one place to retry: the SDK, the tool wrapper or the graph node, not all three.

Only retry what is safe to repeat. LangGraph's default retry_on skips programming errors such as ValueError and TypeError, and for HTTP libraries such as requests and httpx it retries only 5xx responses. A retry re-runs the whole node, which gives at-least-once semantics: a tool that sends an email or charges a card needs an idempotency key before it can be retried.

Measure before tuning. Export per-tool error rates and latencies from LangSmith or Langfuse traces (see tracing) and paste them in here. A tool whose failure rate stays high after retries needs a fix at the source: a higher rate limit, a cache, a circuit breaker or a fallback tool. The agent loop token cost simulation shows the other side of long runs: every extra step also costs tokens. See also cost and latency budgets.

Sources

Last updated Nov 23, 2026
Type to search.
    ↑↓ navigate↵ open