LangChain Agents in Production: Beyond the Model
What makes a LangChain or LangGraph agent production-ready: checkpointers, human approval, retries, streaming, LangSmith tracing and evals, and deployment.
A model that answers well in a notebook can still fail badly once real users arrive. The process restarts mid-task, a payment API times out, the agent wants to run a DELETE statement nobody approved, or a prompt change quietly makes answers worse. None of those problems is solved by picking a better model. This page walks through the pieces LangChain’s own stack offers for them, using only current APIs from the LangChain docs.
An earlier version of this article quoted analyst forecasts and speed-up figures we could not trace to any primary source. They are gone. What remains is what the official documentation says and shows.
Which layer does what
LangChain now ships as a few related projects, and it helps to know which one owns each concern:
| Project | Role, per the docs |
|---|---|
| LangChain | The agent framework. create_agent is its configurable harness: model, tools, prompt and middleware |
| LangGraph | Low-level orchestration runtime: persistence, durable execution, streaming, interrupts |
| LangSmith | Tracing, evaluation, prompts and deployment, usable across frameworks |
| Deep Agents | A heavier harness (planning, subagents, filesystem tools) built on LangGraph |
Since v1.0, LangChain recommends create_agent in place of the earlier langgraph.prebuilt.create_react_agent, so check older tutorials before copying them. Agents built with it sit on top of LangGraph, so the persistence and interrupt features below apply to them directly. If you want a quick reference to the framework itself, see our LangChain Agents listing, or the LangChain.js page for the TypeScript version.
Persistence: survive restarts and pick up where you left off
LangGraph saves a snapshot of state at every super-step (one tick of the graph) through a checkpointer, grouped by a thread_id. That one mechanism powers conversation memory, human approval, time travel debugging and recovery from failures. When a node fails, writes from sibling nodes that already finished in the same step are kept, so they are not run again on resume.
The common mistake is shipping with InMemorySaver. It lives in RAM, and the docs warn that every checkpoint disappears when the process restarts. For production, they show a Postgres-backed saver passed straight into create_agent:
from langchain.agents import create_agent
from langgraph.checkpoint.postgres import PostgresSaver
DB_URI = "postgresql://postgres:postgres@localhost:5432/postgres?sslmode=disable"
with PostgresSaver.from_conn_string(DB_URI) as checkpointer:
checkpointer.setup() # auto create tables in PostgreSQL
agent = create_agent(
"gpt-5.5",
tools=[get_user_info],
checkpointer=checkpointer,
)
Install it with pip install -U langgraph-checkpoint-postgres "psycopg[binary]". Other separately installed savers include SQLite (meant for local work), MongoDB and Azure Cosmos DB. Each call then needs a config such as {"configurable": {"thread_id": "1"}}.
Three practical details from the persistence docs:
- Durability mode. You choose per run.
"exit"writes only when the run ends, which is fastest but cannot recover from a crash midway."async"writes while the next step runs, with a small window where a crash can lose a checkpoint."sync"writes each checkpoint before moving on, trading some speed for the strongest guarantee. - Growth. Checkpoints pile up on long threads, raising latency and storage cost. Plan a pruning job.
- Keys. With
PostgresSaver, keepthread_idunder 255 characters.
To continue a thread after an error, invoke the graph with None as input and the same config; LangGraph loads the latest checkpoint and retries the unfinished work. Sending new input instead starts from the entry point with the saved state.
Human approval before risky tool calls
For actions you do not want an agent taking alone, create_agent has a built-in HumanInTheLoopMiddleware. You list which tools need review and which decisions a reviewer may make. When a call matches, the agent raises an interrupt and its state is checkpointed, so a person can respond minutes or days later. This is from the human-in-the-loop guide:
from langchain.agents import create_agent
from langchain.agents.middleware import HumanInTheLoopMiddleware
from langgraph.checkpoint.memory import InMemorySaver
agent = create_agent(
model="gpt-5.5",
tools=[write_file, execute_sql, read_data],
middleware=[
HumanInTheLoopMiddleware(
interrupt_on={
"write_file": True, # All decisions (approve, edit, reject, respond) allowed
"execute_sql": {"allowed_decisions": ["approve", "reject"]}, # No editing allowed
"read_data": False, # Safe operation, no approval needed
},
description_prefix="Tool execution pending approval",
),
],
checkpointer=InMemorySaver(),
)
The four decisions are approve (run as proposed), edit (change the arguments first), reject (skip it and tell the model why) and respond (the human’s reply stands in for the tool’s output, for “ask user” style tools). Resume with the same thread:
from langgraph.types import Command
agent.invoke(
Command(
resume={"decisions": [{"type": "approve"}]} # or "reject"
),
config=config, # Same thread ID to resume the paused conversation
version="v2",
)
The example uses InMemorySaver for brevity, but the docs say to use a persistent saver such as AsyncPostgresSaver or MongoDBSaver in production. Newer releases add a when predicate so only some calls pause (for example, SQL that is not a plain SELECT, from langchain>=1.3.3) and a "per_call" interrupt mode (from langchain>=1.4.6), which LangChain recommends for new agents.
One rule catches people out. When an interrupt resumes, the whole node runs again from its first line, not from the line that paused. Anything before interrupt(), such as a write to an external system, should be idempotent or it may happen twice. The interrupts page covers this in detail.
Retries, fallbacks and limits
At the agent level, middleware handles transient failures. ToolRetryMiddleware and ModelRetryMiddleware retry with exponential backoff, ModelFallbackMiddleware switches to other models when the primary fails, and ModelCallLimitMiddleware caps model calls per thread or per run to stop runaway loops and spending:
from langchain.agents import create_agent
from langchain.agents.middleware import ToolRetryMiddleware
agent = create_agent(
model="gpt-5.5",
tools=[search_tool, database_tool],
middleware=[
ToolRetryMiddleware(
max_retries=3,
backoff_factor=2.0,
initial_delay=1.0,
),
],
)
If you build a custom graph in LangGraph instead, you set a RetryPolicy per node, and from langgraph>=1.2 per-node timeouts and error handlers. The defaults are three attempts, a half-second first wait and a doubling backoff with jitter. Timeouts only apply to async nodes.
The fault tolerance page is worth reading for one reason above all: a retry runs the whole node again, which is at-least-once behaviour. If a node charges a card and then the process dies, a retry can charge it again. The fix the docs give is an idempotency key built from state that is already saved (an order ID, say), never one generated inside the same node.
Streaming so users are not staring at a spinner
Agents can take many steps. Streaming lets you show progress as it happens. The stream modes are updates (state after each agent step), messages (LLM tokens with metadata) and custom (your own signals from inside tools or nodes). The token example from the streaming docs:
for chunk in agent.stream(
{"messages": [{"role": "user", "content": "What is the weather in SF?"}]},
stream_mode="messages",
version="v2",
):
if chunk["type"] == "messages":
token, metadata = chunk["data"]
print(f"node: {metadata['langgraph_node']}")
print(f"content: {token.content_blocks}")
For new applications the docs now recommend event streaming (stream_events with version="v3"), added in LangChain v1.3, which gives a separate iterator for messages, tool calls and other projections.
Tracing and evaluation with LangSmith
You cannot fix what you cannot see. Agents made with create_agent send traces to LangSmith with no code changes once the environment is set. The tracing quickstart uses:
export LANGSMITH_TRACING=true
export LANGSMITH_API_KEY="<your-langsmith-api-key>"
In LangSmith Cloud’s agent-based workspaces you also set LANGSMITH_AGENT_ID and LANGSMITH_AGENT_ENVIRONMENT after registering the agent once; project-based and self-hosted setups use LANGSMITH_PROJECT instead. Each trace records the input, every model and tool call, and the final answer, and you can attach tags and metadata such as a user or session ID.
Evaluation comes in two flavours in LangSmith’s docs. Offline, you run the agent over a curated dataset and compare experiments to catch regressions before shipping. Online, evaluators score live production traces for things like safety or format, with sampling to keep costs down. The loop LangSmith suggests is to turn failing production traces into dataset examples, so one bug becomes a permanent test. LangChain’s testing guide adds that agents tend to need more integration testing than usual, because they chain several components and model output varies from run to run. If you want an open-source tracing alternative, Langfuse is in our evaluation and monitoring hub.
Deployment options
You can host an agent anywhere you can run Python, but then the checkpointer database, background runs and scaling are your job. LangSmith Deployment is LangChain’s runtime for that work, and its Agent Server manages persistence for you. It comes in four shapes:
| Option | Who runs what |
|---|---|
| Cloud | LangChain hosts control plane, data plane and databases (Plus plan or above) |
| Hybrid | LangChain hosts the control plane; your VPC runs the Agent Servers |
| Self-hosted | Everything in your Kubernetes cluster (Enterprise plan) |
| Standalone Agent Server | Docker or Kubernetes, your own PostgreSQL and Redis, no control plane |
The Cloud path deploys from a GitHub repository, and the docs say a first deploy can take about 15 minutes. LangSmith Deployment also accepts agents from other frameworks via the Functional API or a wrapper package.
A short checklist
Before calling a LangChain agent production-ready, check that it has:
- A database-backed checkpointer and a deliberate durability mode.
- Human review on any tool that writes, deletes, pays or sends.
- Idempotent side effects, since both retries and resumed interrupts re-run whole nodes.
- Retry, fallback and call-limit middleware with sensible caps.
- Streaming to the UI.
- LangSmith (or another tracer) on from day one, plus an offline eval dataset.
- A hosting plan that covers the database, not just the API.
LangGraph and LangChain are both MIT licensed. For other frameworks that handle orchestration differently, browse our agent frameworks hub.
Written by AI Agents Directory
Editorial team
Facts in this guide are checked against official documentation and repositories, which are linked in the article.