Agentic AI with LangGraph: build around state, control, and recovery

Agentic AI with LangGraph: build around state, control, and recovery

Key takeaways

  • LangGraph is a low-level runtime for stateful agents.
  • Use it when state, branching, recovery, intervention, or durability must be explicit.
  • For basic tool use without durable checkpoints or human approval, a plain loop may be enough.

The architecture decision comes before the framework decision. Start with the operating responsibilities your workflow must carry. If the work needs visible routes, resumable pauses, or durable state, a graph can give those responsibilities an explicit home. If it does not, graph structure can become work that the workload never asked for.

LangGraph is a runtime for stateful agent workflows

LangGraph is an agent runtime and low-level orchestration framework for stateful agents. That description is more useful than treating it as a general label for any system that calls tools. The framework belongs at the runtime and orchestration layer, where state and execution paths need to remain legible as an agent works.

This distinction changes the first design question. Do not begin with, "How many nodes should this graph have?" Begin with the state that must persist and the decisions that can change the route. Then ask what must happen after a failure, where a person may intervene, and whether the run must resume later. Those are orchestration concerns. A graph is justified only when the workload actually has them.

The langchain-ai/langgraph repository uses the MIT License. That fact applies to the repository license. It does not make licensing a substitute for architecture fit.

This is also why "agentic" is too broad to settle the choice. Some agents can run as a short loop. Others need stateful execution with branches that stay visible outside the prompt. The work, not the label, decides.

Can LangChain create agentic AI?

Yes. A simple AI agent can be built with LangChain and Groq. LangGraph is not a prerequisite for every agent, and LangChain is not merely a stepping stone that must eventually be replaced by a graph.

The sharper comparison is workload shape. LangChain suits linear LLM workflows, while LangGraph is designed for stateful, looping AI agents. A linear workflow can still call a model and use tools. A looping workflow has a different operating problem because an earlier result can send execution back through part of the system.

That gives you a practical boundary:

  • Choose a linear LangChain workflow when the work follows a direct sequence and does not require graph-managed loops.
  • Consider LangGraph when the agent must carry state across a loop and route work according to that changing state.

Neither choice is a maturity level. Adding a graph does not make an agent more agentic by itself. It makes state and looping part of the architecture. If those responsibilities are absent, the extra structure has no workload to serve.

The same distinction helps with a common naming problem. "LangGraph AI agents" can refer to agents whose execution is organized as a stateful graph. "Agentic AI using LangGraph" is therefore an implementation choice, not a separate class of intelligence. If you are still deciding whether the work is a fixed sequence or a stateful loop, settle that boundary before choosing APIs.

For a separate look at this underlying distinction, see our guide to agentic workflows versus AI agents.

What are the limitations of LangGraph?

LangGraph should be selected for workflow-complexity fit, not used as a universal default. Test the workload before committing to graph structure.

Choose LangGraph for explicit state, branching, or recovery; simpler workloads may fit a plain loop, schema-first system, or DSPy.

Use this graph-or-simplify checklist before implementation:

OptionBest-fit workloadBoundary that rules it inTradeoff
Plain SDK or ReAct-style loopBasic tool useDurable checkpoints and human approval are unnecessaryGraph structure would add an orchestration layer the workload does not require
Schema-first systemStructured extraction and validation-heavy tasksThe central job is producing and validating structured outputIts focus is schema and validation, not stateful workflow control
DSPyMetric-guided prompt or program optimizationOptimization against a metric is the primary goalIts focus is optimization, not explicit workflow routes and recovery
LangGraphStateful workflows with branching and recoveryExplicit state, branching, failure recovery, human intervention, or durable workflow state is requiredIts structure may exceed what basic tool use, extraction, or optimization needs

Before adding a node, write down the operating job it owns. State management, a branch, failure recovery, an intervention point, and durable workflow state are concrete jobs. If the proposed node owns none of them, it is a sign to simplify the design. This keeps the decision tied to workflow behavior instead of framework ambition.

How do you build agentic AI with LangGraph?

Build the smallest graph that makes changing execution state visible. A compact LangGraph example can use Python-function nodes, edges between nodes, conditional edges for dynamic routing, and a dictionary that holds execution results and chat history.

Picture a tool-using workflow with four components:

  1. A Python-function node receives the current work.
  2. An edge connects that node to a tool or resource step.
  3. The result is recorded in the state dictionary alongside chat history.
  4. A conditional edge routes execution according to the updated state.

That is enough to show the essential mechanism without turning the example into a feature tour. The nodes identify units of work. Edges make their connections visible. The conditional edge carries the route decision. The dictionary gives execution results and chat history an explicit place to live.

Now follow one conceptual pass. The first Python-function node works from the state dictionary. A connecting edge moves execution to the tool or resource step. The returned result joins the execution state. A conditional edge then selects a route from that updated state. If the route returns to an earlier node, the agent has a visible loop. If it moves forward, the same state still carries the execution result and chat history into the connected work.

This component map is useful because it separates four decisions that are easy to compress into one prompt. What work belongs in a node? Which connection is fixed? Which result changes the route? What state must be available when that route is evaluated? Answer those questions with the smallest set of nodes and edges that represents the workload.

