LangGraph: build a stateful agent in local

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.
#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?
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.
| Tool | What it is | Choose it if | Flow control |
|---|---|---|---|
| LangGraph | Orchestration engine: graph, state, persistence, interrupts | You want to control every step, resume a conversation, add human approval | Full: you write the graph |
| LangChain (create_agent) | Agent framework and model connectors | You want an agent with tools in just a few lines | Standard loop, customizable via middleware |
| Deep Agents | Layer on top of LangGraph: planning, subagents, files | You want an agent that plans long tasks without coding everything yourself | Low, the structure is provided |
| CrewAI | Framework for role-based agent teams | You think in roles (researcher, writer) rather than in graphs | Moderate, 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 model | Size shown by Ollama | Advertised context | For which machine |
|---|---|---|---|
| qwen3:8b | 5.2 GB | 40K | 8 GB graphics card or 16 GB Mac, to get started |
| qwen3:14b | 9.3 GB | 40K | 12 GB graphics card, better instruction following |
| gpt-oss:20b | 14 GB | 128K | 16 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.
#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.
- 01Install Ollama and check that it respondsInstall 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.
- 02Download a model that supports tool callingRun 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.
- 03Install LangGraph and LangChainIn 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.
- 04Install the Ollama connectorRun pip install -qU langchain-ollama. This package includes the ChatOllama class, which replaces the quickstart's hosted model with your local model.
- 05Verify the installationIn Python, import langgraph.graph and then langchain_ollama. If both imports succeed and ollama list shows your model, your LangGraph environment is ready.
#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.
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.
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:
#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.
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.
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.
#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.
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.
| Component | Where it runs | Data sent online |
|---|---|---|
| Model via ChatOllama | Ollama, on your machine | None |
| LangGraph graph and tools | Your Python process | Only if a tool calls a web service |
| InMemorySaver or SqliteSaver | RAM or local file | None |
| LangSmith tracing | LangSmith platform | Execution traces, unless LANGSMITH_TRACING=false |
| LangSmith Studio | Web interface connected to langgraph dev | LangSmith key required; no data if tracing is turned off |
Is LangGraph free?+
CrewAI or LangGraph: which should you choose for a local agent?+
Can LangGraph use MCP servers?+
Is there a GUI for LangGraph?+
Where can you learn LangGraph for free?+
#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.
- Source: LangGraph overview (LangChain)
- Source: LangGraph quickstart, calculator agent (LangChain)
- Source: ChatOllama integration (LangChain)
- Source: context length (Ollama)
- Source: persistence and checkpointers (LangChain)
- Source: interrupts and human-in-the-loop approval (LangChain)
- Source: LangSmith Studio and tracing (LangChain)
- Source: LangGraph version 1.2.22 (GitHub)
- Source: gpt-oss in the Ollama library
- Source: MCP in LangChain (LangChain)
Feedback, an error, or a clarification? Let us know—it improves the guide for everyone.