Table of Contents
🌏 中文版
LangChain v1 Agents is the high-level entry point for tool-calling agents. create_agent combines a model, tools, and instructions into a loop that continues until the model returns a final answer or reaches a stop condition.
The current design should not be understood through LangChain's early collection of chains and executors. create_agent runs on LangGraph, while middleware is the supported boundary for dynamic prompts, model selection, tool errors, PII controls, and human approval.
A minimal agent is a model plus tools
from langchain.agents import create_agent
from langchain.tools import tool
@tool
def search_orders(customer_id: str) -> str:
"""Return recent orders for a customer."""
return "order-42: shipped"
agent = create_agent(
model="openai:gpt-5-mini",
tools=[search_orders],
system_prompt="Answer support questions using verified order data.",
)
result = agent.invoke({"messages": [{"role": "user", "content": "Where is my order?"}]})
Tools may be ordinary Python functions or coroutines. The framework exposes their schemas, executes calls, returns results to state, and decides whether another model turn is needed. It does not replace authorization or domain validation inside those tools.
Structured output is the completion contract
The agent documentation accepts schemas through response_format. It uses a provider-native strategy when available and can fall back to a tool-based strategy. This changes completion from “the model says it is done” to “the result satisfies a schema,” though factual and domain validation remain application responsibilities.
Middleware is the main v1 extension point
Middleware can run around the agent, model, and tools. Common uses include dynamic model selection, context compression, tool-error handling, PII filtering, fallbacks, and approval gates. Ordering becomes part of the control flow, so test each layer's inputs, outputs, and failure behavior instead of stacking message-mutating middleware without traces.
The LangChain–LangGraph boundary
create_agent fits the standard model-tools-model loop. When a system needs custom nodes, edges, branches, subgraphs, checkpoints, or precise resume points, use LangGraph directly. LangChain is the high-level agent abstraction; LangGraph is its orchestration runtime.
Overall
LangChain v1 suits Python teams that want a quick but extensible agent loop with a path down to LangGraph. Start with one tool and a fixed evaluation set, then add structured output and one middleware at a time. Preserve traces and success rates so each abstraction earns its place. See the agent framework guide for the wider comparison.
References
Loading...