An agentic architecture may iterate while an agent fetches tools and resources, updating a reasoning model multiple times with data, context, or prompts. In a graph, that repeated interaction can be represented as a route through connected nodes instead of being buried inside one opaque call.

A working example can use Python-function nodes, connecting edges, conditional edges, and dictionary state. The point is not to copy its topology. The point is to assign each primitive one job in your own workload.

Yes, it is possible to build your own AI agent, and LangGraph can be used to develop AI agents. The more useful question is whether your agent needs this stateful graph shape. Our guide to building agentic workflows can help you define the workflow before its graph hardens into code.

Graph boundaries become product behavior

Once the basic graph exists, every added construct should own a concrete behavior. Typed state, conditional routing, deterministic tools, retries, interrupts, checkpoints, and traces can all be combined in one LangGraph workflow. They should not be added as a bundle by habit.

A SQL repair loop

A LangGraph workflow can implement SQL analytics with repair loops. The operating job is the repair route: an execution result can lead the workflow through another pass instead of ending the run. Put that route in the graph when the loop itself must be visible and controlled.

The important design choice is not the name of the repair node. It is the state that lets the workflow distinguish the current result from the work that must be attempted again. Typed state gives that information a declared place. Conditional routing gives the repair path an explicit connection. Retries can then belong to workflow structure instead of an instruction hidden inside a prompt.

Review this loop as a route, not as a promise of a correct result. The graph can expose the repair attempt, the state it reads, and the branch it follows. That visibility is the value of this pattern. It does not turn repair into a guarantee.

An evidence gate for retrieval

A LangGraph workflow can also implement retrieval-augmented generation with evidence gating. Here, the key boundary is the conditional route. Retrieved evidence can pass through a gate before the workflow proceeds along the route that follows it.

This example differs from a repair loop. The graph is not merely repeating a failed step. It is representing a decision point around evidence. The route becomes inspectable because it exists as graph structure. That keeps the gate separate from whatever language the model generates.

The gate also gives a trace a meaningful event to record: which route followed the evidence decision. The trace can show the path. The conditional edge still owns the route itself. Keeping those responsibilities distinct prevents observability from being mistaken for control.

Routes, pauses, and traces

LangGraph patterns can make routes, pauses, and audit trails explicit product behavior instead of hidden prompt logic. A route determines where execution can go. An interrupt gives a pause a defined place. A checkpoint supports recovery. A trace records the path the workflow took.

These constructs can work together, but they own different responsibilities. A trace does not create a recovery point. A checkpoint does not decide which route should run. An interrupt does not define the permission policy around a tool. Keeping those jobs explicit makes it possible to inspect the workflow as an operating system, not just read the prompt and guess what might happen.

A useful design review can therefore move construct by construct. For typed state, identify what execution information the workflow carries. For a conditional edge, identify the route decision. For a retry, identify the work that may run again. For an interrupt and checkpoint, identify the pause and recovery path. For a trace, identify the execution path that must remain visible. The graph stays readable when each answer is concrete.

This is the central harness-engineering move: treat repair, validation, routing, interruption, persistence, and tracing as software responsibilities. LangGraph is useful when the graph gives those responsibilities a clearer boundary than a plain loop can.

What happens when a run pauses or the process restarts?

Failure pathRequired mechanismResulting behavior
Policy review interrupts an active runInterrupt plus checkpoint recoveryThe workflow pauses at the review boundary and can recover from the checkpoint
The process restarts before the run resumesFor HITL, a durable checkpointerThe pause and resume state can survive the process restart

The table exposes two separate tests. First, decide whether policy review needs a real interruption point. Second, decide whether the paused run must remain resumable after its process restarts. The second requirement changes the persistence choice.

An interrupt and checkpoint can pause and resume a review, while surviving a process restart requires a durable checkpointer.

An in-memory checkpointer can suit local development. It does not satisfy a production requirement for pause and resume that survives process restarts. If that durability matters, make the checkpointer decision part of the architecture rather than a late deployment detail.

This is where a diagram that looks complete can still hide an unfinished recovery design. A node labeled "review" says where review appears, but it does not by itself establish durable resume. Ask what state is checkpointed at the interrupt, and whether the selected checkpointer can carry that state across a restart. Those questions turn a nominal human-in-the-loop box into a defined failure path.

Tool authority is part of the design

Orchestration does not settle who may use a tool or which credentials a run may carry. Credential sharing, static tokens, overly broad access, and overused human-in-the-loop approvals are poor identity and access management practices that revive known vulnerabilities in agentic systems.

Treat those four failure modes as architecture questions:

  • Does the run rely on a shared credential?
  • Is a static token carrying authority through the workflow?
  • Is tool access broader than the work requires?
  • Are approvals being used so often that they have become the access model?

An interrupt is a workflow mechanism, not a complete authorization design. Adding approval everywhere does not repair weak identity and access choices. Keep permissions, state, checkpoints, and intervention boundaries visible as separate parts of the harness.

Apply the graph-or-simplify checklist to your current design. Record any interruption and durable recovery requirements. Then compare the resulting boundaries with our guide to designing a LangGraph autonomous agent's operating envelope.

More from Lab Notes.