LangChainGuide
Flat isometric illustration of a glowing blue wireframe polyhedron between two pink block towers, with small pink cubes and spheres on a dark slab.
comparisons

LangChain vs LangGraph: Agents, State and Control Flow

Compare LangChain vs LangGraph for agent loops, state, checkpoints and human approval, with guidance on when to use create_agent or a custom graph.

By LangChainGuide Editorial · ·Updated · 5 min read

LangChain vs LangGraph is a choice about how much agent control flow to define yourself. LangChain provides model and tool integrations plus a ready-made agent loop through create_agent. LangGraph provides the underlying graph runtime and APIs for defining state, nodes and routing. Current LangChain agents run on LangGraph, so choosing LangChain does not mean giving up that runtime’s capabilities.

This guide focuses on that relationship. If your decision is between data frameworks for retrieval, use LlamaIndex vs LangChain: which to use for RAG, the family’s dedicated two-way comparison.

LangChain vs LangGraph: what each layer controls

The LangChain overview describes a framework for building agents with model and tool integrations. Its agent abstraction handles a recurring pattern: call the model, execute requested tools, return results to the model and continue until an answer is ready. You configure the model, tools and middleware around that loop.

The LangGraph overview describes a lower-level orchestration runtime. A custom graph lets you specify where a deterministic step runs, where a model makes a decision, and which state is available to the next node. LangChain components can run inside those nodes, but LangGraph does not require LangChain.

The distinction is between configuring an existing agent architecture and defining the architecture directly. Neither library makes a tool reliable or a retrieved document correct by itself.

Side-by-side comparison

The LangChain column below describes current create_agent, rather than a legacy chain or executor. Capabilities follow the official agent, graph, persistence and approval guides listed in the sources.

DecisionLangChain create_agentCustom LangGraph graph
Starting abstractionModel/tool agent loopState schema, nodes and edges
RoutingSupplied loop, configurable through tools and middlewareExplicit edges and conditional routing
StateAgent state, including messages; can be extendedApplication-defined state with update rules
Conversation persistencePass a checkpointer to the agentCompile the graph with a checkpointer
Human approvalConfigure human-in-the-loop middlewarePlace interrupts in the workflow
Tool and model integrationsProvided by LangChain integration packagesReuse LangChain components or other callable code
Main design taskConfigure the agent’s behaviorDefine the workflow and its state transitions

Persistence and human approval therefore are not reasons, by themselves, to discard create_agent. The deciding issue is whether its loop and extension points express the application you need.

When LangChain create_agent fits

Start here when the application can use a model/tool loop with a known set of tools. The agents guide covers tool definitions, structured output, system prompts and middleware. Those are useful configuration points before writing a custom graph.

For example, a document assistant might have one retrieval tool and return an answer after using its results. Define what the tool returns, what counts as a valid answer, and what should happen when retrieval finds nothing. The LangChain RAG pipeline walkthrough covers the data stages that feed that tool.

If every request always follows the same sequence, a composed pipeline may be enough. An agent loop is useful when the model needs to choose the next action; LangChain building blocks explains that design choice.

When a custom LangGraph graph fits

Use an explicit graph when the workflow itself needs to be modeled: separate retrieval and validation branches, a deterministic review stage, or a route back to a previous step based on application state. The Graph API guide defines nodes, edges, conditional edges and state reducers.

Before implementing it, write down the values each step reads and changes. Decide which updates replace a value and which accumulate results. That makes routing and state handling reviewable independently of a model’s response.

A graph can also contain subgraphs for portions of a workflow with their own structure. This introduces more architecture to maintain, so use it for a concrete control-flow requirement. A larger diagram alone does not make an agent more dependable.

Checkpoints, memory and human approval

A checkpointer records graph state by thread. The persistence guide explains checkpoint inspection, resuming execution and state history. Configure persistence deliberately; an in-memory implementation does not survive process loss.

For an agent built with LangChain, human-in-the-loop middleware can pause selected tool calls for review and supports approval, editing or rejection according to the configured policy. It relies on checkpointing to retain state across the interruption. You do not need to build a custom graph solely to add that review step.

Conversation history and cross-thread facts also need different storage decisions. The LangChain memory types and replacements guide maps legacy memory classes to checkpointers, stores, trimming and summarization.

Where LlamaIndex fits

LlamaIndex is a separate data framework. Its framework documentation covers ingestion, indexing and querying alongside agents and workflows. Keep that data-layer decision separate from how much LangGraph control flow you want to define.

RequirementStarting point
Configure a model/tool loopLangChain create_agent
Define branches and state transitions directlyLangGraph Graph API
Compare document ingestion and query abstractionsThe LlamaIndex vs LangChain RAG comparison linked above

A data framework can supply retrieval results to an orchestration layer. Define the returned content, source metadata and failure behavior at that boundary before combining libraries.

A practical decision checklist

Start by drawing the expected steps for one successful request and one failed request. If both fit a configured model/tool loop, evaluate create_agent. If they require explicit routing between distinct application stages, evaluate the Graph API.

Then identify which state must survive another request, a review pause or a process restart. Choose a suitable persistence backend and make thread identifiers part of the application contract. Pin package versions and check the relevant documentation before changing that contract.

Finally, record tool outcomes and model usage while evaluating representative inputs. The token and agent cost sizer helps compare assumptions about step count and context size. For the diagnostic path when a loop repeats, skips a tool or emits invalid output, read why LangChain agents loop, skip tools, or fail to parse.

Sources

  1. LangChain documentation: Overview
  2. LangChain documentation: Agents
  3. LangGraph documentation: Overview
  4. LangGraph documentation: Graph API
  5. LangGraph documentation: Persistence
  6. LangChain documentation: Human-in-the-loop
  7. LlamaIndex documentation: Python framework

Related