
LangGraph has become one of the most popular libraries for building reliable, stateful AI agents in Python. Its graph-based approach gives you precise control over how agents think, act and hand off work, while built-in persistence makes it possible to pause workflows for human approval and resume them later. In this langgraph tutorial, you will build a multi-agent content workflow with a researcher, a writer and a reviewer, add checkpointing, and include a human in the loop approval step.
Start with the core concepts.
Core LangGraph Concepts
State: a shared data structure, typically a typed dictionary, that flows through the graph. Each node reads and updates it.
Nodes: Python functions that perform work, such as calling an LLM, running a tool or transforming data. Each node receives the state and returns updates.
Edges: connections that define which node runs next. Conditional edges choose the next node based on the state.
Checkpointer: a component that saves state after each step, enabling persistence, resumption and time travel.
Interrupts: pauses that wait for human input before continuing.
These concepts make stateful ai agents straightforward to reason about, because every step and transition is explicit.
What You Need
- Python 3.10 or later.
- An API key for a chat model provider.
- Basic Python knowledge.
Install the packages by running pip install langgraph followed by a LangChain integration package for your model provider, such as langchain-anthropic or langchain-openai.
Step 1: Define the State
Create a file named workflow.py. Define a state class using TypedDict with fields for:
- topic: the subject of the article.
- research: notes produced by the researcher.
- draft: the article draft.
- feedback: reviewer comments.
- revision count: how many times the draft has been revised.
- approved: whether the human has approved publication.
Keeping state explicit makes the workflow easy to debug.
Step 2: Create the Model
Initialize your chat model using the provider integration, such as ChatAnthropic or ChatOpenAI, with a model name and a moderate temperature.
Step 3: Build the Researcher Node
Write a function named researcher that receives the state, sends the topic to the model with a prompt asking for key facts, angles and questions readers will have, and returns an update containing the research notes.
In a real system, the researcher could use search tools. LangGraph's prebuilt ReAct agent helper makes it easy to give a node its own tools.
Step 4: Build the Writer Node
Write a function named writer that uses the topic, research and any existing feedback to produce or revise a draft. If feedback exists, include it in the prompt with instructions to address each point. Return the draft and increment the revision count.
Step 5: Build the Reviewer Node
Write a function named reviewer that evaluates the draft against criteria such as accuracy, clarity and structure. Ask the model to return either APPROVED or a list of specific improvements. Store the result in the feedback field.
Using structured output here, such as a schema with an approved flag and a list of comments, makes routing reliable.
Step 6: Add Conditional Routing
Write a routing function that looks at the state after review:
- If the reviewer approved the draft, go to the human approval node.
- If not approved and the revision count is below three, go back to the writer.
- Otherwise, go to human approval anyway, so the loop cannot run forever.
This is the langgraph multi agent pattern in action: specialized nodes collaborating through shared state with explicit control flow.
Step 7: Add Human in the Loop
Human in the loop langgraph functionality uses interrupts. Create a node named human_approval that calls the interrupt function with the draft and asks for a decision. When the graph reaches this node, execution pauses and returns the draft to your application.
When a human responds, you resume the graph with a command containing the decision. The node then records whether the draft is approved.
Add a final node named publish that runs only when approved, for example saving the article to a file.
Step 8: Assemble the Graph
Create a StateGraph with your state class. Add nodes for researcher, writer, reviewer, human_approval and publish. Add edges:
- Start to researcher.
- Researcher to writer.
- Writer to reviewer.
- Conditional edges from reviewer using your routing function.
- Human approval to publish if approved, otherwise to the end.
- Publish to the end.
Visual description: if you render the graph, you see a flow from researcher to writer to reviewer, a loop arrow from reviewer back to writer, and a branch to human approval and publish.
Step 9: Add LangGraph Checkpointing
LangGraph checkpointing saves state after every step. For development, compile the graph with an in-memory checkpointer. For production, use a persistent checkpointer backed by SQLite or PostgreSQL.
When invoking the graph, pass a configuration with a thread ID. All checkpoints for that run are stored under the thread ID, which lets you resume after interrupts, recover from crashes and inspect history.
Step 10: Run the Workflow
Invoke the graph with an initial state containing the topic and the thread configuration. Execution runs through research, writing and review until it pauses at human approval. Display the draft to the user. When they approve, resume with the approval command and the same thread ID. The workflow continues to publish.
Because state is checkpointed, the approval could happen minutes or days later, even after a server restart.
Troubleshooting Common Issues
State not updating: ensure nodes return dictionaries with the keys to update rather than mutating state directly.
Infinite loops: always include a counter or limit in routing functions, and set a recursion limit when invoking.
Interrupt not resuming: use the same thread ID and a checkpointer; interrupts require persistence.
Inconsistent reviewer routing: use structured output instead of parsing free text.
Import errors: confirm package versions are compatible and follow current documentation, since APIs evolve.
Observability
Tracing helps debug multi-step workflows. LangSmith integrates natively with LangGraph, and OpenTelemetry-based tools such as Langfuse also work. Traces show every node execution, model call, state change and routing decision.
Frequently Asked Questions
Is LangGraph only for multi-agent systems? No. It is equally useful for single agents that need persistence, control flow or human approvals.
Can I deploy LangGraph workflows as APIs? Yes, through LangGraph's deployment platform or by wrapping graphs in your own web service.
Conclusion
In this langgraph tutorial, you built a python agent workflow with researcher, writer and reviewer nodes sharing typed state, conditional routing for revisions, human in the loop approval using interrupts and persistence through checkpointing.
Key takeaways: model state explicitly, keep nodes focused, use structured outputs for routing, limit loops, and use persistent checkpointers in production. Next, give the researcher a real search tool and add tracing to watch the workflow run end to end.