new·The score now tells you which way it movedA brain's exam only ever grows: its own material writes questions, and so does every question a real caller asked and did not get answered. The score is a percentage over that growing set, so a brain that learned more could post a smaller number — and this week three did. One of them answered two MORE questions than the week before and showed eighteen points less. Printed as a single percentage, that reads as decline to a reader and as punishment to anyone who contributes material.all news →
mozg.beta
Sign in

LangChain · LangGraph · all subjects

testing

9 notes, read out of this brain and free to use. Each one was extracted from a source and is re-checked against its exam.

Test LangGraph: create graph before each test with new checkpointer

A useful pattern when testing LangGraph agents that depend on state is to create your graph before each test where you use it, then compile it within tests with a new checkpointer instance. This ensures isolation between tests.

Test LangGraph: basic agent execution example

Example showing how to test a simple linear graph that progresses through node1 and node2, each updating the state key 'my_key'. Create a StateGraph with typed state, add nodes with lambda functions, add edges from START through nodes to END, compile with a MemorySaver checkpointer, then invoke with an initial state dict and config containing a thread_id in configurable.

Test LangGraph: access individual nodes via graph.nodes

Compiled LangGraph agents expose references to each individual node as 'graph.nodes'. You can access and invoke individual nodes directly to test them in isolation. Note that testing individual nodes this way will bypass any checkpointers passed when compiling the graph.

Test LangGraph: individual node execution example

Example showing how to test a single node by accessing it from a compiled graph via compiled_graph.nodes['node1'].invoke() and passing only the input state, bypassing the full graph execution and checkpointer.

Test LangGraph: partial execution testing pattern

To test partial execution paths within a larger graph without restructuring as subgraphs: (1) Compile your agent with a checkpointer like MemorySaver; (2) Call update_state with as_node parameter set to the node name before where you want to start; (3) Invoke your agent with the same thread_id and an interrupt_after parameter set to the node name where you want to stop.

Test LangGraph: partial execution example

Example testing nodes 2 and 3 of a 4-node graph. Call compiled_graph.update_state() with thread_id in config, the state values to simulate, and as_node='node1' to mark state as coming from node 1 so execution resumes at node 2. Then call compiled_graph.invoke(None, config with thread_id, interrupt_after='node3') to run nodes 2-3 and stop before node 4.

Test LangGraph: prerequisites - pytest for Python

To test LangGraph agents in Python, install pytest using: pip install -U pytest

Test LangGraph: prerequisites - vitest for JavaScript

To test LangGraph agents in JavaScript, install vitest using: npm install -D vitest

Test LangGraph: persistence enables partial execution testing

LangGraph's persistence mechanisms can be used to simulate a state where an agent is paused right before a desired section and will pause again at the end. This allows testing specific portions of larger graphs without modifying the graph structure itself.

Give your agent this brain