All Agent Engineering

Write node and execution-path regression checks for a LangGraph graph

Check a graph without a real model at node, path, and loop-limit level, and leave an acceptance sheet.

AINavWritten / Updated
On this page

At a glance

A LangGraph graph's state, edges, and loops can be checked without a real model. The documentation describes building the graph afresh for each test and compiling it with a new checkpointer, calling single nodes through graph.nodes, running a partial path with update_state plus interrupt_after, and bounding loops with the recursion limit. This note turns the input, a graph under test with node inputs and termination conditions, into an acceptance sheet.

Runtime and applicability

Article type
Engineering practice
Verified
Applies to
  • LangGraph Write node and execution-path regression checks for a LangGraph graph

Execution locations and responsibilities

  • LangGraph graph runtime and application host Use the workflow below to distinguish responsibilities of the caller, runtime, and external actions.
Engineering workflow order
Engineering workflow order1. Prepare a per-test graph fixture → 2. Invoke each node and assert its return → 3. Check conditional-edge routing results → 4. Run the whole graph and assert final state → 5. Isolate a middle section with partial execution → 6. Verify loop termination and the recursion limit. Arrows show the order of checks in the guide. Follow each step’s prerequisites, branches and stop conditions; unexecuted steps are not completed work.1. Prepare a per-test graph fixture2. Invoke each node and assert its return3. Check conditional-edge routing results4. Run the whole graph and assert final state5. Isolate a middle section with partial execution6. Verify loop termination and the recursion limit

Arrows show the order of checks in the guide. Follow each step’s prerequisites, branches and stop conditions; unexecuted steps are not completed work.

When to use

  • A compiled graph exposes its nodes through graph.nodes, so one node can be invoked alone and its return value asserted. The documentation notes this bypasses any checkpointer passed at compile time, so it verifies node logic only, not persistence or routing.

When not to use

  • Calling a node through graph.nodes bypasses the checkpointer, so it cannot show saving, resuming, or interrupt behavior.
  • The documentation gives no syntax for replacing model nodes; how stand-ins are written is a team decision and needs its own review.
  • The default recursion limit changes between versions; this note does not confirm the installed version and only asks that the limit be set explicitly on the sheet.

Prerequisites and input

  • A build function for the graph under test, plus the expected input state and returned partial update for each node.
  • The termination condition of every loop or conditional path, and the maximum super-step count your team wants to allow.

Engineering checks

Node layer: single-node input and output — A compiled graph exposes its nodes through graph.nodes, so one node can be invoked alone and its return value asserted. The documentation notes this bypasses any checkpointer passed at compile time, so it verifies node logic only, not persistence or routing.

Path layer: whole graph and partial execution — A whole-graph check builds the graph per test, compiles it with a new in-memory checkpointer, invokes it with a thread_id, and asserts the final state. To check only a middle section, the documented approach is to call update_state with as_node to simulate the previous node having finished, then invoke with the same thread_id and set interrupt_after. A conditional edge's routing function receives the current state and returns a node name, a list of names, END, or Send objects, so it can also be checked as an ordinary function.

Boundary layer: loops and the recursion limit — The recursion limit caps how many super-steps one run may execute, and exceeding it raises GraphRecursionError. The documentation says to set recursion_limit as a top-level config key, not under configurable; the default differs by version, so the installed version decides it.

1. Prepare a per-test graph fixture

Where: the test file run by pytest. Input: the graph build function. Action: have each test build its own graph and compile it with a new in-memory checkpointer (the documented example uses MemorySaver, and the partial-execution section mentions InMemorySaver), so thread state does not leak between tests. Completion check: no test shares a compiled graph or checkpointer. Stop condition: stop if building the graph needs a real model or network credentials, and swap in deterministic nodes first.

2. Invoke each node and assert its return

Where: the same test file. Input: sample state for each node. Action: take the node from graph.nodes, invoke it, and assert the partial update it returns; replacing model-calling nodes with fixed-value stand-ins is this note's design suggestion, since the documentation gives no replacement syntax. Completion check: each node has at least one normal and one edge-case input with an expectation. Stop condition: stop if a node cannot return without network access.

3. Check conditional-edge routing results

Where: the routing functions and graph definition. Input: state samples that trigger each branch. Action: call the routing function as an ordinary function and compare what it returns, whether a node name, a list, END, or Send; do not use both static edges and dynamic routing on one node, since the documentation says that can run both paths. Completion check: every branch has a sample and a recorded expected destination. Stop condition: stop if a node mixes routing styles and you cannot explain why.

4. Run the whole graph and assert final state

Where: the test file. Input: initial state and a thread_id. Action: compile, invoke the whole graph, and assert the state keys in the result. Completion check: final values match the acceptance sheet and each test's thread identifier is explicit. Stop condition: stop if the result depends on external input that is not fixed.

5. Isolate a middle section with partial execution

Where: the test file. Input: the entry state of the target section. Action: call update_state with as_node set to the node before the section, then invoke with None and set interrupt_after to the section's last node. Completion check: the returned state corresponds to the last node of the section and later nodes did not run. Stop condition: if isolating the section really needs a subgraph, invoke that subgraph on its own and record it separately.

6. Verify loop termination and the recursion limit

Where: the graph with the loop, and its config. Input: states that trigger the repeating path. Action: first check that a satisfied termination condition routes to END; then set a small recursion_limit as a top-level config key, feed a non-converging input, and expect GraphRecursionError. Completion check: both expectations are written on the sheet. Stop condition: if you do not know the default limit of your version, do not rely on it and set the limit explicitly.

Task example

Hypothetical walkthrough (nothing was run): a graph has nodes draft and review; the conditional edge after review goes to END when the draft is acceptable and back to draft otherwise. The acceptance sheet reads: node layer, give review an acceptable sample and expect the routing function to return END; path layer, invoke the whole graph with a fixed thread_id and expect an acceptance flag in the final state; boundary layer, give a draft that never passes, set a very small recursion_limit, and expect GraphRecursionError. These are expectations derived from the documentation; no actual result has been observed.

Completion checks

  • Every node has a sample input and expected return that needs no real model.
  • Every conditional branch has a triggering sample and an expected destination.
  • Every loop has two expectations: normal termination and hitting the recursion limit.
  • Each test builds its own graph and checkpointer, with an explicit thread identifier.

Verification scope

This note relies only on the supplied LangGraph test page and Graph API documentation, which were read. LangGraph and pytest were not installed, no login was made, no API was executed, and no output was produced or verified; the walkthrough and expectations are hypothetical.

Sources

All links are official pages; verification dates are listed per source, and links point to the version checked.

  1. LangGraph · LangGraph documentation: langgraph-test
  2. LangGraph · LangGraph documentation: langgraph-api

Found an error? Tell us →