LangChain vs LangGraph: what's the difference?
They are not competitors, and picking between them is a category error. LangChain gives you the parts; LangGraph decides the order they run in — and lets you see it.
ON THIS PAGE
Watch the lesson · AI agent frameworks, explained, lesson 3
Also in the course: What is LangChain?, What is LangGraph?
LangChain is a library of integrations and abstractions, with a ready-made agent loop; LangGraph is a way to express an agent's control flow as an explicit graph of state, nodes and edges. LangChain gives you the parts; LangGraph decides the order they run in, and lets you see it. They come from the same people, LangChain's agents now run on LangGraph, and so "which should I pick?" is usually the wrong question. The real one is which layer you need to work in.
First, what an agent is#
An agent is a language model that chooses its own next action, in a loop, against a set of tools, in pursuit of a goal. The model reads the state and picks a tool; the tool runs and its result goes back into the state; the model decides whether to go again. The word that matters is chooses: if your code decides what happens next and the model only fills in text, that is a pipeline, and a pipeline is often the better engineering choice (see What Is an AI Agent?).
Everything a framework adds is scaffolding around that loop. So ask of each one: what does it do to the loop?
What LangChain is for#
LangChain's value has always been breadth: one common interface over model providers, tools, retrievers, document loaders, vector stores and output parsers. When you need to talk to something and would rather not write the client yourself, that breadth is the product. Because every model sits behind the same interface, switching provider is a small change.
Its agent loop is create_agent: give it a model, a list of tools and a system prompt, and you have an agent. A tool is a plain Python function, and its docstring is how the model learns what it does.
from langchain.agents import create_agent
def get_weather(city: str) -> str:
"""Get weather for a given city."""
return f"It's always sunny in {city}!"
agent = create_agent(
model="provider:model-name", # e.g. "openai:…" or "anthropic:…"
tools=[get_weather],
system_prompt="You are a helpful assistant",
)
agent.invoke({"messages": [{"role": "user", "content": "Weather in Lima?"}]})LangChain describes an agent as a model plus a harness: the prompt, the tools, and middleware, which adds behaviour one piece at a time: guardrails, retries, routing between models, rules about which tools may run.
Its weakness is the same breadth seen from the other side. Deep abstraction stacks are hard to debug when a prompt goes wrong three layers down, and the criticism that you end up reading library source to understand your own program is fair more often than its defenders like. Tracing (LangSmith, from the same company) helps a great deal, but it is still worth knowing which layer you are standing on.
What LangGraph is for#
LangGraph is a low-level orchestration framework and runtime for long-running agents that keep state. You declare three things: the state the steps share, the nodes (the steps that exist) and the edges (which moves between steps are allowed). The agent loop stops being implicit in a framework's internals and becomes a graph you drew, and one graph can mix steps a model decides with steps your code decides.
from langgraph.graph import StateGraph, MessagesState, START, END
def mock_llm(state: MessagesState):
return {"messages": [{"role": "ai", "content": "hello world"}]}
graph = StateGraph(MessagesState)
graph.add_node(mock_llm)
graph.add_edge(START, "mock_llm")
graph.add_edge("mock_llm", END)
graph = graph.compile()
graph.invoke({"messages": [{"role": "user", "content": "hi!"}]})Note that this imports LangGraph alone: it does not need LangChain, and its nodes can call any model client you like. Three things fall out of drawing the graph, and they are the reason to use it:
- Inspectable state. You can see what the agent knew at each step, which turns "why did it do that?" from archaeology into reading.
- Durability. Because state is explicit, a run can be checkpointed and resumed, which matters enormously the first time a long-running agent dies half-way.
- Deliberate human gates. A pause for someone's approval is a step in the graph, not a hack bolted on.
Layers, not rivals#
The two now stack. In LangChain's own description of the family:
- Deep Agents: a ready-made harness on top, with planning, subagents, file tools and context management.
- LangChain: the agent framework, with integrations for models and tools and the agent loop. Its agents are built on LangGraph.
- LangGraph: the runtime underneath, with durable execution, streaming, human-in-the-loop and persistence.
- LangSmith: traces and evaluates runs from any of them.
Use create_agent and LangGraph is already running underneath; you may never touch the graph yourself. So the choice is not between two products. It is whether you work in the ready-made loop or in the graph itself.
Four questions that decide it#
- Do you need lots of integrations (models and data sources you would rather not wire up yourself)? Use LangChain's parts.
- Is a standard agent loop enough, a model with some tools?
create_agentis the quick path. - Is an unexpected step expensive? Do you need approvals, or runs that resume after a crash? Write the permitted steps down as a LangGraph graph.
- Are the steps fixed in advance? Then you need neither: that is a pipeline, and plain code does it well. With one model provider and a couple of tools, calling the provider's own SDK is often simpler to read and to debug. See Do You Need an Agent Framework at All?
Put shortly: choose the layer by what goes wrong if the agent takes an unexpected step.
The comparison people actually mean#
Nine times in ten, "LangChain vs LangGraph" is really "LangGraph vs a team of role-playing agents": explicit graphs against agents that work out the coordination between themselves. That is a trade of control against expressiveness, and it is the comparison in CrewAI vs AutoGen.
