LangChain vs LangGraph
LangChain and LangGraph are two closely related open‑source projects that often cause confusion among developers entering the agentic AI space. LangChain is a general‑purpose framework for building applications powered by large language models, providing abstractions for prompts, chains, memory, retrieval, and agents. LangGraph is a low‑level, graph‑based orchestration framework that emerged from the LangChain ecosystem to address the limitations of traditional linear chains for complex, stateful, and long‑running agent workflows.
Understanding the difference is critical: LangChain helps you compose LLM calls with tools and data retrieval; LangGraph helps you control the flow of an agent’s thought‑action loop with full state persistence, branching, and human‑in‑the‑loop. This guide clarifies their relationship, compares their architectures, and helps you decide when to use each—or both—in production.
What is LangChain?
LangChain is a modular framework for building LLM‑powered applications. Its core idea is to provide standardized, composable components that developers can chain together to create complex behavior. These components include:
- Prompts: Templating and management of prompts.
- Models: Wrappers for LLM providers (OpenAI, Anthropic, etc.) with unified interfaces.
- Chains: Sequences of calls to LLMs or other utilities. Chains can be simple (prompt → LLM → output) or more complex.
- Retrievers: Interfaces for document retrieval from vector databases, web search, etc.
- Memory: Classes for storing and managing conversation history (buffer, summary, vector‑backed).
- Tools: Abstractions for functions that models can invoke.
- Agents: Higher‑level constructs that use a language model to decide which tools to use and in what order, implemented via a reasoning loop (ReAct, OpenAI functions).
LangChain introduced the LangChain Expression Language (LCEL) to declaratively compose runnables (prompts, models, parsers) in a chain‑able fashion, offering automatic parallelization, streaming, and tracing.
LangChain excels at building RAG (retrieval‑augmented generation) systems, chatbots, document Q&A, and simple agent loops where the flow is mostly linear. However, its original AgentExecutor loop had limitations: it was difficult to add custom branching, persistent state, or complex human‑in‑the‑loop patterns. This motivated the creation of LangGraph.
What is LangGraph?
LangGraph is a graph‑orchestration framework for building stateful, multi‑actor applications with LLMs. It models application logic as a StateGraph: a directed graph where each node represents a computational step (LLM call, tool execution, condition check), and edges define the transitions between them. A shared State object propagates through the graph, updated by reducers that handle concurrent writes.
Key features:
- Cyclic graphs: Natural for agent loops (model → tool → model → …).
- Conditional routing: Edges can be dynamic; the next node is determined by evaluating a function on the current state.
- Checkpointing: After every node execution, the entire state is saved to a persistent store (Postgres, SQLite). This enables pause and resume, time‑travel debugging, and durable execution across restarts.
- Human‑in‑the‑loop: The
interruptfunction suspends execution at a node, waits for external input, then resumes from the exact checkpoint. - Parallelism: The
SendAPI fans out to multiple nodes concurrently.
LangGraph is essentially a workflow engine for LLM applications. It does not prescribe what the nodes do; they can use LangChain components, raw API calls, or any Python logic. This makes it highly flexible but also shifts more design responsibility to the developer.
Relationship Between LangChain and LangGraph
LangGraph is built on top of LangChain’s ecosystem but can be used independently. The typical evolution is:
- LangChain (chains, tools, memory, retrievers) → used inside LangGraph nodes for the actual LLM interactions.
- LangGraph provides the orchestration layer: state management, control flow, persistence, and human‑in‑the‑loop.
Many production agents combine them: LangChain components handle the heavy lifting of model calls, retrieval, and tool execution; LangGraph weaves them into a robust, stateful workflow. However, LangGraph is not dependent on LangChain—you can write nodes with raw LLM client calls if you prefer.
When you need a simple linear flow (prompt → model → output), LangChain alone suffices. When you need cycles, branching, long‑running stateful agents, or complex human approvals, LangGraph becomes the better choice.
Architecture Comparison
| Feature | LangChain | LangGraph |
|---|---|---|
| Execution Model | Sequential chains or agent loop (AgentExecutor) | State machine: graph traversal with state |
| Workflow Orchestration | LCEL or predefined chain patterns | Fully customizable graph nodes and edges |
| Control Flow | Linear, with limited branching via routers | Arbitrary: conditional edges, cycles, parallel nodes |
| State Management | Ephemeral conversation memory; not persistent | Built‑in State object persisted via checkpointing |
| Retries | Manual; can add fallbacks in LCEL | Node‑level retry policies; custom error edges |
| Memory | Dedicated memory classes (buffer, summary) | State can include any data; memory is just part of state |
| Checkpoints | None | Automatic after every node; supports pause/resume |
| Persistence | External DBs for long‑term memory | Checkpoints stored in Postgres/SQLite; state durable across restarts |
| Human Approval | Not built‑in; requires custom tool or loop | interrupt + resume; survives restarts |
| Streaming | LCEL supports streaming tokens | Streaming from nodes; custom event streaming |
| Multi‑Agent | Basic agent delegation (via tools) | Subgraphs, supervisor patterns, map‑reduce |
Workflow Comparison
Consider a typical agent workflow: user asks a question → agent plans → calls tools → uses memory → returns final answer.
LangChain (AgentExecutor):
User Input → AgentExecutor loop:
1. LLM decides action (tool or final)
2. If tool: execute tool, feed observation back
3. Repeat until Final Answer
→ Output
The loop is built‑in, with limited customization. Adding conditional logic (e.g., “if tool returns empty, try a different tool”) requires subclassing.
LangGraph:
User Input → Graph:
Node: agent (LLM) → conditional edge:
if tool call → tool node → loop back to agent
if end → end
Node: tool (executes) → updates state
→ Output
The developer defines each node and transition. Conditional edges can evaluate the state and decide next steps. A human approval node can be inserted easily.
LangGraph makes the loop explicit and gives full control over what happens at each step, including error handling and parallel tool execution.
State Management
State management is the most significant differentiator.
-
LangChain: Conversation memory (e.g.,
ConversationBufferMemory) persists history in memory or a database, but the agent loop itself is stateless. If the process crashes, you lose the current step and must restart the entire chain. There is no built‑in mechanism to pause an agent and resume it later. -
LangGraph: State is the core concept. The
StateGraphdefines a typed schema, and after each node execution, the entire state is saved to a checkpointer. This means:- Durable execution: The graph can be halted (intentionally or due to crash) and resumed from the last checkpoint.
- Time‑travel debugging: You can load a past state and replay from that point.
- Branching: Create alternative execution paths from any checkpoint.
Engineering implications:
- For short‑lived, non‑critical agents (e.g., simple chatbot), LangChain’s memory is sufficient.
- For long‑running workflows (e.g., a loan approval that takes days), LangGraph’s checkpointing is essential.
Tool Calling
Both frameworks support tool calling, but they differ in control and integration.
LangChain: Tools are defined with the @tool decorator or using Pydantic models. The agent binds tools to the LLM and the executor handles the calling loop. MCP (Model Context Protocol) servers can be integrated as tools.
LangGraph: Tools can be the same LangChain tools or any Python callable. In a graph, tool execution is a separate node (or nodes). This gives you the ability to:
- Add retry logic around tool calls.
- Call multiple tools in parallel using
Send. - Implement fallback tools if primary fails.
- Validate outputs before passing them back to the LLM.
Example LangGraph tool node with retry:
from langgraph.graph import StateGraph
from langgraph.prebuilt import ToolNode
tool_node = ToolNode(tools, retry_policy={"max_attempts": 2})
This explicit control is a major advantage for production reliability.
Agent Orchestration
-
LangChain Agents: Use a predefined reasoning loop (ReAct, OpenAI functions). You can customize the prompt and tools, but the loop structure is fixed. Multi‑agent delegation is possible by wrapping agents as tools, but complex coordination (supervisor, hierarchical) is cumbersome.
-
LangGraph Agents: There is no predefined agent loop. You build your own by connecting nodes. This allows patterns like:
- Supervisor agent: A node that evaluates the state and routes to different sub‑agents (which can be separate subgraphs).
- Hierarchical workflows: A top‑level planner graph that calls worker subgraphs.
- Reflexion: A node that criticizes the agent’s output and loops back for improvement.
LangGraph is the clear winner for complex agent orchestration, while LangChain suffices for single‑agent tool‑use scenarios.
Multi‑Agent Systems
LangChain’s multi‑agent support is limited to tool‑based delegation (one agent calling another as a tool). LangGraph natively supports:
- Supervisor agents: A central node that dispatches work to subgraphs.
- Parallel agents: The
SendAPI allows multiple agents to work concurrently on different parts of a problem. - Dynamic collaboration: Agents can be added or removed from the graph dynamically based on state.
For any production system with more than one agent, LangGraph provides the necessary scaffolding.
Human‑in‑the‑loop
LangGraph’s interrupt mechanism is a game‑changer. You can insert an interrupt node that pauses the graph and returns control to an external system. The system can present information to a human, wait for their approval, and then resume the graph with additional state. This persists across restarts.
LangChain has no equivalent; implementing human‑in‑the‑loop in a vanilla LangChain agent would require a blocking tool that holds the process open, which is fragile and not crash‑safe.
Production Readiness
| Area | LangChain | LangGraph |
|---|---|---|
| Observability | LangSmith tracing, callbacks | Deep graph‑level tracing in LangSmith; OpenTelemetry |
| Tracing | Traces each chain step | Traces each node with state snapshots |
| Deployment | Stateless microservice; scale horizontally | Stateful graph requires checkpoint DB; LangGraph Cloud for managed deployment |
| Monitoring | Standard logging, metrics | Built‑in metrics for node execution |
| Testing | Unit test chains and tools | Unit test nodes; integration test graph behavior; replay from checkpoints for regression testing |
| Reliability | Retry mechanisms can be added manually | Built‑in node retry; checkpoint‑based recovery |
| Scalability | Horizontally scalable (stateless) | Horizontally scalable with shared checkpoint DB |
LangGraph’s infrastructure requirements are higher due to the checkpoint database, but the payoff in reliability and auditability is substantial for mission‑critical agents.
Performance Comparison
- Latency: LangChain has a lighter execution overhead; LangGraph adds checkpoint I/O (a few milliseconds per node) but this is negligible compared to LLM latency.
- Concurrency: LangGraph supports parallel node execution, which can reduce total wall‑clock time for independent tool calls. LangChain’s LCEL can parallelize chains internally but not custom agent loops.
- Scalability: Both can scale horizontally; LangGraph requires careful scaling of the checkpoint store. For high‑throughput, stateless agents, LangChain may be simpler to scale.
Learning Curve
- LangChain: Easier to start; LCEL provides a clean, declarative syntax. The abundance of high‑level abstractions can become confusing, but for common patterns (RAG, chatbots), the learning path is well‑trodden.
- LangGraph: Steeper learning curve. You need to understand graph concepts, state schemas, reducers, and checkpointers. However, the lower‑level API gives you a clearer mental model once mastered.
Many teams begin with LangChain to prototype and then transition to LangGraph when the workflow outgrows the simple agent loop.
Enterprise Use Cases
LangChain is suitable for:
- RAG‑based question answering over documents.
- Simple chatbots with fixed tool sets.
- Document extraction and summarization pipelines.
- Rapid prototyping of LLM features.
LangGraph is suitable for:
- Long‑running business process automation (e.g., insurance claims processing).
- Autonomous agents that research, code, and iterate over hours.
- Multi‑step workflows requiring human approval at specific stages.
- Multi‑agent collaboration systems (e.g., a team of AI assistants working on a report).
- Any application where traceability, replay, and fault tolerance are required.
Strengths and Weaknesses
| Feature | LangChain | LangGraph |
|---|---|---|
| Ease of prototyping | ✅ High | ❌ Lower initial effort but more control |
| Flexibility of control flow | ❌ Limited to predefined patterns | ✅ Full control over every transition |
| State durability | ❌ Ephemeral | ✅ Checkpoints across restarts |
| Human‑in‑the‑loop | ❌ Fragile workarounds | ✅ Robust interrupt/resume |
| Multi‑agent orchestration | ❌ Simple delegation only | ✅ Complex supervisor, hierarchical, parallel |
| Maturity | ✅ Mature, large ecosystem | ✅ Battle‑tested, rapidly evolving |
| Complexity | Medium (many abstractions) | Higher (explicit graph design) |
| Ecosystem integration | ✅ Extensive integrations | ✅ Reuses LangChain integrations |
| Debugging | Traces; step inspection | Time‑travel debugging; state inspection |
When Should You Choose LangChain?
Choose LangChain when:
- You are building a straightforward LLM application: RAG, chatbot, or simple extraction.
- Your workflows are linear or have only minor branching.
- You do not need durable state or long‑running agent execution.
- You want to leverage the huge ecosystem of integrations (vector stores, retrievers, document loaders).
- You are prototyping and need to move fast.
When Should You Choose LangGraph?
Choose LangGraph when:
- Your agent’s control flow is complex, with many conditional branches and loops.
- You need the agent to run for an extended period and survive restarts.
- Human‑in‑the‑loop approval is a core requirement.
- You need auditability and the ability to replay past executions.
- You are building a multi‑agent system with non‑trivial coordination.
Can They Be Used Together?
Yes, and this is a common and recommended pattern. Use LangChain components inside LangGraph nodes. For example, a retrieval step within a LangGraph workflow can use LangChain’s Retriever and Document classes. The LLM call can use LangChain’s model wrapper for consistency. This approach combines LangChain’s rich ecosystem with LangGraph’s robust orchestration.
Many teams start with LangChain for initial development and then wrap the core logic in a LangGraph graph when they need advanced orchestration.
Migration Guide: LangChain → LangGraph
Migrating from a LangChain agent to LangGraph involves:
- Identify the current agent loop: Map the steps of the
AgentExecutor(plan → tool → observe → repeat) to graph nodes. - Define a State schema: Include
messages(conversation history) and any additional context (e.g., user ID, retrieved documents). - Create nodes: An
agentnode that calls the LLM with tools bound, and atoolnode that executes tools. - Add a conditional edge: After the agent node, check if the last message contains a tool call; if yes, route to
toolnode, else route toEND. - Move tool definitions: LangChain tools can be reused directly via
ToolNode. - Implement persistence: Add a checkpointer (e.g.,
SqliteSaverorPostgresSaver) to the graph. - Add human approval (if needed): Insert an
interruptafter the agent node before executing a sensitive tool. - Test with checkpoints: Use the ability to replay from saved checkpoints to validate behavior.
The migration does not require rewriting tools or prompts; it primarily restructures the orchestration layer.
Frequently Asked Questions
-
Is LangGraph replacing LangChain?
No, they are complementary. LangGraph focuses on orchestration; LangChain provides the components. They are maintained by the same organization and work together. -
Should beginners learn LangChain first?
Yes, LangChain’s higher‑level abstractions are a gentler introduction to LLM application development. LangGraph is better learned after you understand the basics of tool calling and chains. -
Can LangGraph use LangChain tools?
Absolutely. Tools from LangChain can be used directly in a LangGraphToolNode. -
Which framework scales better?
For pure throughput, a stateless LangChain service scales slightly easier. For complex workflows, LangGraph’s checkpointing can become a bottleneck, but with a properly scaled Postgres it handles production loads well. -
Which framework is better for RAG?
For a standard RAG pipeline (retrieve → generate), LangChain is simpler and sufficient. If your RAG pipeline includes conditional retrieval, multiple rounds of search, or long‑running context gathering, LangGraph provides more control. -
Which framework is better for enterprise agents?
LangGraph, due to its durability, auditability, and human‑in‑the‑loop capabilities. -
Is LangGraph production‑ready?
Yes, it is used in production at many companies. LangGraph Cloud offers managed infrastructure. -
Can I use LangGraph without LangChain at all?
Yes. You can write nodes that call LLM APIs directly without any LangChain dependency. However, you’ll lose the convenience of unified model interfaces and tool abstractions. -
Does LangGraph support streaming?
Yes, nodes can stream tokens, and custom events can be emitted. LangChain’s streaming integrates seamlessly. -
How does debugging differ?
LangChain provides trace views showing the sequence of chain calls. LangGraph provides trace views plus the ability to load a checkpoint and step through the graph from any point. -
Which is easier to test?
LangGraph’s deterministic graph makes unit testing nodes straightforward and enables replay‑based regression testing. LangChain’s testing is also possible but relies more on mocking the agent loop. -
Is there a performance overhead with LangGraph?
Minimal. Checkpoint I/O adds a few milliseconds per node, but in most agent workflows LLM latency dominates by orders of magnitude.
Best Practices
- Separate business logic from orchestration: Keep tools and utility functions framework‑agnostic so they can be used with either LangChain or LangGraph.
- Avoid deeply nested chains: Flat, composable runnables (LCEL) are easier to debug and later migrate to graphs.
- Design reusable tools: Use clear schemas; these will work seamlessly in both frameworks.
- Persist only necessary state: In LangGraph, be mindful of state size; trim conversation history or summarize.
- Implement retries and timeouts on all external calls: LangGraph’s node‑level retry policies make this easy; in LangChain, add them at the tool level.
- Monitor graph execution: Use LangSmith or OpenTelemetry to trace node execution and identify bottlenecks.
- Write deterministic nodes: Keep node functions pure (output depends only on input state) to facilitate testing and replay.
- Adopt observability from day one: Both frameworks integrate with LangSmith; instrument even prototypes.
Conclusion
LangChain is the right foundation for most LLM applications—especially RAG, chatbots, and simple tool‑using agents. It provides the components and abstractions that accelerate development.
LangGraph extends that foundation into a full‑fledged orchestration platform for complex, stateful, and durable agent workflows. It is the better choice when you need advanced control flow, long‑running execution, human‑in‑the‑loop, or multi‑agent coordination.
In practice, many production systems use both: LangChain for the building blocks, LangGraph for the orchestration layer. Understanding when to graduate from chains to graphs is a key skill for AI engineers building reliable agent systems.
Recommendation matrix:
| Project Type | Recommended Framework |
|---|---|
| Simple RAG Q&A | LangChain |
| Document summarization pipeline | LangChain |
| Customer support chatbot (single agent) | LangChain |
| Coding assistant with tool use | LangGraph (or LangChain; LangGraph if complex) |
| Multi‑step loan approval workflow | LangGraph |
| Autonomous research agent (long‑running) | LangGraph |
| Multi‑agent collaborative system | LangGraph |
| Internal enterprise assistant with retrieval | LangChain (can start); LangGraph if stateful |
Further reading: