Agent in Production
ResilienceLong read

Flaky Tool Calls in Coding Agents and Retry Strategy Design

Retries need separate controls for safety, timing, and stopping.

· 8 min read
Cover illustration for “Flaky Tool Calls in Coding Agents and Retry Strategy Design”
Resilience · November 27, 2026 · 8 min read · 1,883 words

Flaky tool calls in coding agents require separate controls for safe repetition, retry timing, and stopping execution. Preventing unexpected API bills also requires hard spending limits enforced during the session. A sound retry strategy combines those limits with failure classification, idempotency, per-tool timeouts, backoff with jitter, circuit breakers, and an auditable owner for every retry decision.

Why tool calls, not model reasoning, are the primary failure surface of coding agents

A model can choose the correct action while the tool executes it twice, times out silently, or completes only part of the requested work. The failure lives at the tool boundary. That boundary is the contract between the agent’s intended action and what the tool actually does, including how it reports completion.

Four failure shapes recur at this boundary, including wrong argument types that pass validation, transient timeouts treated as permanent failures, partial successes reported as completion, and non-idempotent writes executed twice. Partial success means some work was done, but the full operation did not finish. Idempotency means repeating an operation does not produce another effect. Three of these four failure shapes are contract problems.

MCP standardizes how tools are described and called, but it does not define retry strategy, idempotency, rate-limit policy, or partial-failure semantics. Those remain the application’s responsibility.

How naive retry logic turns a single flaky call into a compounding failure

Take a tool that works nine times in ten. With zero delay, no backoff, and no cap, it gets called fifty times in three seconds. The sandbox rate-limits it, and each 429 makes it try again right away. After hundreds of LLM calls, the pipeline has used up a large token budget, but the original task is still unfinished. The retry has become the workload.

Parallel agents make this storm harder to contain. When they share the same flaky tool and retry simultaneously, their combined load saturates it faster than any single agent would. Even growing delays can re-synchronize into waves without jitter, producing a thundering herd. Meanwhile, independent retry counters in the agent loop, SDK, HTTP client, queue, and tool wrapper multiply attempts below the apparent policy.

The expense also extends beyond tool execution. Retrying the full reasoning loop pays for planning again, while appending every full error to message history makes subsequent prompts longer. If the plan was wrong, repeating the same prompt can reproduce the wrong plan at full cost. Blanket retries of 400 Bad Request or 403 Forbidden add another deterministic source of failure.

Classifying failures before choosing a response — the prerequisite the other controls depend on

The first decision is whether another attempt could succeed. Retryable candidates include 429, 5xx, connection errors, and timeouts because the underlying condition may be transient. Non-retryable responses include 400, 401, 403, 404, and 422 because repeating the unchanged request reproduces the failure. LangGraph’s default retry policy similarly excludes ValueError and TypeError. Input correction is not the same as repetition.

A transport failure leaves it unclear whether the tool ran, but a tool-reported error means the tool ran and rejected the operation. Neither category alone establishes safe repetition. MCP’s readOnlyHint, destructiveHint, and idempotentHint inform that judgment as server claims that carry no guarantee.

The resulting policy should permit timeout retries for reads, or for idempotent operations protected by a caller-supplied key. For invalid input, a structured error should describe what is wrong with each field and give an example of correct input. That lets the model correct the request instead of interpreting a raw stack trace as another reason to retry.

Idempotency as the prerequisite for safe retries on writes

A create_ticket call that timed out may already have created the ticket. Retrying without an idempotency guard can create a second one, even though the agent intended only to recover from a network failure. Waiting longer does not change that execution risk. Neither does lowering the attempt cap.

Every retryable write needs an idempotency key supplied by the caller, which the tool accepts and uses to keep the operation from running twice. The protection belongs below the agent’s reasoning layer. An agent can report success after duplicating an effect, so its final completion message cannot establish that the operation happened only once.

If a downstream tool does not accept an idempotency key and the application does not control it, retrying a non-idempotent write is unsafe and execution must stop.

Caps, exponential backoff, and jitter as controls on retry timing and volume

Once repetition is safe, three controls govern its volume and timing. A hard cap bounds attempts, exponential backoff increases the delay between them, and full jitter chooses a random wait between zero and the computed delay. These controls are not interchangeable. A cap limits the damage, backoff gives the service time to recover, and jitter keeps competing agents from trying again at the same time.

Framework defaults make explicit configuration important. Temporal’s RetryPolicy defaults to maximum_attempts = 0, meaning unlimited attempts, as of June 2026. Inngest runs each step.run() five times total by default, with an independent counter for each step. LangGraph’s RetryPolicy defaults to max_attempts=3, but retries are opt-in and attached per node. Five attempts is a workable limit, but it will not fit every case.

The original task also needs a deadline. Four attempts with growing backoff can outlive the caller, so retrying must stop when the remaining time is smaller than the next computed delay. A 429 response should also have its Retry-After honored. Amazon’s Builders’ Library article “Timeouts, retries, and backoff with jitter” provides background for these timing controls, but the application still has to fit them within its own task budget.

Per-tool timeouts derived from real latency data, not shared defaults

