· 8 min read · 1472 words

How to Test and Evaluate LangGraph Workflow Agents: Graph Tests vs LLM Node Evals

When an AI agent is 80% LangGraph StateGraph and 20% model nodes, judging the whole run wastes money while unit tests alone miss contract drift. How we split topology tests from node-boundary evals, diffed 60 days of trace paths, and caught copied rules drifting in two weeks.

Part 4 of Deterministic Workflows vs Autonomous AI Agents in LangGraph.

How to Test and Evaluate LangGraph Workflow Agents: Graph Tests vs LLM Node Evals

When I first wrote the evaluation plan for our upgrade planning agent, the agent was an autonomous orchestrator reading a fixed process from its prompt. So my plan evaluated the whole run end-to-end and explicitly declared individual tool responses out of scope.

Two months later, the team rebuilt it as the deterministic LangGraph StateGraph covered in Parts 1 through 3: order moved into edges, human approvals became interrupt() nodes, planning became a Python compiler, and only per-service impact analysis stayed an LLM worker.

That architecture shift breaks standard LLM eval advice. When an "agent" is 80% deterministic graph and 20% model nodes, running LLM judges over the whole system wastes tokens asserting things code already guarantees, while unit tests alone miss how the model behaves at the node boundary.

Here is the split that actually worked: tests own the graph (zero LLM calls), and evals own the model node boundary, plus the exact gaps where copied contracts, drifted eval inputs, and missing CI triggers still bit us.


Split the work: tests own the graph, evals own the model

One sentence from our post-rebuild engineering strategy settled every debate about what goes in pytest versus what goes in an LLM eval suite:

"Impact analysis is unreachable until scope approves is a topology fact: one deterministic sub-second test. A judge could only ever assert it statistically."

In fact, removing a model call is the highest-leverage evaluation work you can do. When we replaced the LLM planner worker with a deterministic Python compiler, planning dropped to roughly a quarter of the time and a third of the cost, and an entire family of brittle LLM eval datasets vanished into fast unit tests.

Component Before the workflow rebuild After the workflow rebuild
Phase order Judged statistically from trajectories Asserted directly on compiled graph edges
Human approval gates Prompt prose + LLM judge interrupt() nodes tested with Command(resume=...)
Plan generation LLM planner + rubric evals Deterministic compiler + unit tests
Impact analysis Buried inside orchestrator runs Standalone worker evals (contract checks + judges)

Four graph tests worth writing first (zero model cost)

Our workflow carries over seven hundred fast, in-process tests that compile the real graph object production runs using fake tools, fake workers, and an in-memory checkpointer. Four patterns do almost all the heavy lifting:

1. Assert topology, deleted nodes, input schema, and zero accidental LLM calls. Do not just test that a node exists; assert its exact incoming edge sources, assert deleted legacy nodes are gone, assert callers can only seed messages, and inject a fake model that raises RuntimeError("unit test must not call the LLM") if any refactor sneaks a completion into a code node:

# Simplified from the compiled graph test suite
async def test_export_is_only_reachable_from_the_publication_gate():
    graph = await _compile(_workers(), _workflow_tools())
    into_export = {e.source for e in graph.get_graph().edges if e.target == NODE_EXPORT}
    assert into_export == {NODE_PUBLICATION_GATE}

async def test_messages_is_the_only_channel_a_caller_may_seed():
    graph = await _compile(_workers(), _workflow_tools())
    assert set(graph.get_input_jsonschema()["properties"]) == {"messages"}

2. Drive every gate with Command(resume=...) and assert what did not happen. A gate that pauses properly yet fires a side effect before pausing is still broken:

async def test_rejected_scope_analyses_nothing_and_cancels_job():
    workers, tools = _workers(), _workflow_tools()
    graph = await _compile(workers, tools)
    config = {"configurable": {"thread_id": "t2"}}

    await graph.ainvoke({"messages": [HumanMessage(content="upgrade us")]}, config=config)
    await graph.ainvoke(Command(resume="reject"), config=config)

    assert workers["impact-worker"].calls == []
    assert tools["spec_save"].calls == []
    assert tools["job_finalize"].calls[0]["status"] == "cancelled"

3. Use contract fakes (ContractTool), never loose mocks. Every fake tool validates required args, rejects unknown args, and checks allowed enum values against the real server's signature (proving, for example, that the workflow never passes an organization_id override to a job store that derives org from caller identity).

4. Diff real trace path signatures against test paths. Because a StateGraph has a finite set of paths, path coverage is actually measurable. Over a sixty-day trace window on dev and staging, I pulled node names only (no payloads) and collapsed every run plus its resumes into a path signature. Roughly two in five dev runs and three in five staging runs ended at or before the scope gate; about 15% of dev runs reached publication; and every single graph path seen in real traffic matched a compiled graph test. The scan also debunked a false alarm: most "errors" logged on the worker node in dev were actually user cancellations logged with opaque status text, not flaky workers.

