ProdCraft
Subscribe
AI Agents

LangGraph Agent Workflow Tutorial: State, Nodes, Checkpoints and Human Review

Understand LangGraph StateGraph workflows, tool nodes, checkpointing and human-in-the-loop design through a bounded support example.

ProdCraft5 min read
ProdCraft featured image — LangGraph Agent Workflow Tutorial: State, Nodes, Checkpoints and Human Review

LangGraph Agent Workflow Tutorial: State, Nodes, Checkpoints and Human Review is a hands-on guide for AI developers who need a dependable system rather than another chatbot demonstration. It presents a reproducible setup path, a realistic workflow, tests for failure, and the controls that matter when generated text meets real users or external tools. Choose a model and SDK version supported by your account and validate all behavior in a non-production environment.

Why an explicit graph can beat a free-running loop

Some AI tasks require branching but not unlimited autonomy. An invoice assistant might extract fields, validate a vendor ID, request a human decision for ambiguous cases, then store an approved record. A graph of named steps makes this behavior inspectable. LangGraph provides stateful workflows for such applications, but it is not mandatory for every chatbot. Start by writing the states and transitions on paper. If you cannot explain when a step runs or how the flow ends, adding a graph framework will not solve that ambiguity.

Install the library and define state

Create a virtual environment and install the currently supported langgraph package with compatible Python dependencies. A basic example defines a typed state holding ticket_text, classification and approved. In the Python library, StateGraph builds a graph whose nodes read and update state. Use the current project quickstart for exact constructor and compiler syntax, since frameworks change APIs. Keep authentication context outside model-editable state fields or enforce it as immutable server-side data.

Split the process into small nodes

Define a classify node, a validate node and a finalize node. The classify step may call a model but should return only structured classification fields. The validation step checks those fields against deterministic business rules. If the category is unknown or a requested action carries risk, route to human review instead of automatically continuing. Your code—not the model’s prose—should implement the conditional branch. Draw a start node, branches and an end state; use names that a support engineer can recognize while reviewing a trace.

Understand checkpoints and durable execution

A production workflow may be interrupted while a human reviews an approval. A checkpointer can persist state so work can resume without repeating every earlier step. Persistence is not automatically correct: you need stable workflow IDs, state versioning, expiration policy and authorization for who may resume a run. Some stages may have already written to databases; replaying them without idempotency can create duplicate tickets or charges. Design side effects around explicit transaction IDs and repeat-safe execution, and test restart after every sensitive step.

Use human review where it materially matters

Human-in-the-loop review makes sense when the workflow would otherwise change customer state, approve payments or act on ambiguous information. Present the reviewer with the relevant inputs, evidence and proposed action; do not require them to accept a model-generated claim without context. The approval must be bound to the exact action and parameters, not a generic “continue” button that later permits changed arguments. Record who approved and when, while respecting privacy retention rules. Allow the reviewer to reject or modify a proposed action safely.

Test branches and operational failure recovery

Construct cases that follow each branch: approved classification, missing source data, invalid state, timed-out model call, interrupted checkpoint and denied human approval. Assert the final state and whether any side effect occurred. Track node execution durations, retries, model costs and error categories. If model output fails a schema, route back through bounded repair or human review instead of looping forever. Upgrade library versions only after checkpoint compatibility and state migration testing. A graph is useful when it gives you clearer control, not merely because it looks sophisticated in an architecture diagram.

Practical acceptance test: prove the application works

Build a small test fixture before allowing real customers to interact with the system. Include a typical request, a confusing request, an explicitly out-of-scope request and a deliberately malformed input. Define the acceptable answer shape and whether the system should abstain, return a validation error or request approval. Record the exact model identifier, prompt revision and configuration used. When the assistant can invoke a tool, mock that tool in unit tests and prove that authorization is checked even when the model proposes an unauthorized argument. Include at least one request with adversarial instructions inside user-provided data.

After local tests, use a staging environment with synthetic or sanitized data to check network, credentials, health routes, timeouts and monitoring. Avoid interpreting the ability to generate plausible sentences as a successful end-to-end task. A good release criterion measures task completion and safe failure behavior in the same suite.

Production engineering checklist

Protect provider credentials and tool tokens, scope permissions to authenticated identities, and establish limits for request length, concurrency and cost. Separate read-only information retrieval from state-changing operations. Add predictable timeouts, bounded retries for transient errors, monitoring of upstream status and a process for disabling compromised integrations. Avoid retaining sensitive prompts unless necessary, protected and documented. Keep deployment configuration in reviewable version control and use tests to catch changes in schema or model behavior. If the system influences payments, legal obligations, hiring or other significant decisions, include appropriate human oversight and clear boundaries.

Frequently asked questions

Can an API key be placed in a Docker image or source file?

No. Treat it as a secret and inject it at runtime through an approved secret-management mechanism. Rotate leaked keys and prevent their appearance in build logs, telemetry and repositories.

How can I avoid unsupported or unsafe model output?

Restrict the task, use typed responses where possible, verify claims or permissions against trusted systems, test refusals and anomalies, and require confirmation for consequential actions. A good prompt helps, but deterministic application controls remain essential.

Documentation and further learning

Follow the official API or tooling documentation for version-specific examples and supported features. Our guides to RAG evaluation and prompt injection defense provide complementary approaches for testing evidence quality and tool trust boundaries.

Checkpoint recovery exercise

Use a disposable support workflow whose classification node finishes before a simulated human-review step. Persist its state through a supported checkpointer and stop the worker before review completes. Restart the process with the same workflow identifier and resume the approved path. Confirm the initial classification is not recomputed unexpectedly and no state-changing operation is repeated twice. If your node performs writes, add idempotency protection so a restart cannot duplicate the operation.

Next, reject the review and verify that the workflow ends without executing finalization. This makes graph control flow, persistence and human authority testable. Upgrade LangGraph only after checking your persistence backend and state schema compatibility. For permissions on the downstream tools, use our safe function-calling tutorial.

Share this article

Written by

ProdCraft

ProdCraft publishes practical engineering guides on DevOps, Kubernetes, Docker, Linux, databases, cloud and LLMs — written for engineers who ship.

227 articles View profile

The weekly ops & AI brief

One email a week with the best new guides, tools and incident write-ups. No spam, unsubscribe anytime.

Leave a Reply

Your email address will not be published. Required fields are marked *