Quickstart
This guide will get you up and running with LangGraph in under 5 minutes. You’ll create a simple stateful workflow that demonstrates the core concepts of graphs, nodes, edges, and state.Prerequisites
Before you begin, make sure you have:- Python 3.10 or higher installed
- Basic familiarity with Python and type hints
Your First LangGraph Application
Let’s build a simple workflow that processes text through multiple nodes.First, define the state schema using a TypedDict. The state represents the data that flows through your graph:
Nodes are the building blocks of your graph. Each node is a function that receives the current state and returns an update:
def node_a(state: State) -> dict:
return {"text": state["text"] + "a"}
def node_b(state: State) -> dict:
return {"text": state["text"] + "b"}
Node functions can return a partial state update. LangGraph automatically merges the update with the existing state.
from langgraph.graph import START, StateGraph
graph = StateGraph(State)
graph.add_node("node_a", node_a)
graph.add_node("node_b", node_b)
graph.add_edge(START, "node_a")
graph.add_edge("node_a", "node_b")
StateGraph(State) creates a graph with your state schemaadd_node() registers functions as nodes in the graphadd_edge() defines the execution flow between nodesSTART is a special constant representing the entry pointComplete Example
Here’s the full code in one place:Expected Output
When you run this code, you’ll see:- Starts with an empty string
"" node_aappends"a"→"a"node_bappends"b"→"ab"
Understanding the Flow
Each node receives the current state and returns updates. LangGraph automatically merges these updates.
Building a Conditional Workflow
Let’s extend the example with conditional routing:count until it reaches 3.
Next Steps
Now that you’ve built your first LangGraph application, explore more advanced features:Core Concepts
Learn about state management, reducers, and graph patterns
Checkpointing
Add persistence and enable time-travel debugging
Human-in-the-Loop
Pause execution for human approval or input
Examples
Explore real-world LangGraph applications
Troubleshooting
Import Errors
If you seeModuleNotFoundError, ensure LangGraph is installed:
Type Errors
Make sure you’re usingtyping_extensions.TypedDict (not typing.TypedDict) for Python 3.10 compatibility:
State Not Updating
Remember that node functions should return dictionaries with the keys to update:Get Help
Need assistance? Here are some resources:- LangChain Forum - Community Q&A
- GitHub Issues - Bug reports and feature requests
- LangChain Academy - Free structured course