Notice two field bugs that still slipped past 700 green tests: a deterministic scope check mistakenly validated the source release series instead of only the target (unit-test gap, invisible to worker evals), and a failed classification step produced an empty estate that approved and closed "successfully" with zero services analyzed ("every path closes the job" is not the same property as "a closed job did real work").

Two-panel diagram showing Graph Tests (topology assertions, Command(resume) gates, ContractTool fakes, trace path-signature diff) on the left and Model Node Evals (input fidelity, programmatic JSON contract checks, contract parity tests, and CI triggers across the boundary) on the right.

Left: deterministic sub-second tests own topology, gates, tool contracts, and real-world path coverage. Right: model-node evals must match the graph's real input, score the machine contract first, prevent copied-rule drift, and trigger whenever the graph changes.


Evaluating the model nodes: four gaps we found at the boundary

Inside the workflow, nobody chats with the impact worker. The fan-out node hands it one fixed message and parses one fenced JSON report (items, check_outcomes, blocker flags). Free-text prose is for humans; the downstream compiler reads only that narrow machine surface.

That boundary gave us four hard lessons:

1. Make the graph parser's acceptance test the node's first eval metric. Before any LLM judge grades faithfulness, programmatic contract checks verify the exact invariants the parser needs:

{
  "M-IMPACT-JSON-PROG": [
    {"type": "impact_fence_only", "strict": true},
    {"type": "impact_json_parseable", "strict": true},
    {"type": "impact_no_tools_after", "strict": true},
    {"type": "impact_json_path", "strict": true, "path": "$.check_outcomes", "min_length": 7},
    {"type": "impact_json_path", "strict": true, "path": "$.items", "present": true}
  ]
}

2. Check whether your eval sends what the graph actually sends. To isolate which of the worker's four internal phases broke, our team built phase-specific eval sets using seeded prior turns and instructions like "Stop after Phase 3". When I audited every row in the worker datasets against the graph's real impact_task() builder, 0% of eval cases sent the graph's exact production message, roughly 90% injected eval-only phase-stop framing, and two thirds used seeded turns. Phase sets are awesome for blaming a specific phase; they do not prove a cold production delegation works. You need both: phase sets for diagnosis, plus a small verbatim set generated directly by calling the graph's own impact_task() function.

3. Never copy contract code across the eval boundary without a parity test. To fail worker reports containing unresolved placeholders (${, <todo>, {), we wanted the eval to mirror the workflow compiler's has_placeholder() check. Importing app code broke hermetic eval loading, so we copied the tuple into the eval package with a "Keep in sync" comment. Two weeks later, the workflow updated its rule to allow Gradle version-range braces and Kotlin string templates; the eval copy stayed frozen. Running both functions side by side on eight inputs disagreed on 3 of 8 cases. Either write a shared parity test over a common table of inputs, or do what our mobile eval suite did: commit a file-hash attestation in CI that fails whenever the workflow's prompt builder changes until someone re-attests.

4. Wire CI triggers across the graph-to-worker seam. Originally, worker smoke evals ran only when files inside the worker's folder changed. Editing the workflow graph (including switching the default impact worker to a brand-new implementation) triggered zero worker evals. We added a CI rule running both worker smoke sets on workflow changes, plus a test guarding that trigger rule so it cannot silently vanish.

And one final note on Shape 2 (the single tool-less schema-bound model turn from Part 1): it has no user chat turn and no tools, only a packed evidence packet in and a Pydantic object out (much like a DSPy signature). Score it at its own input/output interface using the exact prompt shipped by the graph, rather than burying it inside noisy full-workflow runs that mix live tools, org data, and model accuracy into one muddled number.


What I am still going back and forth on

Our biggest open hole is whole-workflow evaluation past a human gate. Our eval runner handles interactive agents by stubbing tool-shaped questions, yet a LangGraph interrupt() is a graph pause with no tool to stub. Adding Command(resume=...) support to our eval runner is on the list and still unbuilt, which means we still have zero automated live end-to-end eval crossing a human gate.

I also still wonder how much to rely on a single live release-candidate run versus investing in recorded tool-replay fixtures. Live runs catch real integration breaks and drift whenever the underlying knowledge graph shifts; recorded snapshots give crisp regression diffs and never catch an upstream schema surprise. Most real teams eventually end up needing both.


Test code like code, evaluate models at the contract

When you move an enterprise process into a LangGraph StateGraph, resist two opposite traps: do not waste LLM judges re-checking deterministic graph topology, and do not assume 700 green unit tests over fakes prove your model nodes still honor the graph's contract.

Assert your edges, resume your gates, diff real trace path signatures against your tests, generate verbatim eval inputs from the graph's own task builder, guard copied rules with parity tests, and trigger worker evals whenever the graph changes.

Read the full series: Part 1: Workflow vs AI Agent Decision Guide · Part 2: StateGraph, interrupt() Gates, and Durable Jobs · Part 3: Parallel Fan-Out with Send and Nested Workers · Part 4 (you are here).

Related writings