LangGraph
Build stateful, controllable agents as graphs.
LangGraph models agent workflows as a directed graph of nodes (functions) and edges (transitions) over a shared, typed state. It adds durable execution, time-travel, human-in-the-loop interrupts, and streaming — the runtime behind most production LangChain agents.
Install
pip install langgraphnpm install @langchain/langgraphQuickstart
A minimal example to verify your setup.
from typing import TypedDict
from langgraph.graph import StateGraph, START, END
class State(TypedDict):
input: str
output: str
def respond(state: State) -> State:
return {"output": f"Echo: {state['input']}"}
graph = StateGraph(State)
graph.add_node("respond", respond)
graph.add_edge(START, "respond")
graph.add_edge("respond", END)
app = graph.compile()
print(app.invoke({"input": "hello"}))Core concepts
State graphs
Define a typed state schema, then declare nodes that read and update it. Conditional edges branch on state to express loops, retries, and routing.
Checkpointers
Plug in SQLite, Postgres, or Redis to persist state across steps. Resume crashed runs, fork from past steps, and audit every transition.
Human-in-the-loop
Interrupt the graph before any node to wait for approval, edits, or tool confirmation, then resume with updated state.
Streaming
Stream tokens, node outputs, and intermediate state updates to drive responsive UIs over WebSocket or SSE.
Common use cases
- ›Multi-agent collaboration
- ›Long-running research and coding agents
- ›Approval workflows with human review
- ›Reliable tool-using assistants