Skip to main content
Nodes are the steps of a Graph API graph. This page covers how to attach runtime configuration, retries, timeouts, error handlers, defaults, and caching when you add a node. For wiring nodes into sequences, branches, and loops, see Control flow. For the full retry, timeout, and error lifecycle, see Fault tolerance.

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:
  1. Specify a schema for your configuration
  2. Add the configuration to the function signature for nodes or conditional edges
  3. Pass the configuration into the graph
See below for a simple example:
Choose OpenAI or Anthropic at invoke time. These examples call live providers and need API keys.
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. Pass retryPolicy to addNode. An empty object uses the built-in defaults:
Retries are opt-in: without a retryPolicy, the first failure ends the attempt. If the policy omits retryOn, LangGraph retries thrown errors except:
  • Abort and cancellation errors (error.name === "AbortError", or error.message starts with "Cancel" or "AbortError")
  • GraphValueError, matched by error.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")
See Fault tolerance for the full default list and parameters.
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.
Pass 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:
When a node exceeds its timeout, LangGraph raises 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.
Pass errorHandler to addNode on StateGraph (not the base Graph class). The handler runs after retries are exhausted and can route with Command:
See Fault tolerance for compensation patterns and Command routing.

Set graph-wide node defaults

Requires @langchain/langgraph v1.4.0 or later.
Use 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 via config.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

Use executionInfo 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, use executionInfo 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 via config.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:
  1. Pass a cache when you compile the graph (for example, InMemoryCache). SqliteCache is also available in Python.
  2. Attach a CachePolicy on 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.
You can also set cachePolicy (and other node options) once for the graph with setNodeDefaults. See Set graph-wide node defaults.

See also