Timeout selection begins by pulling the last two weeks of traces, grouping them by tool name, and computing p50, p95, and p99 latency. The chosen percentile reflects the false-timeout rate the team accepts. If cutting off one call in a hundred is acceptable, p99 supplies the corresponding threshold.

A product search tool with a low p95 and a PDF export tool with a much higher p95 cannot sensibly share one timeout. A setting can be too aggressive for the export while still allowing the search to wait unnecessarily long. In an agent, either mistake distorts the retry decision.

Each tool also needs its own connect, read, and total timeouts. The connect timeout is short, around one to two seconds, while the read timeout measures silence after sending the request. A total timeout bounds the whole exchange. This distinction is especially important for streaming tools, where slowly arriving data can keep resetting a read timer without completing the operation. A write timeout still does not authorize repetition without idempotency.

Circuit breakers as the control that stops retrying a tool that is plainly down

A retry cap bounds one operation’s attempts, but it does not stop subsequent operations from calling the same unavailable tool. A circuit breaker addresses that gap. After a configurable number of consecutive failures from an endpoint, with around ten as a practical threshold, it opens and stops further calls to that tool. The agent then escalates, preserving its remaining budget.

The breaker must be scoped per tool. A payment tool should remain available when a weather API fails, and an opening should generate an incident alert. When a fallback is available, the application can use a replica, cached result, or secondary tool. Degradation metadata must tell the model what changed, including whether it now has cached results from two hours ago in place of live search.

LangGraph 0.2.x lacks native circuit-breaker utilities, although Temporal’s Nexus implements circuit breaking per caller-Namespace/Endpoint pair. Where coverage is absent, the tool wrapper needs the control. A Python pattern combining tenacity for retries and circuitbreaker for isolation can return structured fallback responses without making the model infer an outage.

Retry stacking across orchestration layers and why each layer cannot own its own policy independently

Each independent retry owner interprets failure from its own position in the stack. An SDK can exhaust its attempts before the wrapper retries the entire SDK operation, after which a queue redelivery can repeat both. Every local policy may appear conservative. Together, they authorize more work than the developer intended.

The architectural rule is one retry owner per failure class. Other layers must pass the failure through or disable their own retries for that class, while every attempt consumes the original task’s time and call budget. Establishing that ownership requires an inventory of the agent loop, SDK defaults, HTTP client defaults, queue redelivery policy, and tool wrapper. Missing attempt guards and an unset Temporal cap deserve particular attention.

A supervisor architecture makes these boundaries explicit. The supervisor controls worker assignment, allowed tools, and whether a failure should retry or stop, rather than leaving planning, routing, validation, retries, cleanup, and summarization inside one undifferentiated agent loop. This separation limits the blast radius of a worker’s failure. It also gives retry ownership a defined place in the system’s state transitions.

Observability as the mechanism that makes retry policy auditable and improvable

A retry policy is only testable against its actual attempts. The minimum record is one JSON line per attempt containing tool name, idempotency key, attempt number, latency in milliseconds, circuit-breaker state, and outcome. Attempt numbers must remain visible per layer. Otherwise, an outage-driven traffic spike cannot be distinguished from the hidden multiplication of nested retry policies.

OpenTelemetry attributes can link records of what ran to what it cost. Relevant fields include gen_ai.tool.name, coding_agent.tool_call.duration_ms, coding_agent.tool_call.retry_count, gen_ai.usage.cached_tokens, and gen_ai.cost.total_usd. Those records support attribution by tool call and retry attempt, while breaker openings must surface as alerts. Spend reporting alone does not halt execution.

Production records should identify who initiated the agent, which prompt ran, which calls and retries occurred, what files changed, and who approved the merge, with the record written to an immutable store and forwarded to SIEM.

Ellipsis is one managed option that runs sessions in isolated sandboxes and logs every tool call and timeout, making stacked attempts visible in the record. It also enforces session and developer budget caps while execution is running, so a retry storm encounters a hard limit.

Assembling the full retry strategy — a layered policy for coding agents in production

Diagram: The Layered Retry Decision: From Failure to Eligible Attempt. Visualizes: Show the sequential decision gates a coding agent must pass before executing a retry on a write operation.

A transient response makes a retry eligible, but a write still requires an accepted caller-supplied idempotency key and a deduplication window. Without that protection, the decision stops. For an eligible call, the application then evaluates its per-tool timeout, remaining deadline, attempt allowance, and circuit state before applying backoff with full jitter.

The designated layer controls repetition for its failure class, while nested layers consume the same original task budget. A hard spending limit serves a different purpose from an attempt cap or deadline. It bounds financial exposure during the session, including the cost of reasoning loops and growing error context.

Graceful degradation also needs an explicit outcome. An open circuit can trigger escalation or a declared fallback, rather than leaving the model to reason over missing data as though the tool succeeded. Every such decision must remain attributable to the tool, session, and trigger.

In production, these controls work alongside scoped credentials, isolated execution, and complete audit trails. Retry strategy is therefore an engineering discipline encompassing the “try again” setting and deserves the same version-controlled, observable, governed treatment as the rest of the agent’s configuration.

Sources

  1. Engineering Reliable Coding Agents: Evaluating and Operating the System Around the Model
Filed underResilience

More in Resilience