Intermediate 13 minAgents

LangGraph: build a stateful agent in local

An open laptop casts green light across a dark desk.
Direct response

LangGraph is an open-source Python framework (MIT license, version 1.2.22 from November 14, 2026) for building stateful AI agents: you describe the agent as a graph of nodes and edges, with memory, resumption, and human approval. It runs entirely locally with Ollama via langchain-ollama and a model that supports tool calling, such as gpt-oss:20b or qwen3:8b.

LangGraph is the LangChain component for agents where you want control over every step. This guide explains what LangGraph does and how it differs from LangChain, then builds a stateful agent on your machine with Ollama: installation, graph, durable memory, pausing for approval, and what can still go online.

By Mohamed Meguedmi·Update 2026-11-23·Tested on Windows, macOS, and Linux

#What exactly is LangGraph?

LangGraph is an open-source Python framework, published by LangChain Inc. under the MIT license, for building stateful AI agents: programs where a language model makes decisions, calls tools, keeps track of where it is, and can resume after a pause or a failure.

The official documentation defines LangGraph as a low-level orchestration framework and runtime for long-running agents. A LangGraph agent is a graph: a shared state, nodes that do the work, and edges that decide the next step. A node can call a model or run ordinary code.

State
LangGraph state is a shared snapshot of the application, usually a typed dictionary: the list of messages, a counter, an intermediate result. Each node reads it and returns an update.
Node
A LangGraph node is a Python function that reads the state, performs a task (calling the model, running a tool), and returns what changed.
Edge
A LangGraph edge connects two nodes. A conditional edge chooses what comes next based on the state, for example "tool to call" or "final answer."
Checkpointer
The checkpointer is the component that saves the state at each step, under a conversation identifier called thread_id. It's what provides memory and the ability to resume.

According to the releases page of the official GitHub repository, the latest version of LangGraph as of November 18, 2026 is 1.2.22, released on November 14, 2026. The PyPI page specifies Python 3.10 or later. An equivalent library, LangGraph.js, exists for JavaScript and TypeScript.

#What's the difference between LangGraph and LangChain?

The complete kit for building your own AI copilot.

Benefit from our experience and a guided path to build your local copilot and get comfortable with your coding assistant.

  • Lifetime online access
  • PDF + files
  • Refunded within 30 days

LangChain is the vendor's agent framework: according to the official documentation, it provides the abstractions and integrations for models, tools, and agent loops. LangGraph provides the engine that orchestrates these building blocks with explicit state, persistence, and pauses. The documentation notes that LangGraph does not require LangChain, even though its examples use it.

The rule given in the LangGraph documentation is simple: use LangGraph when you need explicit control over state and flow. For a ready-made agent loop, LangChain's create_agent function or the Deep Agents layer provide a higher-level loop that's already written. LangChain defines an agent as a model that calls tools in a loop until the task is complete: that's exactly the loop you design yourself with LangGraph.

