Build an AI Agent With LangGraph: A Step-by-Step Tutorial
Turn this article into takeaways for your work.
Each assistant summarizes the article only for you and suggests best practices for your work.
LangGraph is LangChain's low-level framework for building stateful AI agents as an explicit graph of nodes and edges, giving you direct control over how an agent branches, pauses, and persists state across a long-running task. It's the code path teams reach for once a job needs conditional logic, multi-step approval flows, or memory that survives days instead of one conversation. This guide covers what LangGraph actually is, how to install it, a full build walkthrough with two working examples, and when it's the right platform versus the alternatives.
What LangGraph Actually Is
LangGraph is a low-level orchestration framework and runtime for building, managing, and deploying long-running, stateful agents. It's separate from LangChain's higher-level abstractions, LangChain gives you models, tools, and prebuilt agent patterns; LangGraph gives you the graph-based runtime underneath, where you define nodes as computation steps, edges as the paths between them, and a shared state object that flows through the whole run. That's a deliberate design choice: reasonable defaults when you don't need much control, an explicit graph when you do.
Real production usage backs up the pitch. LangChain's own writeup on LangGraph in production names Uber (large-scale code migrations on its developer platform), LinkedIn (an AI recruiter that automates candidate sourcing and messaging), Replit (a multi-agent system with human-in-the-loop review), and Elastic (orchestrating a network of agents for real-time threat detection) as production users. AppFolio's property management copilot, also built on LangGraph, saved its property managers more than 10 hours a week and doubled the accuracy of their decisions, a concrete result rather than a vague adoption claim.
That kind of deployment is becoming the norm, not the exception. Gartner projects 40% of enterprise applications will feature task-specific AI agents by the end of 2026, up from less than 5% in 2025, and a meaningful share of that shift is happening in frameworks built specifically for multi-agent systems like LangGraph, where a graph can model an orchestrator handing work to several specialized nodes instead of one model doing everything in a single pass.
LangGraph's Vocabulary, Mapped to the 6 Building Blocks
If you've read how to build an AI agent, you know the six blocks every agent needs: Role, Tools, Rules, Scenario playbook, Decision logic, and Guardrails. LangGraph gives each one a concrete home in code.
| Rework building block | LangGraph concept |
|---|---|
| Role | The system_prompt passed to a high-level agent, or a node's own instructions |
| Tools | Python functions passed as tools=[...], or a dedicated tool-calling node |
| Rules | Instructions written into the system prompt or a node's logic |
| Scenario playbook | The graph itself, nodes as steps, edges as the paths between them |
| Decision logic | Conditional edges that route execution to a different node based on state |
| Guardrails | interrupt() calls that pause for human review, plus validation logic inside a node |
Nothing here is unique to LangGraph conceptually. What LangGraph adds is an explicit, inspectable graph instead of a black-box loop, which is exactly the kind of control no-code vs code AI agents says you should be reaching for once a job's logic gets genuinely custom.
Installing LangGraph
pip install -U langgraph langchain
langgraph is the core graph and runtime library. langchain adds create_agent, the current high-level entry point for a standard tool-calling agent, which runs on top of LangGraph under the hood. Set an API key for your model provider as an environment variable and you're ready to build.
The Fast Path: create_agent
For a single agent that just needs a model, some tools, and a system prompt, you don't need to touch the graph directly:
from langchain.agents import create_agent
def get_account_status(company: str) -> str:
"""Look up a customer account's status by company name."""
return f"{company}: active, plan tier Growth, renewal in 45 days."
agent = create_agent(
model="claude-sonnet-4-6",
tools=[get_account_status],
system_prompt="You are a support assistant. Answer only from tool results, never guess.",
)
result = agent.invoke(
{"messages": [{"role": "user", "content": "What's the status of Acme Corp's account?"}]}
)
print(result["messages"][-1].content)
This is the same how AI agents use tools mechanic every platform relies on: describe a function, let the model decide when to call it, feed the result back in. create_agent replaced LangGraph's older create_react_agent helper as the recommended starting point, same idea, cleaner API.
Going Lower-Level: A Custom Graph With Conditional Routing
The fast path covers a lot of ground, but it can't express "do X, then branch to a human review step only if risk is flagged." For that, you build the graph directly. Here's a simplified contract review flow, close to the AI Contract Review Agent blueprint: analyze a contract, then route to a human reviewer or auto-approve depending on what the analysis finds.
from typing import TypedDict
from langgraph.graph import StateGraph, START, END
from langgraph.checkpoint.memory import InMemorySaver
class ReviewState(TypedDict):
contract_text: str
risk_flagged: bool
summary: str
def analyze_contract(state: ReviewState) -> dict:
# call the model here to extract terms and set risk_flagged
return {"risk_flagged": True, "summary": "Non-standard liability cap on page 4."}
def route_on_risk(state: ReviewState) -> str:
return "human_review" if state["risk_flagged"] else "auto_approve"
def human_review(state: ReviewState) -> dict:
return {"summary": state["summary"] + " Routed to legal for review."}
def auto_approve(state: ReviewState) -> dict:
return {"summary": state["summary"] + " Auto-approved, no flags."}
graph = StateGraph(ReviewState)
graph.add_node("analyze", analyze_contract)
graph.add_node("human_review", human_review)
graph.add_node("auto_approve", auto_approve)
graph.add_edge(START, "analyze")
graph.add_conditional_edges("analyze", route_on_risk, {
"human_review": "human_review",
"auto_approve": "auto_approve",
})
graph.add_edge("human_review", END)
graph.add_edge("auto_approve", END)
app = graph.compile(checkpointer=InMemorySaver())
add_conditional_edges is the decision logic block made literal: after analyze runs, route_on_risk inspects the state and sends execution down one of two named paths. That's a branch a single linear tool-calling loop can't express cleanly, and it's the reason teams reach for LangGraph once multi-agent systems or multi-step approval flows enter the picture.
Persistence and Memory
The checkpointer argument on compile() is what makes a graph resumable instead of stateless. InMemorySaver, shown above, is fine for local testing but disappears when the process restarts. Production graphs use a persistent backend instead, SQLite or Postgres checkpoint savers ship as separate installable packages, keyed by a thread_id so a specific run's state can be reloaded and continued days later. That's the same working-memory-versus-persistent-memory distinction covered in general in AI agent memory: a checkpointer is LangGraph's concrete answer to persistent memory.
Human-in-the-Loop With Interrupts
LangGraph's interrupt() function pauses graph execution at a specific point and waits for external input before resuming, exactly what the human_review node above needs in a real implementation instead of the placeholder logic shown. A person (or another system) reviews the paused state and responds, the graph resumes from that exact point using the checkpointed state rather than starting over. This is the concrete mechanism behind the approval gates covered generally in human-in-the-loop for AI agents: the graph doesn't guess when a human should step in, you wire that decision directly into the routing logic.
Guardrails and Testing Before You Ship
A conditional edge is only as good as the logic deciding which way to route, so validate that logic before it touches real contracts, tickets, or records. Add explicit checks inside a node (reject or retry an output that fails a rule you define) rather than trusting the model's judgment alone, the discipline covered in AI agent guardrails. And don't call a graph done after one clean test run. How to evaluate and test AI agents covers building a real test set from historical cases, including the messy ones that should route to human review, before any LangGraph agent touches production volume.
Cost and Limits
LangGraph itself is free and open source. What you pay for is LLM API usage, and a graph with more nodes and more branches makes more model calls than a single well-scoped agent doing the same job, the same tradeoff covered in multi-agent systems. If you'd rather not host and monitor the graph yourself, LangChain also offers LangGraph Platform, a paid hosted deployment option with built-in persistence and observability; running it yourself costs nothing beyond your own infrastructure and the model calls.
The real limit isn't pricing, it's that LangGraph gives you no visual builder and no pre-built app connectors. Every integration, every retry policy, every piece of error handling is code you write, which is the direct trade for the control a graph gives you over a no-code platform's bounded logic.
When to Pick LangGraph vs the Alternatives
| If you want... | Consider |
|---|---|
| Maximum control over branching, state, and long-running persistence, as an explicit graph | LangGraph |
| A more readable, role-based API for a multi-agent job | CrewAI |
| A business team building without writing code | See no-code vs code AI agents |
| The fastest path to a working agent across your existing app catalog | Zapier or Make |
| An enterprise platform with Microsoft 365 grounding and governance built in | Microsoft Copilot Studio |
| Full control directly on OpenAI's models, minimal abstraction | OpenAI's Responses API |
Key Facts
- LangGraph is a low-level, open source orchestration framework and runtime for stateful agents, separate from but complementary to LangChain's higher-level abstractions.
- Documented production users include Uber, LinkedIn, Replit, and Elastic; AppFolio's LangGraph-built copilot saved property managers 10+ hours a week and doubled decision accuracy.
create_agentin thelangchainpackage is the current recommended high-level entry point, replacing the oldercreate_react_agenthelper, and runs on top of LangGraph.StateGraphwithadd_conditional_edgesis what lets an agent branch based on its own output, the mechanic behind approval flows and multi-step decision logic.- A
checkpointer(in-memory for testing, SQLite or Postgres for production) makes a graph resumable across sessions, keyed bythread_id.
Where to Go Next
LangGraph is one code path to a working agent, not the only one. Build an AI agent with CrewAI covers a more role-based framework for multi-agent work, and if you're still deciding between writing code and using a visual builder at all, choosing an AI agent platform walks through that decision across no-code, framework, and managed options directly. Once a graph works reliably in testing, deploying AI agents to production covers the rollout and rollback plan before it touches real volume. The dev tools roundup and the AI coding assistant buying guide are useful next stops for writing and maintaining the code itself faster.

Co-Founder, Rework.com
On this page
- What LangGraph Actually Is
- LangGraph's Vocabulary, Mapped to the 6 Building Blocks
- Installing LangGraph
- The Fast Path: create_agent
- Going Lower-Level: A Custom Graph With Conditional Routing
- Persistence and Memory
- Human-in-the-Loop With Interrupts
- Guardrails and Testing Before You Ship
- Cost and Limits
- When to Pick LangGraph vs the Alternatives
- Key Facts
- Where to Go Next