LangGraph
LangGraph is a low-level agent orchestration framework providing graph-based execution with durable state, built-in persistence, and human-in-the-loop patterns. As of v1.0 it is the foundational runtime for LangChain agents. Use LangChain for high-level agent abstractions, LangGraph for fine-grained control.
Warnings
- deprecated langgraph.prebuilt module deprecated in 1.0. All prebuilt functionality moved to langchain.agents.
- breaking langgraph-prebuilt==1.0.2 introduced a breaking signature change to ToolNode.afunc adding a required runtime parameter. langgraph==1.0.1 does not pin this dependency.
- gotcha MemorySaver is in-memory only. State is lost on process restart. Not for production.
- gotcha LangGraph requires a compiled graph before invocation. Always call graph.compile() before graph.invoke().
- gotcha State TypedDict must be defined before StateGraph instantiation. Missing keys raise KeyError at runtime not at definition time.
Install
-
pip install langgraph -
npm install @langchain/langgraph
Imports
- StateGraph
from langgraph.graph import StateGraph
- create_react_agent
from langchain import create_agent
- MemorySaver
from langgraph.checkpoint.memory import MemorySaver
Quickstart
from langgraph.graph import StateGraph, END
from typing import TypedDict
class State(TypedDict):
messages: list
def call_model(state: State):
# your LLM call here
return {"messages": state["messages"]}
graph = StateGraph(State)
graph.add_node("agent", call_model)
graph.set_entry_point("agent")
graph.add_edge("agent", END)
app = graph.compile()
result = app.invoke({"messages": [{"role": "user", "content": "hello"}]})