Comparing 30 Agent Frameworks: LangChain vs LangGraph
AI-assisted — drafted with AI, reviewed by editorsDiego Herrera
Creative technologist writing about AI agents in design and content.
# Comparing 30 Agent Frameworks: LangChain vs LangGraph ## Overview of LangChain and LangGraph LangChain is a Python and JavaScript library for building applications that combine large language mode...
Comparing 30 Agent Frameworks: LangChain vs LangGraph
Overview of LangChain and LangGraph
LangChain is a Python and JavaScript library for building applications that combine large language models (LLMs) with external data sources, tools, and memory. It was first released in 2022 and has reached version 0.2.13 as of early 2026. LangChain provides composable abstractions such as chains, agents, and retrievers that let developers orchestrate LLM calls without writing low‑level glue code.
LangGraph is an extension of LangChain that adds a graph‑based execution engine. Released in mid‑2024 as LangGraph 0.1.0, it enables developers to define agent workflows as directed graphs where nodes represent LLM calls, tool invocations, or conditional logic, and edges define the flow of control. LangGraph 0.2.5 (the latest at time of writing) adds built‑in support for persistence, streaming, and human‑in‑the‑loop checkpoints.
Both libraries are maintained by the same core team at LangChain, Inc., and are distributed under the MIT license.
Key Features and Capabilities
LangChain
- Chains: Sequential or tree‑structured compositions of LLMs, prompts, and parsers. Example:
LLMChainfor a single prompt‑model pair. - Agents: Reasoning loops that decide which tool to call next based on the agent’s scratchpad. Implemented via
AgentExecutor. - Memory: Classes like
ConversationBufferMemoryandVectorStoreRetrieverMemoryto retain chat history or embeddings. - Tools: Over 150 built‑in tool wrappers (e.g.,
GoogleSearchAPIWrapper,PythonREPLTool) and a simple interface for custom tools. - Retrievers: Integrations with vector stores such as FAISS, Chroma, Pinecone, and Weaviate for semantic search.
- Callbacks: Hook system for logging, tracing, and metric collection.
LangGraph
- State Graph: Workflow defined as a
StateGraphwhere each node updates a shared state object. - Conditional Edges: Nodes can route to different successors based on state values, enabling loops and branching.
- Persistence: Automatic checkpointing to SQLite or PostgreSQL, allowing workflows to resume after interruption.
- Streaming: Real‑time yield of intermediate node outputs via async generators.
- Human‑in‑the‑Loop: Built‑in
interruptnode that pauses execution and waits for external input. - Subgraphs: Reusable graph fragments that can be instantiated multiple times.
Both frameworks support synchronous and asynchronous execution, and they expose the same LLM interface (e.g., ChatOpenAI, ChatAnthropic).
Architecture and How They Work
LangChain Architecture
LangChain treats an LLM as a callable object. A chain is a sequence of callables where the output of one feeds into the next. Agents add a loop: the agent calls the LLM, parses the output for a tool invitation, executes the tool, appends the result to the scratchpad, and repeats until a stopping condition.
Data flow example (simplified):
from langchain.llms import OpenAI
from langchain.chains import LLMChain
from langchain.prompts import PromptTemplate
llm = OpenAI(temperature=0)
prompt = PromptTemplate.from_template("What is the capital of {country}?")
chain = LLMChain(llm=llm, prompt=prompt)
result = chain.run({"country": "France"})
print(result) # -> "The capital of France is Paris."
LangGraph Architecture
LangGraph builds on the same LLM callable but adds a graph executor. The developer defines a StateGraph with nodes that are callables (LLMs, tools, or custom functions). The graph maintains a mutable state dictionary that is passed between nodes. Conditional edges are functions that inspect the state and return the name of the next node.
Example of a simple reflexion agent:
from langgraph.graph import StateGraph, END
from typing import TypedDict, Annotated
class AgentState(TypedDict):
input: str
output: str
iterations: int
def call_model(state: AgentState) -> AgentState:
# pseudo‑LLM call
state["output"] = f"Answer to {state['input']}"
state["iterations"] += 1
return state
def should_continue(state: AgentState) -> str:
return "call_model" if state["iterations"] < 3 else END
builder = StateGraph(AgentState)
builder.add_node("call_model", call_model)
builder.add_conditional_edges("call_model", should_continue, {"call_model": "call_model", END: END})
builder.set_entry_point("call_model")
graph = builder.compile()
result = graph.invoke({"input": "Explain quantum entanglement", "output": "", "iterations": 0})
print(result["output"])
The graph executor handles looping, state persistence, and streaming of each node’s output.
Real-World Use Cases
LangChain
- Question‑Answering over Documents: Load PDFs with
UnstructuredPDFLoader, embed withOpenAIEmbeddings, store in FAISS, and retrieve withRetrievalQA. - API‑Driven Agents: Build an agent that calls
GitHubAPIWrapperto create issues, then uses aPythonREPLToolto test proposed fixes. - Chatbots with Memory: Use
ConversationBufferMemoryto keep context across turns in a Streamlit or Slack bot.
LangGraph
- Multi‑Step Data Pipelines: A graph where one node extracts data from a REST API, a second node transforms it with Pandas, and a third node loads the result into a data warehouse.
- Human‑Review Loops: A content moderation workflow where an LLM flags toxic text, an
interruptnode pauses for a human reviewer, and a final node applies the reviewer’s decision. - Agentic CAD Assistant: Nodes that generate SVG sketches, call a validation tool, and iterate until the design passes constraints.
These examples are drawn from public repositories and case studies posted on the LangChain blog (e.g., "Building a Retrieval‑Augmented Agent with LangGraph" – March 2025).
Strengths and Limitations
LangChain
Strengths:
- Mature ecosystem with extensive documentation and community tutorials.
- Large library of ready‑made tools and integrations.
- Simple to start with for linear chains or basic agents.
Limitations:
- The agent loop (
AgentExecutor) can be opaque; customizing control flow requires subclassing. - No built‑in persistence; long‑running agents must manage state externally.
- Complex branching leads to nested chains that are hard to debug.
LangGraph
Strengths:
- Explicit graph representation makes workflow logic transparent.
- Built‑in checkpointing enables fault‑tolerant, long‑running processes.
- Easy to inject human review or external callbacks at any node.
Limitations:
- Smaller set of community‑contributed nodes compared to LangChain’s tool library.
- Learning curve for developers unfamiliar with graph‑based programming.
- As of v0.2.5, some advanced features (e.g., dynamic graph rewriting) are still experimental.
Comparison Table
| Feature | LangChain | LangGraph |
|---|---|---|
| Primary abstraction | Chains / Agents | State Graph |
| Control flow | Imperative loops (AgentExecutor) | Declarative graph with conditional edges |
| Persistence | External (developer‑managed) | Built‑in (SQLite/Postgres) |
| Streaming | Via callbacks | Native async generators per node |
| Human‑in‑the‑Loop | Requires custom logic | interrupt node provided |
| Tool library | ~150+ built‑in wrappers | Same tools usable as nodes |
| Latest version (early 2026) | 0.2.13 | 0.2.5 |
| Typical use case | Simple QA, linear agents | Complex workflows, pipelines, review loops |
Getting Started Guide
Installing LangChain
pip install "langchain>=0.2.13" "langchain-openai>=0.1.0"
Create a virtual environment, then run a basic LLM chain:
# basic_chain.py
from langchain.chat_models import ChatOpenAI
from langchain.prompts import ChatPromptTemplate
llm = ChatOpenAI(model="gpt-4o-mini", temperature=0)
prompt = ChatPromptTemplate.from_messages([("system", "You are a helpful assistant."),
("human", "Explain {topic} in one sentence.")])
chain = prompt | llm
print(chain.invoke({"topic": "LangGraph"}))
Run with:
python basic_chain.py
Installing LangGraph
pip install "langgraph>=0.2.5" "langchain-openai>=0.1.0"
Example: a two‑step graph that first summarizes a text, then translates the summary.
# translate_graph.py
from langgraph.graph import StateGraph, END
from typing import TypedDict
from langchain.chat_models import ChatOpenAI
llm = ChatOpenAI(model="gpt-4o-mini", temperature=0)
class State(TypedDict):
text: str
summary: str
translation: str
def summarize(state: State) -> State:
prompt = f"Summarize the following in one bullet: {state['text']}"
state["summary"] = llm.invoke(prompt).content
return state
def translate(state: State) -> State:
prompt = f"Translate this to Spanish: {state['summary']}"
state["translation"] = llm.invoke(prompt).content
return state
builder = StateGraph(State)
builder.add_node("summarize", summarize)
builder.add_node("translate", translate)
builder.add_edge("summarize", "translate")
builder.add_edge("translate", END)
builder.set_entry_point("summarize")
graph = builder.compile()
result = graph.invoke({"text": "LangGraph enables developers to define agent workflows as graphs, making control flow explicit and persistent.",
"summary": "",
"translation": ""})
print(result["translation"])
Run with:
python translate_graph.py
Both examples assume you have set the OPENAI_API_KEY environment variable. Replace the model name with any supported LLM (e.g., anthropic/claude-3-5-sonnet via ChatAnthropic).
LangChain and LangGraph serve complementary roles. LangChain excels when you need a large library of ready‑made tools and a quick start for simple agents. LangGraph shines when your application requires explicit, persistent, and potentially human‑guided workflows. Choosing between them depends on the complexity of the control flow you need and whether built‑in checkpointing is a priority.