LangChain and LangGraph

LangChain and LangGraph

Summary

LangChain is a framework for wiring models, prompts, tools, retrievers, and agents together quickly. LangGraph is a lower-level orchestration runtime for stateful, branching, long-running agent workflows. Since LangChain v1.0 (Oct 2025), standard LangChain agents run on LangGraph under the hood — you pick LangChain for speed, LangGraph when you need explicit control.

Official docs LangChain · LangGraph
Already in this vault RAG chunking uses LangChain loaders/splitters — Text Chunking, rag_backend
Related concepts Agentic AI · MCP

Explain like I'm five

Imagine you are building a robot helper.

You can use the LEGO kit without thinking about the circuit board — until your robot needs a custom brain with loops, memory, and “wait for approval” buttons. Then you wire the circuit board yourself.


What is LangChain?

LangChain is an open-source framework (Python and JavaScript) for building applications on top of large language models.

It gives you reusable building blocks so you do not re-implement the same glue code for every project:

Building block What it does Vault example
Model integrations One interface to OpenAI, Anthropic, Ollama, etc. Ollama embeddings
Prompts & parsers Template prompts, structured output
Retrievers & vector stores RAG: fetch relevant chunks, pass to model RAG primer
Document loaders & splitters Ingest PDFs, chunk text RecursiveCharacterTextSplitter in Text Chunking
Tools & agents Let the model call functions/APIs in a loop Overlaps with Agentic AI
LCEL (LangChain Expression Language) Compose steps as pipelines: prompt | model | parser Linear chains — retrieve → generate

Mental model: LangChain is the developer-experience layer — integrations, abstractions, and a fast path to “working demo.”

What it is not: a model host, a vector database, or a deployment platform by itself (though the LangChain ecosystem also includes LangSmith for tracing/evals and LangGraph Platform for deployment).


What is LangGraph?

LangGraph is a library for building stateful, graph-shaped workflows where each step is a node, transitions are edges, and shared data lives in state.

Unlike a simple linear chain (A → B → C), a graph can:

Core concepts:

Concept Meaning
StateGraph The workflow definition — nodes + edges + state schema
Node One unit of work (call model, run tool, transform data)
Edge Which node runs next (can be conditional)
Checkpointing Save/resume execution state (in-memory or Postgres, etc.)
Interrupt Pause graph, wait for human input, resume

Mental model: LangGraph is the orchestration runtime — explicit control flow for agents that act over time, not just respond once.

Inspired by graph systems like Pregel/NetworkX; implemented by the same team behind LangChain (official overview).


How they fit together (2025–2026)

flowchart TB
  subgraph apps [Your application]
    RAG[RAG pipeline]
    AGENT[Agent with tools]
    MULTI[Multi-agent workflow]
  end

  subgraph lc [LangChain — framework layer]
    INT[Model / tool / retriever integrations]
    CA[create_agent + middleware]
    LCEL[LCEL chains]
  end

  subgraph lg [LangGraph — runtime layer]
    SG[StateGraph]
    CP[Checkpointing]
    HITL[Human-in-the-loop interrupts]
  end

  RAG --> INT
  RAG --> LCEL
  AGENT --> CA
  CA --> SG
  MULTI --> SG
  SG --> CP
  SG --> HITL
Layer Library Role
Framework LangChain Abstractions, 600+ integrations, create_agent, RAG helpers
Runtime LangGraph Durable execution, cycles, branching, persistence
Harness (optional) Deep Agents Higher-level patterns (planning, subagents, filesystem) on top of LangGraph

Key fact (v1.0, Oct 2025): LangChain agents now use LangGraph as the execution engine. create_agent replaced the older AgentExecutor. You do not choose one instead of the other for most agent work — LangChain sits on LangGraph.

When the boundary becomes visible: you need to inspect mid-run state, custom routing, durable multi-day workflows, or multi-agent handoffs — then you drop to LangGraph directly and design the StateGraph yourself.

Sources: LangChain product concepts, LangGraph overview.


LangChain vs LangGraph — decision table

Question Use LangChain Use LangGraph directly
First RAG prototype with loaders + retriever? Yes Overkill
Standard tool-calling agent loop? Yes (create_agent) Only if default loop is insufficient
Custom cycles, retries, or conditional routing? Middleware may help Yes — explicit graph
Human must approve before an action? Via middleware Yes — first-class interrupt
Workflow must survive server restart? Inherited from runtime Yes — checkpointing is core
Multi-agent with handoffs between specialists? Possible Usually clearer as a graph

How this maps to your vault

Topic in vault LangChain role LangGraph role
Text Chunking RecursiveCharacterTextSplitter, loaders Not required — linear ingest
rag_backend Chroma retriever, Docling loader, RAG chain Optional if you add agentic re-query loops
Agentic AI Agent abstractions, tool wiring Stateful plan → act → observe loops
MCP Alternative tool protocol (not LangChain-specific) MCP tools can be called from LangGraph nodes

Practical takeaway: your RAG notes already use LangChain as plumbing (splitters, loaders, retrievers). Agentic AI is where LangGraph matters most — when the system must remember, branch, and keep acting across steps.


Minimal code shapes (conceptual)

LangChain — linear RAG chain

# Conceptual — not a full runnable script
from langchain_text_splitters import RecursiveCharacterTextSplitter
from langchain_core.prompts import ChatPromptTemplate

splitter = RecursiveCharacterTextSplitter(chunk_size=500, chunk_overlap=50)
chunks = splitter.split_text(raw_text)

prompt = ChatPromptTemplate.from_template(
    "Answer using only this context:\n{context}\n\nQuestion: {question}"
)
# chain = retriever | prompt | model   (LCEL composition)

LangGraph — explicit state machine

# Conceptual — graph with a loop
from typing import TypedDict
from langgraph.graph import StateGraph, END

class AgentState(TypedDict):
    messages: list
    step_count: int

def call_model(state: AgentState) -> AgentState:
    ...

def should_continue(state: AgentState) -> str:
    return "tools" if needs_tool(state) else END

graph = StateGraph(AgentState)
graph.add_node("model", call_model)
graph.add_node("tools", run_tools)
graph.add_conditional_edges("model", should_continue)
# compile with checkpointer for durable state

Common misconceptions

Myth Reality
“LangGraph replaces LangChain” They are stacked. LangChain v1.0 agents run on LangGraph.
“I need LangGraph for every RAG app” No — simple retrieve-then-generate is fine with LangChain chains alone.
“LangChain = one Python package” Modern installs are modular: langchain-core, langchain-text-splitters, provider packages, etc.
“LangGraph is only for LangChain users” LangGraph can be used standalone; docs often show LangChain integrations for convenience.

Ecosystem map

flowchart LR
  LC[LangChain
framework] LG[LangGraph
runtime] LS[LangSmith
tracing / evals] LGP[LangGraph Platform
deployment] LC --> LG LC --> LS LG --> LS LG --> LGP
Product Purpose
LangChain Build apps — models, tools, RAG, agents
LangGraph Orchestrate stateful, long-running workflows
LangSmith Debug traces, datasets, evaluations
LangGraph Platform Deploy and operate graphs in production

If you want to… Go to
Build or extend your RAG pipeline RAG primer
Understand autonomous agents conceptually Agentic AI
Wire tools via a standard protocol MCP v1
Official LangChain agent docs docs.langchain.com — agents
Official LangGraph tutorials docs.langchain.com — LangGraph

2_AI Index · Agentic AI · MCP