LangChain today, create_agent and middleware
If your mental model of LangChain is "chains, LCEL pipes and a hundred agent classes", it is out of date. Since the 1.0 release the library has been slimmed down around one idea: a single agent constructor, create_agent, built on LangGraph, plus a middleware system for customizing it. As of October 2026 the Python package is on the 1.4 line. This doc walks through the pieces you actually use now.
Why it matters
LangChain is still the most common entry point into the ecosystem, and it now has a much clearer job. It gives you:
- A model interface that works across providers, with model strings like
"openai:gpt-5.5"or"claude-sonnet-4-6". - An agent loop (
create_agent) that handles tool calling, streaming and state, and runs on the LangGraph runtime, so you get persistence and interrupts for free. - Middleware, which is the real story of v1. Instead of subclassing an agent or rewriting its prompt, you plug in small, composable hooks that run before or after the model and tools.
- Integrations: hundreds of chat models, embeddings, vector stores, loaders and tools, now split into separate
langchain-*partner packages.
The older chain abstractions moved to a langchain-classic package for teams that still depend on them. If you are starting fresh, you do not need them.
How it works
create_agent builds a small graph: a model node and a tools node in a loop, with a set of hook points around them. Middleware attaches to those hook points.
Rendering diagram…
There are two kinds of hooks, according to the custom middleware docs:
- Node style hooks (
before_agent,before_model,after_model,after_agent) run in sequence at a point in the loop and can read or update state, or jump to another point. - Wrap style hooks (
wrap_model_call,wrap_tool_call) wrap the actual call and receive ahandler, so you can retry it, swap the model, short circuit with a cached answer, or edit the request and response.
The built-in middleware catalogue covers most of what teams used to hand roll: SummarizationMiddleware, HumanInTheLoopMiddleware, ModelRetryMiddleware, ModelFallbackMiddleware, ToolRetryMiddleware, ModelCallLimitMiddleware, ToolCallLimitMiddleware, PIIMiddleware, TodoListMiddleware, LLMToolSelectorMiddleware, ContextEditingMiddleware and more. LangChain's "Deep Agents" package (deepagents) adds filesystem and subagent middleware on top, for long running research or coding style agents.
Reference architecture
A typical production agent built with create_agent looks like this. The model and tools stay simple; policy lives in middleware; state lives in a checkpointer.
Rendering diagram…
The checkpointer matters even if you never think about LangGraph. Human approval works by pausing the graph and saving its state; without a checkpointer there is nowhere to resume from.
Code
Here is an email assistant with three middlewares: redact emails in user input, summarize old history once it gets long, and require human approval before sending anything. It uses the APIs from the current LangChain docs.
from langchain.agents import create_agent
from langchain.agents.middleware import (
HumanInTheLoopMiddleware,
PIIMiddleware,
SummarizationMiddleware,
)
from langchain.tools import tool
from langgraph.checkpoint.memory import InMemorySaver
from langgraph.types import Command
@tool
def read_inbox(limit: int = 5) -> list[str]:
"""Return the subjects of the latest emails."""
return ["Invoice overdue", "Lunch Friday?"][:limit]
@tool
def send_email(to: str, subject: str, body: str) -> str:
"""Send an email."""
return f"sent to {to}"
agent = create_agent(
model="claude-sonnet-4-6",
tools=[read_inbox, send_email],
system_prompt="You are a concise email assistant.",
middleware=[
PIIMiddleware("email", strategy="redact", apply_to_input=True),
SummarizationMiddleware(
model="gpt-5.4-mini",
trigger=("tokens", 4000),
keep=("messages", 20),
),
HumanInTheLoopMiddleware(
interrupt_on={
"send_email": {"allowed_decisions": ["approve", "edit", "reject"]},
"read_inbox": False,
}
),
],
checkpointer=InMemorySaver(),
)
config = {"configurable": {"thread_id": "user-42"}}
result = agent.invoke(
{"messages": [{"role": "user", "content": "Reply to the invoice email saying paid."}]},
config=config,
)
# If the agent wants to send, the run pauses and the interrupt is in the result
if "__interrupt__" in result:
result = agent.invoke(
Command(resume={"decisions": [{"type": "approve"}]}),
config=config,
)
print(result["messages"][-1].content)
And a custom wrap style middleware, which is how you add your own policy. This one retries the model call on exceptions:
from typing import Callable
from langchain.agents.middleware import ModelRequest, ModelResponse, wrap_model_call
@wrap_model_call
def retry_model(
request: ModelRequest,
handler: Callable[[ModelRequest], ModelResponse],
) -> ModelResponse:
for attempt in range(3):
try:
return handler(request)
except Exception:
if attempt == 2:
raise
You pass retry_model in the middleware list like any built-in.
Trade-offs and pitfalls
- Middleware order matters. Middlewares run in list order on the way in and reverse order on the way out, like web framework middleware. Put redaction before anything that logs or summarizes.
- Summarization changes what the model sees. It is lossy by design. Keep enough recent messages and test that critical facts (account IDs, decisions) survive.
- Interrupts rerun code. When a graph resumes, the node that interrupted runs again from the start. Keep side effects after the approval point, not before it.
- Version churn is lower but not zero. Pin
langchainand the partner packages together. Old blog posts usingAgentExecutororinitialize_agentwill not match current APIs. - The abstraction can hide the prompt. Turn on LangSmith or another tracer so you can see the final request after all middleware has run.
When to pick it: you want a provider neutral agent with good defaults, you expect to need persistence or human approval later, or you want the large integration catalogue. It is also the easiest on ramp to LangGraph when you outgrow the prebuilt loop.
When not to: you only need one structured output call (the provider SDK is simpler), you are all in on one vendor and want their newest features the day they ship, or your team strongly prefers a type first style, in which case look at Pydantic AI.
Checklist
- Start with
create_agentbefore reaching for a custom graph. - Express policy (PII, approvals, limits, fallbacks) as middleware, not prompt text.
- Always pass a checkpointer if any middleware can interrupt.
- Use a stable
thread_idper conversation. - Order middleware deliberately and document why.
- Pin
langchain,langgraphand partner package versions together. - Trace every run in development.