# 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.

<div data-sim="specx" data-spec="{&#34;head&#34;:&#34;Tool-call retries: exponential backoff, success rate and the time it costs&#34;,&#34;sub&#34;:&#34;Fourteen tools from an agent&#39;s day of traces, each with its own rate of transient failures (429 rate limits, 5xx errors, timeouts). Set the retry policy and see how many calls recover, how long they wait and how much extra load the retries add.&#34;,&#34;params&#34;:[{&#34;id&#34;:&#34;max_att&#34;,&#34;label&#34;:&#34;Max attempts (including the first)&#34;,&#34;min&#34;:1,&#34;max&#34;:8,&#34;step&#34;:1,&#34;value&#34;:3,&#34;note&#34;:&#34;LangGraph&#39;s RetryPolicy default is 3&#34;},{&#34;id&#34;:&#34;base&#34;,&#34;label&#34;:&#34;Initial interval&#34;,&#34;min&#34;:0.1,&#34;max&#34;:5,&#34;step&#34;:0.1,&#34;value&#34;:0.5,&#34;unit&#34;:&#34;s&#34;,&#34;note&#34;:&#34;Wait before the first retry&#34;},{&#34;id&#34;:&#34;factor&#34;,&#34;label&#34;:&#34;Backoff factor&#34;,&#34;min&#34;:1,&#34;max&#34;:3,&#34;step&#34;:0.1,&#34;value&#34;:2,&#34;note&#34;:&#34;Each wait is this many times the previous one&#34;},{&#34;id&#34;:&#34;jit&#34;,&#34;label&#34;:&#34;Jitter share&#34;,&#34;min&#34;:0,&#34;max&#34;:1,&#34;step&#34;:0.05,&#34;value&#34;:1,&#34;note&#34;:&#34;Each wait is drawn uniformly between (1 - share) and 1 times the backoff; 1 is full jitter&#34;},{&#34;id&#34;:&#34;ksteps&#34;,&#34;label&#34;:&#34;Tool calls in one agent task&#34;,&#34;min&#34;:1,&#34;max&#34;:60,&#34;step&#34;:1,&#34;value&#34;:20}],&#34;data&#34;:{&#34;columns&#34;:[&#34;tool&#34;,&#34;calls&#34;,&#34;p_fail&#34;,&#34;lat_s&#34;],&#34;rows&#34;:[[1,1840,0.12,1.4],[2,1620,0.09,2.1],[3,960,0.04,0.6],[4,1310,0.02,0.3],[5,2250,0.01,0.2],[6,540,0.06,8.5],[7,880,0.03,3.2],[8,2900,0.002,0.05],[9,120,0.01,0.9],[10,310,0.015,0.4],[11,420,0.05,0.7],[12,260,0.03,0.5],[13,190,0.2,0.8],[14,150,0.25,1.1]],&#34;note&#34;:&#34;Illustrative day of agent traces (LangSmith or Langfuse style). Tools: 1 web search, 2 page fetch, 3 GitHub API, 4 SQL, 5 vector search, 6 sub-agent LLM, 7 code sandbox, 8 file read, 9 email, 10 calendar, 11 issue tracker, 12 chat, 13 geocoder, 14 weather API. p_fail: retryable first-try failures.&#34;},&#34;pre&#34;:[{&#34;id&#34;:&#34;tot_calls&#34;,&#34;label&#34;:&#34;Tool calls in the day&#34;,&#34;expr&#34;:&#34;sum(calls)&#34;,&#34;fmt&#34;:&#34;i&#34;},{&#34;id&#34;:&#34;wmult&#34;,&#34;label&#34;:&#34;Mean wait as a share of the backoff&#34;,&#34;expr&#34;:&#34;1 - jit/2&#34;,&#34;tex&#34;:&#34;\\mathbb{E}[u] = 1 - \\tfrac{j}{2}&#34;,&#34;hide&#34;:true}],&#34;row&#34;:[{&#34;id&#34;:&#34;psucc&#34;,&#34;label&#34;:&#34;P(success)&#34;,&#34;expr&#34;:&#34;1 - p_fail^max_att&#34;,&#34;fmt&#34;:&#34;p&#34;,&#34;tex&#34;:&#34;P_i = 1 - p_i^{M}&#34;},{&#34;id&#34;:&#34;eatt&#34;,&#34;label&#34;:&#34;expected attempts&#34;,&#34;expr&#34;:&#34;(1 - p_fail^max_att)/(1 - p_fail)&#34;,&#34;tex&#34;:&#34;\\mathbb{E}[A_i] = \\sum_{k=1}^{M} p_i^{k-1} = \\frac{1-p_i^{M}}{1-p_i}&#34;},{&#34;id&#34;:&#34;ewait&#34;,&#34;label&#34;:&#34;expected backoff (s)&#34;,&#34;expr&#34;:&#34;base*wmult*p_fail*(1 - (p_fail*factor)^(max_att - 1))/(1 - p_fail*factor)&#34;,&#34;tex&#34;:&#34;\\mathbb{E}[W_i] = \\big(1-\\tfrac{j}{2}\\big)\\sum_{k=1}^{M-1} p_i^{k}\\, b\\, f^{k-1}&#34;},{&#34;id&#34;:&#34;etime&#34;,&#34;label&#34;:&#34;expected seconds&#34;,&#34;expr&#34;:&#34;eatt*lat_s + ewait&#34;,&#34;tex&#34;:&#34;\\mathbb{E}[T_i] = \\mathbb{E}[A_i]\\,\\ell_i + \\mathbb{E}[W_i]&#34;},{&#34;id&#34;:&#34;lost&#34;,&#34;label&#34;:&#34;calls still failing&#34;,&#34;expr&#34;:&#34;calls*p_fail^max_att&#34;},{&#34;id&#34;:&#34;attempts&#34;,&#34;label&#34;:&#34;attempts sent&#34;,&#34;expr&#34;:&#34;calls*eatt&#34;},{&#34;id&#34;:&#34;cwait&#34;,&#34;label&#34;:&#34;backoff seconds&#34;,&#34;expr&#34;:&#34;calls*ewait&#34;,&#34;hide&#34;:true}],&#34;derived&#34;:[{&#34;id&#34;:&#34;p_first&#34;,&#34;label&#34;:&#34;First-attempt success rate&#34;,&#34;expr&#34;:&#34;1 - dot(calls, p_fail)/tot_calls&#34;,&#34;fmt&#34;:&#34;p&#34;},{&#34;id&#34;:&#34;p_all&#34;,&#34;label&#34;:&#34;Success rate after retries&#34;,&#34;expr&#34;:&#34;1 - sum(lost)/tot_calls&#34;,&#34;fmt&#34;:&#34;p&#34;,&#34;tex&#34;:&#34;\\bar P = 1 - \\frac{\\sum_i c_i\\, p_i^{M}}{\\sum_i c_i}&#34;},{&#34;id&#34;:&#34;n_lost&#34;,&#34;label&#34;:&#34;Calls that still fail&#34;,&#34;expr&#34;:&#34;sum(lost)&#34;},{&#34;id&#34;:&#34;amp&#34;,&#34;label&#34;:&#34;Load amplification&#34;,&#34;expr&#34;:&#34;sum(attempts)/tot_calls&#34;,&#34;tex&#34;:&#34;\\alpha = \\frac{\\sum_i c_i\\,\\mathbb{E}[A_i]}{\\sum_i c_i}&#34;,&#34;note&#34;:&#34;attempts sent per logical call&#34;},{&#34;id&#34;:&#34;wait_h&#34;,&#34;label&#34;:&#34;Time spent in backoff (min)&#34;,&#34;expr&#34;:&#34;sum(cwait)/60&#34;},{&#34;id&#34;:&#34;task_ok&#34;,&#34;label&#34;:&#34;Task with no unrecovered tool error&#34;,&#34;expr&#34;:&#34;p_all^ksteps&#34;,&#34;fmt&#34;:&#34;p&#34;,&#34;tex&#34;:&#34;P_{task} \\approx \\bar P^{\\,K}&#34;},{&#34;id&#34;:&#34;task_ok1&#34;,&#34;label&#34;:&#34;Same task without retries&#34;,&#34;expr&#34;:&#34;p_first^ksteps&#34;,&#34;fmt&#34;:&#34;p&#34;},{&#34;id&#34;:&#34;worst&#34;,&#34;label&#34;:&#34;Worst tool&#39;s success rate&#34;,&#34;expr&#34;:&#34;amin(psucc)&#34;,&#34;fmt&#34;:&#34;p&#34;}],&#34;chart&#34;:{&#34;title&#34;:&#34;Chance a call succeeds against its failure rate&#34;,&#34;x&#34;:{&#34;var&#34;:&#34;t&#34;,&#34;label&#34;:&#34;Transient failure rate of a tool (p)&#34;,&#34;from&#34;:0,&#34;to&#34;:0.3},&#34;y&#34;:{&#34;from&#34;:0.6,&#34;to&#34;:1},&#34;series&#34;:[{&#34;label&#34;:&#34;With retries: 1 - p^M&#34;,&#34;expr&#34;:&#34;1 - t^max_att&#34;},{&#34;label&#34;:&#34;No retries: 1 - p&#34;,&#34;expr&#34;:&#34;1 - t&#34;,&#34;dash&#34;:true}],&#34;fit&#34;:{&#34;x&#34;:&#34;p_fail&#34;,&#34;y&#34;:&#34;psucc&#34;,&#34;label&#34;:&#34;Each tool under this policy&#34;}},&#34;level&#34;:&#34;intermediate&#34;,&#34;bars&#34;:{&#34;title&#34;:&#34;Expected seconds per call, including retries and backoff&#34;,&#34;y&#34;:&#34;etime&#34;,&#34;label&#34;:&#34;tool&#34;},&#34;steps&#34;:[{&#34;title&#34;:&#34;Measure the failure rate&#34;,&#34;text&#34;:&#34;From the traces, {tot_calls} tool calls succeed on the first attempt {p_first:p} of the time. Only retryable errors count: 429, 5xx and timeouts, not bad arguments.&#34;,&#34;show&#34;:[&#34;tot_calls&#34;,&#34;p_first&#34;]},{&#34;title&#34;:&#34;Retry up to M attempts&#34;,&#34;text&#34;:&#34;With {max_att} attempts, a tool fails for good only if every attempt fails, so P = 1 - p^M. Over the day the success rate becomes {p_all:p} and {n_lost} calls still fail.&#34;,&#34;show&#34;:[&#34;p_all&#34;,&#34;n_lost&#34;]},{&#34;title&#34;:&#34;Wait longer each time&#34;,&#34;text&#34;:&#34;Retry k waits b × f^(k-1): {base} s, then {factor} times more. Jitter spreads the waits so clients that failed together do not retry together; the day spends {wait_h} minutes in backoff.&#34;,&#34;show&#34;:[&#34;wait_h&#34;]},{&#34;title&#34;:&#34;Count the extra load&#34;,&#34;text&#34;:&#34;Each logical call now sends {amp} attempts on average. Retries add load exactly when a service is struggling, which is why the attempt count must be capped.&#34;,&#34;show&#34;:[&#34;amp&#34;]},{&#34;title&#34;:&#34;Multiply across the task&#34;,&#34;text&#34;:&#34;An agent task makes {ksteps} tool calls. It avoids every unrecovered tool error with probability {task_ok:p}, against {task_ok1:p} without retries.&#34;,&#34;show&#34;:[&#34;task_ok&#34;,&#34;task_ok1&#34;]},{&#34;title&#34;:&#34;Find the weak link&#34;,&#34;text&#34;:&#34;The worst tool still succeeds only {worst:p} of the time. Fix it at the source (a paid tier, caching, a fallback tool) rather than with more attempts.&#34;,&#34;show&#34;:[&#34;worst&#34;]}]}"><p>Interactive simulation. It needs JavaScript; the text below explains what it shows.</p></div>

## 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](/tools/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](/tools/langsmith) or [Langfuse](/tools/langfuse) traces (see [tracing](/tools/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](/tools/circuit-breaker) or a fallback tool. The [agent loop token cost](/ai-simulations/agent-loop-token-cost) simulation shows the other side of long runs: every extra step also costs tokens. See also [cost and latency budgets](/tools/cost-and-latency-budgets).

## Sources

- [LangChain docs: LangGraph fault tolerance and RetryPolicy](https://docs.langchain.com/oss/python/langgraph/fault-tolerance)
- [AWS Architecture Blog: Exponential backoff and jitter](https://aws.amazon.com/blogs/architecture/exponential-backoff-and-jitter/)
- [Amazon Builders' Library: Timeouts, retries and backoff with jitter](https://aws.amazon.com/builders-library/timeouts-retries-and-backoff-with-jitter)
