Retry Policies
Trying again.
Network calls fail now and then. A model provider is busy, or a stock service times out. Often, simply trying again a moment later works. A retry policy does that for one node, automatically.

- Calls fail sometimes
- Trying again often works
- Automatic retries
A node that retries
The flaky stock node fails twice, with a connection error, then succeeds. We add it with a retry policy, allowing three attempts, with a short wait between them. Run it. The first two attempts fail quietly, the third succeeds, and the graph finishes normally.
from typing import TypedDict
from langgraph.graph import StateGraph, START
from langgraph.types import RetryPolicy
class State(TypedDict):
stock: str
attempts = {"n": 0}
def check_stock(s):
attempts["n"] += 1
print("attempt", attempts["n"])
if attempts["n"] < 3:
raise ConnectionError("stock service busy")
return {"stock": "Dune: 3 copies"}
b = StateGraph(State)
b.add_node("check_stock", check_stock, retry_policy=RetryPolicy(max_attempts=3, initial_interval=0.1))
b.add_edge(START, "check_stock")
print(b.compile().invoke({}))attempt 1
attempt 2
attempt 3
{'stock': 'Dune: 3 copies'}Retry settings
Max attempts caps the tries. Initial interval is the first wait, and backoff factor makes each wait longer. Retry on chooses which errors to retry. By default, LangGraph retries likely temporary errors, like connection problems, and not bugs in your code.
| key | value |
|---|---|
| max_attempts | how many tries |
| initial_interval | first wait |
| backoff_factor | waits grow |
| retry_on | which errors |
Summary
A retry policy on a node retries temporary failures automatically. Set the attempts and the waits. Next, handling errors that retries can't fix.
Key takeaways- RetryPolicy
- max_attempts
- Temporary errors only