Exploring LangGraph

After diving into RAGs and advanced pipelines, today we step into something even more powerful: LangGraph. If LangChain gave us building blocks for LLM apps, LangGraph gives us a framework to structure, persist, and orchestrate workflows as graphs.
Let’s break it down.
🌐 What is LangGraph?
LangGraph is a graph-based framework built on top of LangChain. Instead of writing linear “call → response → call” pipelines, LangGraph lets you:
Define nodes (steps in your workflow)
Connect them with edges (transitions)
Maintain state across steps
Add persistence (checkpointing) so conversations don’t lose context
Think of it like a flowchart for your AI workflows, but programmable and scalable.
🔑 LangGraph vs. LangChain
Here’s how they differ:
Feature | LangChain 🧩 | LangGraph 🔗 |
Purpose | Toolkit for LLM apps (chains, tools, agents) | Framework for stateful, graph-based workflows |
State Handling | Stateless by default (you manage memory) | Built-in state + checkpointing |
Structure | Linear pipelines or agents | Graphs of nodes & edges |
Persistence | Needs custom DB/memory integration | MemorySaver / external checkpoint stores |
Use Case | Quick prototypes, tool calls, RAG | Complex, production-grade multi-step workflows |
👉 TL;DR: LangChain = “lego bricks”, LangGraph = “blueprint + memory to orchestrate them at scale”.
⚡ Example 1: Building a Tavily-powered Agent
Using @langchain/langgraph/prebuilt
, we can spin up a React-style agent that uses:
TavilySearch for web results
ChatOpenAI as the LLM
MemorySaver for checkpointing
A LangSmith Client for tracing
const agentTools = [new TavilySearch({ maxResults: 3 })];
const agentModel = new ChatOpenAI({ model: "gpt-4o-mini", temperature: 0 });
const agentCheckpointer = new MemorySaver();
const agent = createReactAgent({
llm: agentModel,
tools: agentTools,
checkpointSaver: agentCheckpointer,
tags: ["tutorial", "agent-with-tavily"],
});
✅ Here, LangGraph manages the agent’s memory & checkpoints automatically.
If you ask follow-up questions in the same threadId
, it recalls past context!
⚡ Example 2: Adding Special Logic (Date Handling)
You can intercept queries before sending them to the agent. For example, if someone asks “what day is today?”, you can short-circuit the graph and return a fixed response.
if (dateRelatedQueries.some(q => query.toLowerCase().includes(q))) {
return "Today is Friday, August 22, 2025.";
}
👉 This shows how LangGraph lets you mix deterministic logic + LLM reasoning in one workflow.
⚡ Example 3: Custom State Graphs
LangGraph isn’t just for agents. You can define custom state machines for any workflow.
State Definition
const State = Annotation.Root({
foo: Annotation(),
bar: Annotation({
reducer: (state, update) => state.concat(update),
default: () => [],
}),
});
Here:
foo
is a counter (simple value)bar
is a list (with a reducer to accumulate values)
StateGraph Workflow
const graphBuilder = new StateGraph(State)
.addNode("incrementFoo", async (s) => ({ foo: (s.foo || 0) + 1 }))
.addNode("addToBar", async () => ({ bar: ["added item"] }))
.addEdge("__start__", "incrementFoo")
.addEdge("incrementFoo", "addToBar")
.addEdge("addToBar", "__end__");
👉 This compiles into a graph-based workflow that persists foo
and bar
between runs.
🧠 Why LangGraph Matters
Stateful Agents: No more stateless chatbots. Memory persists across runs.
Production Pipelines: Define workflows as graphs = easier debugging & scaling.
Custom Control: Mix rules (like date checks) with AI calls.
Checkpoints: Save and resume workflows mid-run (great for long tasks).
Composable: Works with LangChain tools, retrievers, embeddings, etc.
🚀 Use Cases
Conversational agents with long-term memory
Complex pipelines (RAG + Query Rewriting + Ranking + Caching)
Multi-agent systems (coordinating different specialized agents)
Workflows where state and persistence matter (like customer support bots)
🔮 Final Thoughts
LangChain gave us the building blocks, but LangGraph gives us the architecture to scale.
With agents, state graphs, and checkpointing, you can go beyond toy demos and build real-world GenAI systems.
And the best part? You can mix JavaScript + LangGraph to build these workflows in a way that feels natural for modern full-stack developers.
Subscribe to my newsletter
Read articles from Aman Kumar directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
