LangChain v1 是一个专注于构建智能体的、面向生产环境的基础框架。 我们围绕三项核心改进简化了该框架:Documentation Index
Fetch the complete documentation index at: https://langchain-zh.cn/llms.txt
Use this file to discover all available pages before exploring further.
create_agent
LangChain 中构建智能体的新标准,替代
langgraph.prebuilt.create_react_agent。Standard content blocks
新的
content_blocks 属性,提供跨提供商的现代 LLM 功能的统一访问。Simplified namespace
langchain 命名空间已简化,专注于智能体的基本构建块,遗留功能已移至 langchain-classic。create_agent
create_agent 是 LangChain 1.0 中构建智能体的标准方式。它提供了比 langgraph.prebuilt.create_react_agent 更简单的接口,同时通过使用 middleware 提供了更大的自定义潜力。
create_agent 基于基本的智能体循环构建——调用模型,让它选择要执行的工具,然后在它不再调用任何工具时结束:

Middleware
Middleware 是create_agent 的定义特性。它提供了一个高度可定制的入口点,提高了您能构建内容的上限。
优秀的智能体需要 上下文工程:在正确的时间将正确的信息传递给模型。Middleware 帮助您通过可组合的抽象控制动态提示、对话摘要、选择性工具访问、状态管理和护栏。
Prebuilt middleware
LangChain 为常见模式提供了一些 预构建中间件,包括:PIIMiddleware:在发送给模型之前删除敏感信息SummarizationMiddleware:当对话历史过长时压缩它HumanInTheLoopMiddleware:对敏感工具调用要求批准
Custom middleware
您也可以构建自定义中间件以满足您的需求。中间件在智能体执行的每一步都暴露钩子:
AgentMiddleware 类的子类上实现以下任何钩子来构建自定义中间件:
| Hook | When it runs | Use cases |
|---|---|---|
before_agent | Before calling the agent | Load memory, validate input |
before_model | Before each LLM call | Update prompts, trim messages |
wrap_model_call | Around each LLM call | Intercept and modify requests/responses |
wrap_tool_call | Around each tool call | Intercept and modify tool execution |
after_model | After each LLM response | Validate output, apply guardrails |
after_agent | After agent completes | Save results, cleanup |
Built on LangGraph
因为create_agent 是基于 LangGraph 构建的,所以您自动获得了对长运行和可靠智能体的内置支持,通过:
Persistence
会话在跨会话时自动持久化,具有内置的检查点功能
Streaming
实时流式传输令牌、工具调用和推理轨迹
Human-in-the-loop
暂停智能体执行以在敏感操作前获得人类批准
Time travel
将对话回退到任何时间点并探索替代路径和提示
Structured output
create_agent 改进了结构化输出生成:
- Main loop integration:结构化输出现在在主循环中生成,而不是需要额外的 LLM 调用
- Structured output strategy:模型可以选择调用工具或使用提供商侧的结构化输出生成
- Cost reduction:消除了额外 LLM 调用的额外费用
ToolStrategy 的 handle_errors 参数控制错误处理:
- Parsing errors:模型生成的数据与所需结构不匹配
- Multiple tool calls:模型为结构化输出架构生成了 2 个或更多工具调用
Standard content blocks
内容块支持目前仅适用于以下集成:更广泛的内容块支持将逐渐扩展到更多提供商。
content_blocks 属性引入了跨提供商工作的消息内容的标准表示形式:
Benefits
- Provider agnostic:无论提供商如何,使用相同的 API 访问推理轨迹、引用、内置工具(网络搜索、代码解释器等)和其他功能
- Type safe:所有内容块类型的完整类型提示
- Backward compatible:标准内容可以 延迟加载,因此没有相关的破坏性更改
Simplified package
LangChain v1 简化了langchain 包命名空间,专注于智能体的基本构建块。精简后的命名空间暴露了最有用和最相关的功能:
Namespace
| Module | What’s available | Notes |
|---|---|---|
langchain.agents | create_agent, AgentState | Core agent creation functionality |
langchain.messages | Message types, content blocks, trim_messages | Re-exported from langchain-core |
langchain.tools | @tool, BaseTool, injection helpers | Re-exported from langchain-core |
langchain.chat_models | init_chat_model, BaseChatModel | Unified model initialization |
langchain.embeddings | Embeddings, init_embeddings | Embedding models |
langchain-core 重新导出的,以便为您提供用于构建智能体的聚焦 API 表面。
langchain-classic
遗留功能已移至 langchain-classic,以保持核心包精简且专注。
langchain-classic 中包含:
- Legacy chains and chain implementations
- Retrievers (e.g.
MultiQueryRetrieveror anything from the previouslangchain.retrieversmodule) - The indexing API
- The hub module (for managing prompts programmatically)
langchain-communityexports- Other deprecated functionality
langchain-classic:
Migration guide
查看我们的 迁移指南 以帮助将代码更新为 LangChain v1。Reporting issues
请在 GitHub 上报告发现的任何 1.0 问题,并使用'v1' 标签。
Additional resources
LangChain 1.0
阅读公告
Middleware guide
深入探讨中间件
Agents Documentation
完整的智能体文档
Message Content
新的内容块 API
Migration guide
如何迁移到 LangChain v1
GitHub
报告问题或贡献
See also
- Versioning – Understanding version numbers
- Release policy – Detailed release policies
Connect these docs to Claude, VSCode, and more via MCP for real-time answers.

