RetryConfig in Graph Nodes: Per-Node Retry Policies and Exponential Jitter
Attach RetryConfig and timeout to ADK graph nodes for per-attempt recovery — max_attempts, exponential backoff with jitter, retryable exceptions, and when retries hurt.
Published on • December 2, 2026
AI Assistant

A forecast service returns a 503. A database connection drops mid-query. The model API rate-limits you for two seconds. None of these are bugs in your workflow — they are the normal weather of distributed systems — and without a retry policy, one unlucky attempt fails the entire run: every downstream node goes cold because a single HTTP call blinked at the wrong moment.
ADK 2.0 lets you attach a retry policy and a timeout to each node in a graph workflow, so a transient failure recovers inside the node instead of propagating out. But retries are not free. A naive retry hammers a service that is already struggling, re-executes side effects twice, and multiplies your model spend. In this tutorial you will learn the exact RetryConfig surface, how backoff and jitter actually compute their waits, which exceptions are worth retrying, and how to keep retries idempotent.
Prerequisites
- ADK 2.0 (
pip install google-adk) - Graph workflow basics:
Workflow, nodes, andEvent - The data handling docs for how node output flows
1. The minimal policy
Here is the pattern from the retries and timeouts docs: a node calls an unreliable forecast service with three total attempts, a one-second wait before the first retry, only transient errors retried, and a 10-second limit per attempt:
import random
from google.adk import Context
from google.adk import Event
from google.adk import Workflow
from google.adk.workflow import NodeTimeoutError
from google.adk.workflow import RetryConfig
from google.adk.workflow import node
class ServiceUnavailableError(Exception):
"""Stands in for a transient failure from a remote service."""
@node(
retry_config=RetryConfig(
max_attempts=3, # 1 original attempt + 2 retries
initial_delay=1.0, # seconds before the first retry
exceptions=[ServiceUnavailableError, NodeTimeoutError],
),
timeout=10.0, # seconds allowed for each attempt
)
async def fetch_forecast(ctx: Context):
"""Simulates an unreliable call to a forecast service."""
yield Event(message=f"Fetching forecast, attempt {ctx.attempt_count}")
if random.random() < 0.5:
raise ServiceUnavailableError("Forecast service unavailable")
yield "sunny"
def report_forecast(node_input: str):
return Event(message=f"The forecast is {node_input}.")
root_agent = Workflow(
name="forecast_workflow",
edges=[("START", fetch_forecast, report_forecast)],
)
When the node fails with a listed error or exceeds its timeout, ADK waits, then runs the node again with the same input. The next node runs only after an attempt succeeds. If all three attempts fail, the node fails with the last attempt’s error, and the workflow fails with it. Nodes without a retry policy are not retried at all.
Notice ctx.attempt_count: it starts at 1, so your node can log which attempt is running — invaluable when a “retried twice” claim needs to survive a code review.
2. RetryConfig anatomy and defaults
Every option, with its default, exactly as the docs specify:
| Option | Default | Meaning |
|---|---|---|
max_attempts | 5 | Attempts including the original. 0 or 1 disables retries. |
initial_delay | 1.0 s | Wait before the first retry. |
max_delay | 60.0 s | Cap on any single wait. |
backoff_factor | 2.0 | Multiplier applied to each subsequent wait. |
jitter | 1.0 | Random spread as a fraction of the wait. 0 = fixed waits. |
exceptions | all errors | Error types that start a retry. |
Two semantics trip people up:
max_attemptscounts the original attempt.max_attempts=3means one try plus two retries, not three retries.- Waits are in seconds (floats allowed), in both
RetryConfigandtimeout.
3. Backoff, jitter, and the wait sequence
With the defaults (initial_delay=1, backoff_factor=2), the base waits are 1, 2, 4, 8 seconds — each later wait multiplied by the backoff factor, capped at max_delay.
Then jitter is applied: ADK “adds or subtracts a random amount, up to the jitter factor times the delay, from each wait.” With the default jitter=1.0, a wait of 4 seconds can be perturbed by up to ±4 seconds. The point is de-synchronization: when fifty nodes fail at the same moment — a provider outage, a cold start — fixed delays would produce fifty simultaneous retries that stampede the service right as it recovers. Jitter spreads them out.
Set jitter=0.0 only when you want deterministic waits, for example in tests where a random delay would make the suite flaky.
4. Retry only the errors that can succeed later
The docs are blunt about the default: “a retry policy retries almost every error.” That includes errors caused by bad input or a bug in your code — which fail identically on every attempt, so retrying them only delays the failure while burning attempts.
The fix is the exceptions list. In Python it accepts exception classes or class names, and a listed class also matches its subclasses:
retry_config=RetryConfig(
max_attempts=4,
initial_delay=0.5,
max_delay=10.0,
exceptions=[
ConnectionError, # matches TimeoutError, OSError subclasses
ServiceUnavailableError, # your domain-specific transient error
NodeTimeoutError, # the node's own timeout, if you want it retried
],
)
Worth retrying: connection errors, rate-limit responses, 5xx from a provider, timeouts. Not worth retrying: ValidationError from a schema mismatch, a KeyError from malformed input, auth failures with a rejected token. Those need a code or config change, not another attempt.
One subtlety: if you list specific error types, timeouts are only retried when you include NodeTimeoutError in that list. A timeout without a retry policy — or with a policy that does not cover it — fails the node the first time it fires.
5. Timeouts: a per-attempt brake
timeout (seconds) limits each attempt separately — not the total across retries, and the wait between attempts does not count toward it. When an attempt overruns, ADK stops it and treats it as a NodeTimeoutError, which the policy may then retry.
Without a timeout, a hung HTTP call with no response blocks the node indefinitely: no failure, no retry, just a workflow that never finishes. Timeouts convert “stalled” into “failed,” which is the precondition for retrying. Together they form the standard pair: the timeout detects the stall, the retry policy decides what to do about it.
6. When retries help — and when they hurt
Retries help with transient failures: a dropped connection, a brief rate limit, a node timeout caused by a slow provider. These have a real probability of succeeding on the next try, and backoff gives the remote system time to recover.
Retries hurt in three specific situations:
-
Non-idempotent side effects. A retry runs the whole node again. If the node charged a card before the failing call, you charged twice. The docs’ guidance: “design those operations so that repeating them has no extra effect, or move the side effect into a separate node that runs after the unreliable call succeeds.” That split — pure fetch node, then a commit node with its own policy — is the cleanest idempotency pattern in a graph:
root_agent = Workflow( name="booking_workflow", edges=[("START", check_availability, reserve_seat, charge_card)], )The flaky call (
check_availability) retries freely; the irreversible call (charge_card) runs once, after the flaky step has succeeded. -
Permanent failures. Retrying a
ValidationErrorfive times with exponential backoff is five times the latency and zero times the success. Narrowexceptionsto transient types. -
Amplification. Retries multiply inside loops:
max_attempts=5in a node that sits in a six-round review cycle is up to thirty executions of that node. Size policies with the graph’s worst case in mind, and prefer attaching the policy to the node that can fail rather than a nested workflow — a policy on a nested workflow retries every node inside it, while a policy on the individual node “retries less work and gives you more control.”
7. One documented limitation
The attempt count is not persisted. ADK keeps it in memory for the current run of the node. If the workflow pauses (for example, for human input) or the application restarts, a node that runs again after resume starts from attempt 1 with all of its attempts available.
If your bounded-retry story must survive a pause — say, a workflow that waits for approval mid-way through a retried step — do not rely on max_attempts alone. Track durable counters in session state (with the right key scope) or design the pause so it lands outside the retried node.
8. Checklist
- Every node that calls a remote service has a
retry_configor a deliberate reason not to. -
exceptionslists only errors that can plausibly succeed later — not validation or logic bugs. -
NodeTimeoutErroris included when timeouts should be retried. - Every attempt has a
timeout, so hangs become failures instead of dead runs. - Retried nodes are idempotent, or side effects live in a separate post-success node.
- Waits use the default jitter unless you are writing tests.
- You know the worst case:
max_attempts× loop iterations × fan-out width.
Retries are the difference between a workflow that survives the weather and one that cancels the run at the first gust. Configure them per node, narrow them to transient errors, keep the side effects out of the retry path — and let backoff with jitter do what fixed sleeps cannot: recover without a stampede.