LangGraph, LangChain, Deep Agents, CrewAI: which tool for which need (official documentation as of November 18, 2026; the control column reflects the editors' assessment)
ToolWhat it isChoose it ifFlow control
LangGraphOrchestration engine: graph, state, persistence, interruptsYou want to control every step, resume a conversation, add human approvalFull: you write the graph
LangChain (create_agent)Agent framework and model connectorsYou want an agent with tools in just a few linesStandard loop, customizable via middleware
Deep AgentsLayer on top of LangGraph: planning, subagents, filesYou want an agent that plans long tasks without coding everything yourselfLow, the structure is provided
CrewAIFramework for role-based agent teamsYou think in roles (researcher, writer) rather than in graphsModerate, through roles and tasks

For a first try, this site's guide to LangChain and Ollama remains the shortest path. LangGraph becomes useful when the agent needs to remember things from one session to the next, ask for your approval, or follow a controlled, step-by-step flow.

#What does LangGraph need to run locally?

To run a LangGraph agent without the cloud, you need Python 3.10 or later, Ollama installed on the machine, and a local model capable of tool calling. No API key is required: the official quickstart uses Anthropic by default, but LangChain's Ollama integration page shows how to swap in a local model.

The most common sticking point is the model. According to the Ollama integration documentation, bind_tools() works with a Ollama model that supports tool calling, such as gpt-oss:20b. A model without this capability replies in text instead of triggering the tool, and the LangGraph agent never goes through the tool node.

Ollama models that support tool calling for a LangGraph agent (Ollama library accessed November 18, 2026)
Ollama modelSize shown by OllamaAdvertised contextFor which machine
qwen3:8b5.2 GB40K8 GB graphics card or 16 GB Mac, to get started
qwen3:14b9.3 GB40K12 GB graphics card, better instruction following
gpt-oss:20b14 GB128K16 GB GPU or Mac with 24 GB or more; the model used in the official examples

These sizes are the file sizes shown by Ollama; the conversation context is added on top in memory. The machine column is an estimate based on these sizes, not a measurement. According to the Ollama documentation, acceleration uses the Metal API on Mac and CUDA (Nvidia) or ROCm (AMD) on PC: a Mac's unified memory and a graphics card's memory can't be compared directly.

#What Ollama context window for a LangGraph agent?

The Ollama context window is the most commonly overlooked setting for a LangGraph agent. According to the Ollama documentation consulted on November 18, 2026, Ollama defaults to 4K tokens of context with less than 24 GiB of video memory, 32K from 24 to 48 GiB, and 256K above that, and recommends at least 64,000 tokens for agents and coding tools. With 4K, an agent's message history and tool descriptions are quickly truncated.

To raise this ceiling, the Ollama documentation specifies the OLLAMA_CONTEXT_LENGTH variable when starting the server, then ollama ps to check the allocated context. Stay within the model's limit (40K for qwen3:8b and qwen3:14b, 128K for gpt-oss:20b): more context requires more memory. On the Python side, ChatOllama exposes a num_ctx parameter.

macOS or Linux terminal (Ollama server)
OLLAMA_CONTEXT_LENGTH=64000 ollama serve
ollama ps

#How do you install LangGraph with Ollama?

Installing LangGraph for local use comes down to three Python packages and one Ollama model: langgraph for the graph, langchain for the tools and messages used in the quickstart, and langchain-ollama to talk to the local model. Start by creating a dedicated Python virtual environment for the project.

  1. 01
    Install Ollama and check that it responds
    Install Ollama from its official website, then launch it. According to Ollama's documentation, the server listens by default on port 11434 of the local machine (127.0.0.1). The ollama list command should run without errors in the terminal.
  2. 02
    Download a model that supports tool calling
    Run ollama pull gpt-oss:20b, or ollama pull qwen3:8b on a less powerful machine. Use the same model tag in ollama pull et in ChatOllama, as the LangChain documentation requires.
  3. 03
    Install LangGraph and LangChain
    In the virtual environment, run pip install -U langgraph, then pip install -U langchain. LangChain provides the tool decorator and the message classes used in the official quickstart.
  4. 04
    Install the Ollama connector
    Run pip install -qU langchain-ollama. This package includes the ChatOllama class, which replaces the quickstart's hosted model with your local model.
  5. 05
    Verify the installation
    In Python, import langgraph.graph and then langchain_ollama. If both imports succeed and ollama list shows your model, your LangGraph environment is ready.
macOS, Linux, or Windows terminal (virtual environment active)
pip install -U langgraph
pip install -U langchain
pip install -qU langchain-ollama
ollama pull gpt-oss:20b

#How do you build a stateful agent with LangGraph?

A minimal LangGraph agent consists of a state that accumulates messages, a node that calls the model, a node that runs the tools, and a conditional edge that loops between the two as long as the model requests a tool. The official quickstart builds a calculator this way with three tools: addition, multiplication, and division.

Switching LangGraph to local happens in step 1 of the quickstart, which itself invites you to adapt the model initialization: replace init_chat_model with ChatOllama and keep the rest as is. The instantiation below comes from the Ollama integration documentation; it names the variable llm, so rename it to model for model.bind_tools(tools) to work. This combination was not run for this guide: the example should answer 7 to Add 3 and 4.

Local model (langchain-ollama documentation)
from langchain_ollama import ChatOllama

llm = ChatOllama(
    model="gpt-oss:20b",
    temperature=0,
)

The agent state stores two things: the list of messages and the number of model calls. The Annotated type with operator.add tells LangGraph to append new messages to the list instead of replacing it. This mechanism, called a reducer, is what lets the agent keep the conversation history during execution.

State (LangGraph quickstart)
from langchain.messages import AnyMessage
from typing_extensions import TypedDict, Annotated
import operator

class MessagesState(TypedDict):
    messages: Annotated[list[AnyMessage], operator.add]
    llm_calls: int

Next come three functions described in the quickstart: llm_call calls the model with a system message, tool_node runs each requested tool call and returns a ToolMessage, and should_continue checks the last message and routes to tool_node if it contains a tool call, otherwise to END. You assemble and compile the graph like this:

Graph (LangGraph quickstart)
# Build workflow
agent_builder = StateGraph(MessagesState)

# Add nodes
agent_builder.add_node("llm_call", llm_call)
agent_builder.add_node("tool_node", tool_node)

# Add edges to connect nodes
agent_builder.add_edge(START, "llm_call")
agent_builder.add_conditional_edges(
    "llm_call",
    should_continue,
    ["tool_node", END]
)
agent_builder.add_edge("tool_node", "llm_call")

# Compile the agent
agent = agent_builder.compile()
!
Loop limit to tune for a local model
Since version 1.1.4, LangGraph allows 10,007 super-steps per run by default before raising GraphRecursionError, according to the Graph API documentation. A small local model that keeps calling the same tool endlessly will therefore run for a long time. Pass a low value in recursion_limit, at the top level of the config (not under configurable): the official examples use 3 to 10; about 25, our editorial choice, leaves the calculator some headroom.

#How do you give a LangGraph agent memory?

A LangGraph agent's memory relies on a checkpointer, passed to compile(), and a thread_id supplied with each call. The checkpointer saves the state at every step; the thread_id acts as the primary key for retrieving the right conversation. Same thread_id, same conversation; new thread_id, empty state. In the example below, taken from the Persistence page, builder corresponds to agent_builder from the quickstart.

Conversation memory (Persistence documentation)
from langgraph.checkpoint.memory import InMemorySaver
from langgraph.store.memory import InMemoryStore

checkpointer = InMemorySaver()
store = InMemoryStore()

graph = builder.compile(checkpointer=checkpointer, store=store)

result = graph.invoke(
    {"messages": [{"role": "user", "content": "Hi, my name is Bob."}]},
    {"configurable": {"thread_id": "thread-1"}},
)

InMemorySaver is fine for learning, but the LangGraph documentation warns that it keeps checkpoints in RAM: everything is lost when the process restarts. For a local agent that needs to remember things from one day to the next, LangGraph offers SqliteSaver, a checkpointer that writes to a SQLite file on your disk, described as suited to local use and installed separately: the package README gives the command uv add langgraph-checkpoint-sqlite.

Encrypted on-disk memory (Checkpointers documentation)
import sqlite3

from langgraph.checkpoint.serde.encrypted import EncryptedSerializer
from langgraph.checkpoint.sqlite import SqliteSaver

serde = EncryptedSerializer.from_pycryptodome_aes()  # reads LANGGRAPH_AES_KEY
checkpointer = SqliteSaver(sqlite3.connect("checkpoint.db"), serde=serde)

This official example encrypts the saved state: according to the LangGraph source code, the AES key is read from the LANGGRAPH_AES_KEY environment variable and must be 16, 24, or 32 bytes. The same code requires the PyCryptodome library, which is not among the dependencies installed by default: without it, the call fails with a message asking you to run pip install pycryptodome. An agent's conversations often contain personal data; an encrypted checkpoint.db file stays unreadable if the disk or a backup is copied.

→
SQLite checkpointer security setting
The langgraph-checkpoint-sqlite README recommends setting LANGGRAPH_STRICT_MSGPACK=true, or an explicit list of allowed modules, to restrict checkpoint deserialization to safe types and prevent code execution if the database is compromised.

#How do you add human approval in LangGraph?

LangGraph pauses an agent with the interrupt() function placed inside a node: the checkpointer saves the state, execution waits indefinitely, then resumes when you rerun the graph with Command(resume=...). This is how you get approval for a sensitive action, such as sending an email or deleting a file.

Pause for approval (Interrupts documentation)
from langgraph.types import interrupt

def approval_node(state: State):
    # Pause and ask for approval
    approved = interrupt("Do you approve this action?")

    # When you resume, Command(resume=...) returns that value here
    return {"approved": approved}

The documentation requires three things: a checkpointer, a thread_id in the configuration, and a JSON-serializable pause payload. The documentation recommends event streaming (stream_events, version v3), but graph.invoke() still works: the question surfaces in the __interrupt__ key of the result, and the value passed to Command(resume=...) becomes the return value of interrupt() inside the node.

#With LangGraph running locally, what still goes online?

With ChatOllama, a local checkpointer, and tracing disabled, a LangGraph agent sends no data off your machine: the model runs in Ollama, and state stays in RAM or in a SQLite file. Two optional components of the ecosystem, however, go through LangChain's servers: LangSmith tracing and the Studio interface.

LangSmith Studio, the free visual interface that displays the graph and each step, requires a LangSmith API key to connect to the local agent. Studio runs through langgraph dev, the LangGraph CLI's in-memory development server, which requires Python 3.11 or later. According to the Studio documentation, with tracing disabled, no data leaves your local server.

Agent .env file
LANGSMITH_TRACING=false
Local LangGraph agent: what stays on the machine and what can leave it (official documentation, November 18, 2026)
ComponentWhere it runsData sent online
Model via ChatOllamaOllama, on your machineNone
LangGraph graph and toolsYour Python processOnly if a tool calls a web service
InMemorySaver or SqliteSaverRAM or local fileNone
LangSmith tracingLangSmith platformExecution traces, unless LANGSMITH_TRACING=false
LangSmith StudioWeb interface connected to langgraph devLangSmith key required; no data if tracing is turned off
Frequently asked questions
Is LangGraph free?+
Yes. LangGraph is released under the MIT license, free for both personal and commercial use, and installs from PyPI. With Ollama and an open-weights model, a local LangGraph agent costs you nothing beyond electricity. Online services such as the LangSmith platform are optional for running a graph.
CrewAI or LangGraph: which should you choose for a local agent?+
LangGraph is a good fit when you want to define each step, maintain precise state, and add approval checkpoints. CrewAI is a good fit when you think in terms of a team of role-based agents, such as a researcher and a writer. The choice depends mainly on how much control you want over the flow, not on how powerful your machine is.
Can LangGraph use MCP servers?+
Yes, through LangChain. MCP support is now built into LangChain: you install it with pip install "langchain[mcp]", and the MCPAdapter class, built on FastMCP, converts an MCP server's tools into LangChain tools that an agent can use. The old langchain-mcp-adapters repository is no longer actively maintained, so avoid examples that still import it.
Is there a GUI for LangGraph?+
The official interface is LangSmith Studio, which is free according to its documentation: it shows the graph, each step, tool calls, and state. Studio connects to the local server started by langgraph dev and requires a LangSmith account and API key. Your agent code stays on your machine; turn off tracing with LANGSMITH_TRACING=false so that no traces are sent.
Where can you learn LangGraph for free?+
LangChain Academy offers a free, structured introductory course on LangGraph, listed in the official repository's README. The documentation's quickstart, which builds a calculator agent, is the best first exercise; with ChatOllama in place of the hosted model, you can complete the whole thing locally.

#Sources and verification as of November 18, 2026

The version, license, prerequisites, commands, and code snippets were checked on November 18, 2026, against the official LangGraph and LangChain documentation, the GitHub repository, and the Ollama library. LangGraph ships several releases a month, so double-check the version and examples before you copy any code.

Did this guide help you?

Feedback, an error, or a clarification? Let us know—it improves the guide for everyone.