Add runtime configuration
Pass values into a run (for example, which LLM or system prompt to use) without putting those values in graph state. To add runtime configuration:- Specify a schema for your configuration
- Add the configuration to the function signature for nodes or conditional edges
- Pass the configuration into the graph
Extended example: specifying LLM at runtime
Extended example: specifying LLM at runtime
Choose OpenAI or Anthropic at invoke time. These examples call live providers and need API keys.
Extended example: specifying model and system message at runtime
Extended example: specifying model and system message at runtime
Configure both the model provider and a system message at invoke time. These examples call live providers and need API keys.
Add retry policies
Attach a retry policy when a node calls an API, database, or LLM that can fail transiently. PassretryPolicy to addNode. An empty object uses the built-in defaults:
retryPolicy, the first failure ends the attempt. If the policy omits retryOn, LangGraph retries thrown errors except:
- Abort and cancellation errors (
error.name === "AbortError", orerror.messagestarts with"Cancel"or"AbortError") GraphValueError, matched byerror.name- Aborted connections (
error.code === "ECONNABORTED") - HTTP client errors with status 400, 401, 402, 403, 404, 405, 406, 407, or 409
- OpenAI-style quota errors (
error.error?.code === "insufficient_quota")
Extended example: customizing retry policies
Extended example: customizing retry policies
These snippets show how to attach different retry policies. They do not create database tables or invoke the graph.Pass different retry policies to a model node and a SQL node. The example uses Node.js built-in
node:sqlite (Node.js 22.5 or later):Set node timeouts
Requires
@langchain/langgraph v1.4.0 or later.timeout to addNode to cap how long a single node attempt may run. Use a number (milliseconds) or a TimeoutPolicy for separate run and idle limits:
NodeTimeoutError, clears writes from the failed attempt, and lets the retry policy decide whether to retry. The timeout applies to each attempt independently.
See Fault tolerance for the full timeout lifecycle, idle-timeout refresh sources, and heartbeats.
Handle node errors
Requires
@langchain/langgraph v1.4.0 or later.errorHandler to addNode on StateGraph (not the base Graph class). The handler runs after retries are exhausted and can route with Command:
Command routing.
Set graph-wide node defaults
Requires
@langchain/langgraph v1.4.0 or later.setNodeDefaults to set retryPolicy, timeout, cachePolicy, or errorHandler once for every node in a graph, instead of repeating them on each addNode call. Per-node values always win, and defaults are applied at compile time:
retryPolicy and timeout defaults apply to every node, including error-handler nodes. cachePolicy and errorHandler defaults apply only to regular nodes. Handlers never catch themselves, and caching a handler result is unsafe. Defaults are not inherited by subgraphs.
See Fault tolerance for the full precedence rules and applicability table.
Access execution info inside a node
Access execution identity and retry information viaconfig.executionInfo on the node’s second argument (LangGraphRunnableConfig). This surfaces thread, run, and checkpoint identifiers as well as retry state.
Access thread and run IDs
UseexecutionInfo to access the thread ID, run ID, and other identity fields inside a node:
Adjust behavior based on retry state
When a node has a retry policy, useexecutionInfo to inspect the current attempt number and switch to a fallback after the first attempt fails:
executionInfo is set once the node task is prepared. Even without a retry policy, nodeAttempt defaults to 1, and nodeFirstAttemptTime is set when the node starts executing.
Access server info inside a node
When your graph runs on LangGraph Server, you can access server-specific metadata viaconfig.serverInfo.
serverInfo is undefined when the graph is not running on LangGraph Server.
Requires
@langchain/langgraph v1.2.8 or later.Access drain state inside a node
When a graceful shutdown has been requested,runtime.control?.drainRequested is true. Read this inside a node to skip expensive work before the next superstep boundary:
See Graceful shutdown for the full
RunControl API.Add node caching
Use node caching when a step is expensive and you want to reuse results for the same input. To enable caching:- Pass a cache when you compile the graph (for example,
InMemoryCache).SqliteCacheis also available in Python. - Attach a
CachePolicyon the node.
CachePolicy options:
keyFunc: Function that builds a cache key from the node input.ttl: Time to live in seconds. When omitted, the cache entry does not expire.
cachePolicy (and other node options) once for the graph with setNodeDefaults. See Set graph-wide node defaults.
See also
Connect these docs to your agent of choice via MCP for real-time answers.

