Doramagic 项目包 · 项目说明书
langchain 项目
智能体工程平台。
LangChain v1 概览与整体架构
LangChain 是一个用于构建智能体(Agent)和大语言模型(LLM)驱动应用的框架,它通过可互操作的组件与第三方集成,将 AI 应用的开发流程串联起来,同时为底层技术的演进预留了扩展空间。资料来源:[README.md:1-13]()。
继续阅读本节完整说明和来源证据。
1. 项目定位与核心价值
LangChain 是一个用于构建智能体(Agent)和大语言模型(LLM)驱动应用的框架,它通过可互操作的组件与第三方集成,将 AI 应用的开发流程串联起来,同时为底层技术的演进预留了扩展空间。资料来源:README.md:1-13。
框架的设计理念是提供灵活的抽象层级(Flexible abstraction layers),让开发者可以依据需求选择合适的抽象程度——从高层封装(便于快速启动)到低层组件(用于细粒度控制),LangChain 能够随应用复杂度一起成长。资料来源:README.md:20-23。
对于希望快速上手并获得开箱即用能力的用户,官方推荐使用基于 LangChain 构建的更高级别的包 Deep Agents,它内置了规划、子智能体、文件系统使用等常见用法。资料来源:README.md:9-13。
2. 包结构与生态分层
LangChain 仓库采用 monorepo 形式组织,多个包分别承担不同职责。下面以表格形式展示核心包及其角色:
| 包名 | 路径 | 主要职责 |
|---|---|---|
langchain-core | libs/core | 提供整个生态的基础抽象,包括消息、提示词、文档、工具、向量存储接口等,是最底层的依赖。资料来源:libs/core/README.md:18-26。 |
langchain (v1) | libs/langchain_v1 | 主入口包,对外提供 init_chat_model 等高层 API、预构建的智能体架构与模型集成,强调"10 行代码即可接入 OpenAI、Anthropic、Google 等"。资料来源:libs/langchain_v1/README.md:16-22。 |
langchain-classic | libs/langchain | 保留旧版 langchain_chain、AgentExecutor、ReAct、langchain-community 再导出、索引 API 等已弃用但仍维护的功能,推荐在多数场景下使用主 langchain 包。资料来源:libs/langchain/README.md:8-15。 |
| 合作伙伴包 | libs/partners/* | 各模型与向量库等第三方集成的独立包(如 langchain-openai、langchain-anthropic、langchain-chroma、langchain-exa、langchain-xai 等),拥有独立版本与依赖管理。资料来源:libs/README.md:3-12。 |
langchain-text-splitters | libs/text-splitters | 提供多种文本切分器,专门用于把长文档切分为适合嵌入与检索的块。资料来源:libs/text-splitters/README.md:12-15。 |
langchain-model-profiles | libs/model-profiles | 一个 CLI 工具,从 models.dev 拉取模型能力数据,同步聊天模型的 .profile 字段(上下文窗口、模态、工具调用、结构化输出等)。资料来源:libs/model-profiles/README.md:8-21。 |
下面是包之间的依赖关系示意图:
flowchart TB
User[开发者应用]
User --> LC[langchain v1<br/>高层 API 与智能体工厂]
User --> DA[Deep Agents<br/>规划/子智能体/文件系统]
User --> LG[LangGraph<br/>可控智能体工作流]
LC --> Core[langchain-core<br/>基础抽象]
DA --> Core
LG --> Core
LC --> Partners[合作伙伴包<br/>OpenAI / Anthropic / Chroma / Exa / xAI ...]
Partners --> Core
LC --> Class[langchain-classic<br/>已弃用兼容层]
Class --> Core
Class --> Community[langchain-community 再导出]
LS[LangSmith] -.观测/调试.-> User3. 快速上手与关键 API
LangChain v1 的入门体验被显著简化,安装后即可调用统一入口创建模型实例:
pip install langchain
from langchain.chat_models import init_chat_model
model = init_chat_model("openai:gpt-5.4")
result = model.invoke("Hello, world!")
资料来源:README.md:15-31。init_chat_model 接受 provider:model 形式的字符串,从而以统一接口切换不同提供商的聊天模型,避免为每个集成编写不同的客户端代码。
若需要更复杂的智能体编排(带状态、循环、人工介入),官方推荐使用 LangGraph——一个用于构建可控智能体工作流的框架。资料来源:README.md:25-29。在生产环境中,开发、调试、部署则由 LangSmith 提供支持。资料来源:README.md:33-35。
4. v1 与经典层的演进关系
在 v1 中,旧的 AgentExecutor、initialize_agent、ReActDocstoreAgent 等 API 被整体迁移到 langchain_classic 包,并标注了弃用警告与预计的移除版本(多数计划在 2.0.0 移除)。例如:
@deprecated(
"0.1.0",
message=AGENT_DEPRECATION_WARNING,
removal="2.0.0",
)
class ReActDocstoreAgent(Agent):
...
资料来源:libs/langchain/langchain_classic/agents/react/base.py:33-46。initialize_agent 的文档字符串同样建议迁移到 langchain.agents.create_agent,并附有官方迁移指南的链接。资料来源:libs/langchain/langchain_classic/agents/initialize.py:1-22。
社区中常被引用的"agent 行为"问题,例如"流式输出被结构化输出阻塞"(#34818)、"AgentExecutor 在达到迭代上限后不支持 early_stopping_method='generate'"(#16263)、"convert_to_openai_messages` 修改调用方输入"(#37894),多与 classic 层的旧 API 相关——这也是官方推动 v1 新智能体工厂与 LangGraph 取代这些路径的动力。
5. 文档、资源与贡献
官方提供三类文档入口:
- 概念与教程:docs.langchain.com
- API 参考:reference.langchain.com/python
- 文档问答机器人:chat.langchain.com
社区讨论集中在 LangChain 论坛。资料来源:README.md:41-49。贡献者可参考 Contributing Guide,其中包含 "good first issues" 入口;项目还发布了 行为准则 与免费的 LangChain Academy 课程。资料来源:README.md:51-55。
See Also
- LangChain Core 抽象层
- Deep Agents(基于 LangChain 的高层智能体包)
- LangGraph(可控智能体工作流框架)
- LangChain 经典层(langchain_classic)迁移指南
- 合作伙伴集成包(langchain-openai、langchain-anthropic、langchain-chroma、langchain-exa、langchain-xai 等)
资料来源:README.md:15-31。init_chat_model 接受 provider:model 形式的字符串,从而以统一接口切换不同提供商的聊天模型,避免为每个集成编写不同的客户端代码。
langchain-core 核心抽象:消息、Runnables、Prompts 与输出解析
langchain-core 是 LangChain 生态系统的基座包,承载所有上层集成(langchain、langchain-community、各合作伙伴包)所依赖的基础抽象。libs/core/README.md 明确指出:"LangChain Core contains the base abstractions that power the LangChain ...
继续阅读本节完整说明和来源证据。
继续阅读本节完整说明和来源证据。
概述与分层定位
langchain-core 是 LangChain 生态系统的基座包,承载所有上层集成(langchain、langchain-community、各合作伙伴包)所依赖的基础抽象。libs/core/README.md 明确指出:*"LangChain Core contains the base abstractions that power the LangChain ecosystem. These abstractions are designed to be as modular and simple as possible."* 资料来源:libs/core/README.md:15-18
整个仓库采用清晰的分层结构:
- 根级
README.md引导用户通过init_chat_model快速接入模型,主推Deep Agents与LangGraph。资料来源:README.md:13-39 libs/core定义统一接口(消息、提示词模板、输出解析器、Runnables 等)。libs/langchain_v1提供create_agent等新式工厂函数,强调中间件、结构化输出与 LangGraph 集成。资料来源:libs/langchain_v1/README.md:17-22libs/langchain/langchain_classic保留历史链与已被弃用的AgentExecutor/initialize_agent路径。
消息系统 (Messages)
langchain_core.messages 包提供了跨提供商、跨模态的统一消息模型:
- BaseMessage — 所有消息的抽象基类,定义
content、type、name等通用字段。资料来源:libs/core/langchain_core/messages/base.py - HumanMessage — 用户输入消息。资料来源:libs/core/langchain_core/messages/human.py
- AIMessage — 模型输出消息,可携带
tool_calls、工具调用 ID 与usage_metadata。资料来源:libs/core/langchain_core/messages/ai.py - SystemMessage — 系统级指令。资料来源:libs/core/langchain_core/messages/system.py
- ToolMessage — 工具执行结果回传消息,必须与
tool_call_id配对。资料来源:libs/core/langchain_core/messages/tool.py - ChatMessage — 通用角色消息,可自定义
role。
messages/content.py 进一步把 content 拆为文本块、图像块、引用块等多模态片段,使同一套消息结构可被 Chat Completions、Anthropic、Bedrock 等多协议复用。资料来源:libs/core/langchain_core/messages/content.py
消息与解析的协同流程
flowchart LR S[SystemMessage] --> H[HumanMessage] H --> A[AIMessage] A -- tool_calls --> T1[ToolMessage] T1 --> A A -- "Final Answer" --> F([AgentFinish])
该流程正对应 JSONAgentOutputParser.parse() 的核心逻辑:当 response["action"] == "Final Answer" 时返回 AgentFinish,否则返回 AgentAction 继续循环。资料来源:libs/langchain/langchain_classic/agents/output_parsers/json.py:43-58
输出解析器 (Output Parsers)
langchain_classic 内置多种解析器,分别面向不同提示词协议:
- JSONAgentOutputParser 解析 JSON 块;遇多动作数组时记录
logger.warning("Got multiple action responses: %s", response)并取首个元素,保证单步决策。资料来源:libs/langchain/langchain_classic/agents/output_parsers/json.py:38-58 - ConvoOutputParser 用于对话式 Agent,使用
parse_json_markdown提取action与action_input;解析失败时抛出OutputParserException。资料来源:libs/langchain/langchain_classic/agents/conversational_chat/output_parser.py:21-39 - ReActOutputParser 面向 ReAct 提示词(
Thought/Action/Action Input/Observation),由ReActDocstoreAgent.output_parser默认装配。资料来源:libs/langchain/langchain_classic/agents/react/base.py:33-41
社区高频问题 #1358 "ValueError: Could not parse LLM output" 正是源于上述解析路径在非合规输出下抛出未捕获异常;而 #34818 "Streaming blocked by Structured Output" 则反映旧链路将结构化解析与流式生成耦合造成的瓶颈。
经典 Agent 与 v1 迁移路径
initialize_agent 已显式弃用:*"AGENT_DEPRECATION_WARNING,removal='2.0.0'"*,并提示迁移到 langchain.agents.create_agent,后者提供中间件、结构化输出与 LangGraph 集成。资料来源:libs/langchain/langchain_classic/agents/initialize.py:1-44
迁移后,early_stopping_method="generate" 在迭代上限处的失效问题(issue #16263)可由 LangGraph 的中断与流式中间件机制更细粒度地解决;同时结构化输出也不再阻塞 token 级流式事件。
常见失败模式
- 消息类型遗漏:部分合作伙伴实现(如
langchain-perplexity)的_convert_message_to_dict缺少ToolMessage分支,导致tool_calls字段被丢弃(issue #37910/#37912)。建议在自定义适配器中显式覆盖ToolMessage分支。 - 就地修改输入:
convert_to_openai_messages在部分路径上会原地修改调用方消息(issue #37894),传入前应进行深拷贝。 - 解析异常冒泡:未在调用方捕获
OutputParserException时,错误会直接进入AgentExecutor的迭代上限路径,进而触发early_stopping_method相关告警。
来源:https://github.com/langchain-ai/langchain / 项目说明书
Agent 工厂、中间件与 ToolNode 执行
LangChain 的 Agent 系统经历了从经典(classic)实现到 v1 模块化实现的演进。本页聚焦于 langchainclassic.agents 中提供的 Agent 工厂、Agent 类型与输出解析器,以及向 v1 createagent + ToolNode + Middleware 模型的迁移路径。整体定位是:通过一组可复用的工厂函数(factory)...
继续阅读本节完整说明和来源证据。
概述
LangChain 的 Agent 系统经历了从经典(classic)实现到 v1 模块化实现的演进。本页聚焦于 langchain_classic.agents 中提供的 Agent 工厂、Agent 类型与输出解析器,以及向 v1 create_agent + ToolNode + Middleware 模型的迁移路径。整体定位是:通过一组可复用的工厂函数(factory)把 LLM、Tools、Prompt、OutputParser 装配成一个可执行的 ReAct/Conversational 风格智能体;中间件(Middleware)则是 v1 时代用于在节点前后插入行为的横切关注点抽象,而 ToolNode 由 LangGraph 提供运行时,负责把模型产出的 tool_calls 真实地分发到工具并回填 ToolMessage。
资料来源:libs/langchain/langchain_classic/agents/initialize.py:1-80
经典 Agent 工厂:`initialize_agent`
initialize_agent 是经典工厂的入口,它接受 tools、llm、agent 类型字符串或 agent_path,并返回一个 AgentExecutor。其默认行为:当 agent 与 agent_path 均为空时,落到 AgentType.ZERO_SHOT_REACT_DESCRIPTION,常见异常包括 agent 与 agent_path 同时传入、未知 agent 类型等。
from langchain_classic.agents import initialize_agent, AgentType
from langchain_openai import ChatOpenAI
agent = initialize_agent(
tools=[...],
llm=ChatOpenAI(model="gpt-5.4"),
agent=AgentType.CONVERSATIONAL_REACT_DESCRIPTION,
verbose=True,
)
工厂内部实际上会调用对应子类(ZERO_SHOT_REACT_DESCRIPTION、CONVERSATIONAL_REACT_DESCRIPTION、STRUCTURED_CHAT_ZERO_SHOT_REACT_DESCRIPTION 等)的 _get_default_output_parser 与 prompt,构造出 LLMChain 后再交给 AgentExecutor 驱动循环。该函数自 0.1.0 起被标记 @deprecated,推荐替代为 langchain.agents.create_agent,后者由 LangGraph 运行时支撑并原生支持中间件与结构化输出。
资料来源:libs/langchain/langchain_classic/agents/initialize.py:1-120
Agent 类型与输出解析器
经典实现里,不同 Agent 类型的差异主要由三部分决定:Prompt 模板、OutputParser、对工具输入的校验。下表归纳了仓库中可直接观察到的几类:
| Agent 类型 / 类 | 所在模块 | 输出解析器 | 关键行为 |
|---|---|---|---|
ConversationalAgent | conversational/base.py | ConvoOutputParser | 单输入工具校验 (validate_tools_single_input);保留对话前缀 AI |
ConversationalChatAgent | conversational_chat/base.py | ConvoOutputParser | 基于 ChatPromptTemplate 与 MessagesPlaceholder,工具响应回填模板 TEMPLATE_TOOL_RESPONSE |
JSONAgentOutputParser | output_parsers/json.py | 自解析 JSON | 支持 {"action": "Final Answer", ...} 与 {"action": "...", "action_input": ...};list 响应取首项 |
XMLAgent | xml/base.py | XMLAgentOutputParser | 使用 <tool> / <tool_input> / <observation> / <final_answer> 标签;可选 stop sequence |
| OpenAPI Planner Toolkit | agent_toolkits/openapi/planner_prompt.py | 远端解析 | 通过 DEPRECATED_LOOKUP 动态从 langchain_community 导入 prompt 常量 |
所有解析器最终都把模型输出归约为 AgentAction(继续调用工具)或 AgentFinish(终止并返回结果)两个分支,再交由 AgentExecutor 决定下一步。例如 ConvoOutputParser.parse 解析失败时抛 OutputParserException,驱动 ReAct 循环中的“重试 + 思考”提示。
资料来源:libs/langchain/langchain_classic/agents/conversational/base.py:1-80、libs/langchain/langchain_classic/agents/conversational_chat/base.py:1-80、libs/langchain/langchain_classic/agents/conversational_chat/output_parser.py:1-60、libs/langchain/langchain_classic/agents/output_parsers/json.py:1-60、libs/langchain/langchain_classic/agents/xml/base.py:1-80
Agent 工具包与动态导入
langchain_classic.agents.agent_toolkits 集中暴露各类服务集成(GitHub、Zapier、AINetwork、OpenAPI、VectorStore、ConversationalRetrieval 等)。其 __init__.py 通过 create_importer + as_import_path 与 TYPE_CHECKING 组合,实现:
- 在静态分析期保留类型信息(IDE 跳转与
mypy); - 在运行时按需
__getattr__转发到langchain_community.agent_toolkits.*,避免强依赖把整个社区生态拖入安装包。
flowchart LR
A[langchain_classic.agents] --> B[agent_toolkits]
B --> C[create_importer]
C -->|lazy __getattr__| D[langchain_community.agent_toolkits.*]
D --> E[AINetworkToolkit]
D --> F[AmadeusToolkit]
D --> G[AzureCognitiveServicesToolkit]
D --> H[GitHub / Zapier / VectorStore / OpenAPI]OpenAPI Planner 的 prompt 常量(如 API_CONTROLLER_PROMPT、REQUESTS_GET_TOOL_DESCRIPTION)以 DEPRECATED_LOOKUP 形式转发到 langchain_community.agent_toolkits.openapi.planner_prompt,这是社区工具包从主仓下沉后的统一兼容模式。
资料来源:libs/langchain/langchain_classic/agents/agent_toolkits/__init__.py:1-60、libs/langchain/langchain_classic/agents/agent_toolkits/openapi/planner_prompt.py:1-40
中间件、ToolNode 与迁移路径
经典实现中没有独立的 Middleware 抽象,行为插入主要靠 AgentExecutor 的回调(callback_manager)与 Agent 子类重写。v1 把这些横切关注点拆为可组合的 Middleware(在节点前后执行:before/after model、wrap tool call、动态改写 state/prompt),同时把工具执行抽到 LangGraph 的 ToolNode,它会读取 LLM 消息中的 tool_calls,匹配工具,并发/串行地执行,并把结果回写成 ToolMessage 再进入下一轮。这与社区中的诉求相吻合:例如希望在结构化输出时仍能流式传输(issue #34818)、希望对内存写入做安全校验(issue #37906)、以及更稳健的 backend 集成测试(issue #37905)。
迁移步骤在 initialize.py 的 docstring 中已明确说明:
- 用
create_agent(model, tools, system_prompt=...)替换initialize_agent; - 把
AgentExecutor的max_iterations/early_stopping_method改为 v1 的recursion_limit(issue #16263 反映了旧参数的不一致); - 通过
middleware=[...]注入重试、压缩、审计、提示词清洗等行为,而不是继承Agent子类; - 让 LangGraph 的
ToolNode负责工具分发,错误重试由中间件统一处理。
对于评估与回放场景,langchain_classic.evaluation.agents.trajectory_eval_prompt 提供了对“工具轨迹 + 最终回答”进行 LLM-as-judge 打分的 prompt 模板,可与新中间件产出的轨迹对齐。
资料来源:libs/langchain/langchain_classic/agents/initialize.py:40-120、libs/langchain/langchain_classic/evaluation/agents/trajectory_eval_prompt.py:1-60
常见失败模式与排错
- 解析失败循环:
ValueError: Could not parse LLM output(社区 #1358)多发生在使用非 OpenAI 后端(如HuggingFaceHub)时,模型未严格遵循 ReAct 文本格式。v1 下应通过 Middleware 的wrap_model_call增加格式重试与回退。 - 结构化输出阻塞流式:见 issue #34818,建议在 v1 中将
.with_structured_output()放在工具描述侧而非主响应侧,保留流式通道。 - Pydantic v2 兼容:社区 #6841 已长期推动;当前
langchain_classic在Agent子类上仍使用pydantic.Field的 v1 习惯写法,迁移到langchain.agents.create_agent(基于langchain-corev1)后可彻底切到 v2 语义。
See Also
- LangGraph 运行时与
ToolNode langchain-core中的BaseChatModel与bind_tools- 迁移指南:从
AgentExecutor到create_agent - 评估:Trajectory Evaluator(
langchain_classic.evaluation.agents)
资料来源:libs/langchain/langchain_classic/agents/initialize.py:1-80
聊天模型、Provider 集成与 langchain_classic 兼容层
LangChain 是一个用于构建 Agent 与 LLM 驱动应用的框架,它通过"可互操作的组件 + 第三方集成"的方式把模型、提示、工具、记忆等模块粘合起来 README.md:1-10。在这个体系里有三层密切相关的设施:聊天模型(Chat Model)抽象、Provider 集成包(langchain- partners),以及 langchainclassic 兼容...
继续阅读本节完整说明和来源证据。
概览
LangChain 是一个用于构建 Agent 与 LLM 驱动应用的框架,它通过"可互操作的组件 + 第三方集成"的方式把模型、提示、工具、记忆等模块粘合起来 README.md:1-10。在这个体系里有三层密切相关的设施:聊天模型(Chat Model)抽象、**Provider 集成包(langchain-* partners),以及 langchain_classic 兼容层**。前者定义通用接口,中间层把各家模型/向量库/搜索 API 接入,最后一层为老代码提供过渡路径。
Chat Model 抽象与 `init_chat_model`
聊天模型位于 langchain-core 包中,提供 BaseChatModel 等基础抽象 libs/core/README.md:1-15。langchain 主包在此之上暴露便捷工厂 init_chat_model,让用户用统一字符串指定 provider:
from langchain.chat_models import init_chat_model
model = init_chat_model("openai:gpt-5.4")
result = model.invoke("Hello, world!")
资料来源:README.md 中 Quickstart 段。
模型能力信息由 langchain-model-profiles 包通过 models.dev 同步并暴露在 BaseChatModel.profile 字段上,涵盖上下文窗口、模态、工具调用、结构化输出等 libs/model-profiles/README.md:1-15。
Provider 集成包(langchain-* partners)
绝大多数 provider 实现已从主仓库拆出,迁入 libs/partners/* 下的独立包,以便独立发版、独立管理依赖 libs/README.md:1-15。下表列出了当前仓库中可见的部分集成包:
| 包 | 类型 | 用途 | 来源 |
|---|---|---|---|
langchain-xai | LLM | 接入 xAI 的 API | libs/partners/xai/README.md:1-10 |
langchain-chroma | 向量库 | Chroma 向量数据库 | libs/partners/chroma/README.md:1-10 |
langchain-qdrant | 向量库 | Qdrant 向量检索 | libs/partners/qdrant/README.md:1-10 |
langchain-exa | 搜索 | Exa 网页搜索 API | libs/partners/exa/README.md:1-10 |
每个独立包都遵循相同模式:在 langchain_<provider>/ 命名空间下提供 chat_models.py、可能的 middleware/ 子包,并在 README 中指向 reference.langchain.com 上的 API 参考 libs/partners/xai/README.md:11-25。社区正在持续添加新集成,例如 DeepSeek 近期发布了 langchain-deepseek==1.1.0(社区上下文最新发行说明)。
`langchain_classic` 兼容层
主包 langchain(即 langchain_v1)只保留当前推荐的 Agent 与 chat model 入口;早期 API——包括 ReAct、Conversational、APIChain、传统 AgentExecutor——被整体迁移到 langchain_classic,并打上 deprecated(removal="2.0.0") 标签 libs/langchain/langchain_classic/agents/react/base.py:1-25。
flowchart LR
A[用户应用] --> B[langchain_v1]
B -->|init_chat_model| C[langchain-core]
B -->|tool/MCP| D[partners/*]
A -. 旧代码 .-> E[langchain_classic]
E --> F[ReAct / AgentExecutor / APIChain]
F --> Clangchain_classic 仍然按"Agent / Chain / AgentToolkit"组织模块,例如:
agents.react.base.ReActDocstoreAgent实现 ReAct 论文中的推理-行动循环 libs/langchain/langchain_classic/agents/react/base.py:30-45。agents.conversational_chat.output_parser.ConvoOutputParser解析对话式 agent 的 JSON 输出 libs/langchain/langchain_classic/agents/conversational_chat/output_parser.py:1-20。agents.agent_toolkits收录 GitHub、VectorStore、ConversationalRetrieval 等 toolkit 的延迟导入 libs/langchain/langchain_classic/agents/agent_toolkits/__init__.py:1-25。chains.api.base.APIChain通过limit_to_domains进行 URL 域白名单校验 libs/langchain/langchain_classic/chains/api/base.py:1-25。
libs/langchain/README.md 明确建议:新代码应使用主包 langchain,langchain_classic 仅用于迁移 libs/langchain/README.md:1-15。
常见问题与社区反馈
社区关注点与本页主题直接相关的几类问题包括:
- 流式与结构化输出冲突:当把
streaming=True与with_structured_output()同时启用时,部分 provider 会先缓冲再返回,导致流式失效——参见 Issue #34818。 - 消息转换边界问题:例如
ChatPerplexity._convert_message_to_dict缺少ToolMessage分支,会回退到抛错(Issues #37910 / #37912);convert_to_openai_messages会就地修改调用方传入的消息对象(Issue #37894)。 - Pydantic 版本兼容:Pydantic v2 升级曾长期影响
langchain.agents导入(Issue #6841);近期又有BaseLLM在 Pydantic main 上构造失败的回归(Issue #37835)。 - Agent 输出解析失败:当使用非 OpenAI 后端时,常触发
ValueError: Could not parse LLM output:,社区帖 #1358 已沉淀多种修复模式。 langchain_classic的弃用路径:AgentExecutor的early_stopping_method="generate"在达到迭代上限时不被支持(Issue #16263),建议迁移到 LangGraph。
资料来源:README.md:1-30、libs/langchain_v1/README.md:1-20、libs/langchain/README.md:1-15。
See Also
- langchain-core 抽象与 LangChain 生态
- Deep Agents 高阶 Agent 包
- LangGraph 流程编排
- LangSmith 调试与部署
- 贡献指南
资料来源:README.md 中 Quickstart 段。
失败模式与踩坑日记
保留 Doramagic 在发现、验证和编译中沉淀的项目专属风险,不把社区讨论只当作装饰信息。
可能增加新用户试用和生产接入成本。
可能增加新用户试用和生产接入成本。
可能增加新用户试用和生产接入成本。
可能增加新用户试用和生产接入成本。
Pitfall Log / 踩坑日志
项目:langchain-ai/langchain
摘要:发现 33 个潜在踩坑项,其中 8 个为 high/blocking;最高优先级:安装坑 - 来源证据:Feature: Memory write validation hooks to prevent prompt injection persistence (OWASP ASI-06)。
1. 安装坑 · 来源证据:Feature: Memory write validation hooks to prevent prompt injection persistence (OWASP ASI-06)
- 严重度:high
- 证据强度:source_linked
- 发现:GitHub 社区证据显示该项目存在一个安装相关的待验证问题:Feature: Memory write validation hooks to prevent prompt injection persistence (OWASP ASI-06)
- 对用户的影响:可能增加新用户试用和生产接入成本。
- 证据:community_evidence:github | https://github.com/langchain-ai/langchain/issues/37906 | 来源讨论提到 python 相关条件,需在安装/试用前复核。
2. 安装坑 · 来源证据:Unsupported early_stopping_method="generate" in AgentExecutor after reaching iteration limit
- 严重度:high
- 证据强度:source_linked
- 发现:GitHub 社区证据显示该项目存在一个安装相关的待验证问题:Unsupported early_stopping_method="generate" in AgentExecutor after reaching iteration limit
- 对用户的影响:可能增加新用户试用和生产接入成本。
- 证据:community_evidence:github | https://github.com/langchain-ai/langchain/issues/16263 | 来源讨论提到 python 相关条件,需在安装/试用前复核。
3. 安装坑 · 来源证据:convert_to_openai_messages mutates the caller's input message in place
- 严重度:high
- 证据强度:source_linked
- 发现:GitHub 社区证据显示该项目存在一个安装相关的待验证问题:convert_to_openai_messages mutates the caller's input message in place
- 对用户的影响:可能增加新用户试用和生产接入成本。
- 证据:community_evidence:github | https://github.com/langchain-ai/langchain/issues/37894 | 来源讨论提到 python 相关条件,需在安装/试用前复核。
4. 配置坑 · 来源证据:Importing langchain.agents breaks BaseLLM class construction on Pydantic main
- 严重度:high
- 证据强度:source_linked
- 发现:GitHub 社区证据显示该项目存在一个配置相关的待验证问题:Importing langchain.agents breaks BaseLLM class construction on Pydantic main
- 对用户的影响:可能增加新用户试用和生产接入成本。
- 证据:community_evidence:github | https://github.com/langchain-ai/langchain/issues/37835 | 来源讨论提到 python 相关条件,需在安装/试用前复核。
5. 安全/权限坑 · 失败模式:security_permissions: Add `BackendIntegrationTests` for Deep Agents `BackendProtocol` implementations
- 严重度:high
- 证据强度:source_linked
- 发现:Developers should check this security_permissions risk before relying on the project: Add
BackendIntegrationTestsfor Deep AgentsBackendProtocolimplementations - 对用户的影响:Developers may expose sensitive permissions or credentials: Add
BackendIntegrationTestsfor Deep AgentsBackendProtocolimplementations - 证据:failure_mode_cluster:github_issue | https://github.com/langchain-ai/langchain/issues/37905 | Add
BackendIntegrationTestsfor Deep AgentsBackendProtocolimplementations
6. 安全/权限坑 · 失败模式:security_permissions: Feature: Memory write validation hooks to prevent prompt injection persistence (OWASP ASI-06)
- 严重度:high
- 证据强度:source_linked
- 发现:Developers should check this security_permissions risk before relying on the project: Feature: Memory write validation hooks to prevent prompt injection persistence (OWASP ASI-06)
- 对用户的影响:Developers may expose sensitive permissions or credentials: Feature: Memory write validation hooks to prevent prompt injection persistence (OWASP ASI-06)
- 证据:failure_mode_cluster:github_issue | https://github.com/langchain-ai/langchain/issues/37906 | Feature: Memory write validation hooks to prevent prompt injection persistence (OWASP ASI-06)
7. 安全/权限坑 · 来源证据:Feature Request: Payment primitive integration — x402 payment layer for paid API consumption
- 严重度:high
- 证据强度:source_linked
- 发现:GitHub 社区证据显示该项目存在一个安全/权限相关的待验证问题:Feature Request: Payment primitive integration — x402 payment layer for paid API consumption
- 对用户的影响:可能影响授权、密钥配置或安全边界。
- 证据:community_evidence:github | https://github.com/langchain-ai/langchain/issues/36306 | 来源讨论提到 python 相关条件,需在安装/试用前复核。
8. 安全/权限坑 · 来源证据:Streaming blocked by Structured Output
- 严重度:high
- 证据强度:source_linked
- 发现:GitHub 社区证据显示该项目存在一个安全/权限相关的待验证问题:Streaming blocked by Structured Output
- 对用户的影响:可能阻塞安装或首次运行。
- 证据:community_evidence:github | https://github.com/langchain-ai/langchain/issues/34818 | 来源讨论提到 python 相关条件,需在安装/试用前复核。
9. 安装坑 · 失败模式:installation: Unsupported early_stopping_method="generate" in AgentExecutor after reaching iteration limit
- 严重度:medium
- 证据强度:source_linked
- 发现:Developers should check this installation risk before relying on the project: Unsupported early_stopping_method="generate" in AgentExecutor after reaching iteration limit
- 对用户的影响:Developers may fail before the first successful local run: Unsupported early_stopping_method="generate" in AgentExecutor after reaching iteration limit
- 证据:failure_mode_cluster:github_issue | https://github.com/langchain-ai/langchain/issues/16263 | Unsupported early_stopping_method="generate" in AgentExecutor after reaching iteration limit
10. 安装坑 · 失败模式:installation: convert_to_openai_messages mutates the caller's input message in place
- 严重度:medium
- 证据强度:source_linked
- 发现:Developers should check this installation risk before relying on the project: convert_to_openai_messages mutates the caller's input message in place
- 对用户的影响:Developers may fail before the first successful local run: convert_to_openai_messages mutates the caller's input message in place
- 证据:failure_mode_cluster:github_issue | https://github.com/langchain-ai/langchain/issues/37894 | convert_to_openai_messages mutates the caller's input message in place
11. 安装坑 · 失败模式:installation: langchain-deepseek==1.1.0
- 严重度:medium
- 证据强度:source_linked
- 发现:Developers should check this installation risk before relying on the project: langchain-deepseek==1.1.0
- 对用户的影响:Upgrade or migration may change expected behavior: langchain-deepseek==1.1.0
- 证据:failure_mode_cluster:github_release | https://github.com/langchain-ai/langchain/releases/tag/langchain-deepseek%3D%3D1.1.0 | langchain-deepseek==1.1.0
12. 安装坑 · 失败模式:installation: perplexity: _convert_message_to_dict drops AIMessage.tool_calls and raises on ToolMessage
- 严重度:medium
- 证据强度:source_linked
- 发现:Developers should check this installation risk before relying on the project: perplexity: _convert_message_to_dict drops AIMessage.tool_calls and raises on ToolMessage
- 对用户的影响:Developers may fail before the first successful local run: perplexity: _convert_message_to_dict drops AIMessage.tool_calls and raises on ToolMessage
- 证据:failure_mode_cluster:github_issue | https://github.com/langchain-ai/langchain/issues/37912 | perplexity: _convert_message_to_dict drops AIMessage.tool_calls and raises on ToolMessage
13. 安装坑 · 来源证据:Add Agent Magnet as a memory integration for LangChain agents
- 严重度:medium
- 证据强度:source_linked
- 发现:GitHub 社区证据显示该项目存在一个安装相关的待验证问题:Add Agent Magnet as a memory integration for LangChain agents
- 对用户的影响:可能增加新用户试用和生产接入成本。
- 证据:community_evidence:github | https://github.com/langchain-ai/langchain/issues/37907 | 来源类型 github_issue 暴露的待验证使用条件。
14. 安装坑 · 来源证据:perplexity: _convert_message_to_dict drops AIMessage.tool_calls and raises on ToolMessage
- 严重度:medium
- 证据强度:source_linked
- 发现:GitHub 社区证据显示该项目存在一个安装相关的待验证问题:perplexity: _convert_message_to_dict drops AIMessage.tool_calls and raises on ToolMessage
- 对用户的影响:可能增加新用户试用和生产接入成本。
- 证据:community_evidence:github | https://github.com/langchain-ai/langchain/issues/37912 | 来源讨论提到 python 相关条件,需在安装/试用前复核。
15. 配置坑 · 失败模式:configuration: Feature Request: Payment primitive integration — x402 payment layer for paid API consumption
- 严重度:medium
- 证据强度:source_linked
- 发现:Developers should check this configuration risk before relying on the project: Feature Request: Payment primitive integration — x402 payment layer for paid API consumption
- 对用户的影响:Developers may misconfigure credentials, environment, or host setup: Feature Request: Payment primitive integration — x402 payment layer for paid API consumption
- 证据:failure_mode_cluster:github_issue | https://github.com/langchain-ai/langchain/issues/36306 | Feature Request: Payment primitive integration — x402 payment layer for paid API consumption
16. 配置坑 · 失败模式:configuration: Importing langchain.agents breaks BaseLLM class construction on Pydantic main
- 严重度:medium
- 证据强度:source_linked
- 发现:Developers should check this configuration risk before relying on the project: Importing langchain.agents breaks BaseLLM class construction on Pydantic main
- 对用户的影响:Developers may misconfigure credentials, environment, or host setup: Importing langchain.agents breaks BaseLLM class construction on Pydantic main
- 证据:failure_mode_cluster:github_issue | https://github.com/langchain-ai/langchain/issues/37835 | Importing langchain.agents breaks BaseLLM class construction on Pydantic main
17. 配置坑 · 失败模式:configuration: Streaming blocked by Structured Output
- 严重度:medium
- 证据强度:source_linked
- 发现:Developers should check this configuration risk before relying on the project: Streaming blocked by Structured Output
- 对用户的影响:Developers may misconfigure credentials, environment, or host setup: Streaming blocked by Structured Output
- 证据:failure_mode_cluster:github_issue | https://github.com/langchain-ai/langchain/issues/34818 | Streaming blocked by Structured Output
18. 配置坑 · 失败模式:configuration: [Integration Proposal] UnisonX402Retriever — TSV x402 retriever with A2A affiliate + churn te...
- 严重度:medium
- 证据强度:source_linked
- 发现:Developers should check this configuration risk before relying on the project: [Integration Proposal] UnisonX402Retriever — TSV x402 retriever with A2A affiliate + churn telemetry
- 对用户的影响:Developers may misconfigure credentials, environment, or host setup: [Integration Proposal] UnisonX402Retriever — TSV x402 retriever with A2A affiliate + churn telemetry
- 证据:failure_mode_cluster:github_issue | https://github.com/langchain-ai/langchain/issues/37900 | [Integration Proposal] UnisonX402Retriever — TSV x402 retriever with A2A affiliate + churn telemetry
19. 能力坑 · 能力判断依赖假设
- 严重度:medium
- 证据强度:source_linked
- 发现:README/documentation is current enough for a first validation pass.
- 对用户的影响:假设不成立时,用户拿不到承诺的能力。
- 证据:capability.assumptions | github_repo:552661142 | https://github.com/langchain-ai/langchain | README/documentation is current enough for a first validation pass.
20. 运行坑 · 来源证据:perplexity: _convert_message_to_dict drops AIMessage.tool_calls and raises on ToolMessage
- 严重度:medium
- 证据强度:source_linked
- 发现:GitHub 社区证据显示该项目存在一个运行相关的待验证问题:perplexity: _convert_message_to_dict drops AIMessage.tool_calls and raises on ToolMessage
- 对用户的影响:可能增加新用户试用和生产接入成本。
- 证据:community_evidence:github | https://github.com/langchain-ai/langchain/issues/37910 | 来源讨论提到 python 相关条件,需在安装/试用前复核。
21. 维护坑 · 维护活跃度未知
- 严重度:medium
- 证据强度:source_linked
- 发现:未记录 last_activity_observed。
- 对用户的影响:新项目、停更项目和活跃项目会被混在一起,推荐信任度下降。
- 证据:evidence.maintainer_signals | github_repo:552661142 | https://github.com/langchain-ai/langchain | last_activity_observed missing
- 严重度:medium
- 证据强度:source_linked
- 发现:no_demo
- 证据:downstream_validation.risk_items | github_repo:552661142 | https://github.com/langchain-ai/langchain | no_demo; severity=medium
23. 安全/权限坑 · 存在评分风险
- 严重度:medium
- 证据强度:source_linked
- 发现:no_demo
- 对用户的影响:风险会影响是否适合普通用户安装。
- 证据:risks.scoring_risks | github_repo:552661142 | https://github.com/langchain-ai/langchain | no_demo; severity=medium
24. 安全/权限坑 · 来源证据:Add `BackendIntegrationTests` for Deep Agents `BackendProtocol` implementations
- 严重度:medium
- 证据强度:source_linked
- 发现:GitHub 社区证据显示该项目存在一个安全/权限相关的待验证问题:Add
BackendIntegrationTestsfor Deep AgentsBackendProtocolimplementations - 对用户的影响:可能影响授权、密钥配置或安全边界。
- 证据:community_evidence:github | https://github.com/langchain-ai/langchain/issues/37905 | 来源讨论提到 python 相关条件,需在安装/试用前复核。
25. 安全/权限坑 · 来源证据:[Integration Proposal] UnisonX402Retriever — TSV x402 retriever with A2A affiliate + churn telemetry
- 严重度:medium
- 证据强度:source_linked
- 发现:GitHub 社区证据显示该项目存在一个安全/权限相关的待验证问题:[Integration Proposal] UnisonX402Retriever — TSV x402 retriever with A2A affiliate + churn telemetry
- 对用户的影响:可能影响授权、密钥配置或安全边界。
- 证据:community_evidence:github | https://github.com/langchain-ai/langchain/issues/37900 | 来源讨论提到 python 相关条件,需在安装/试用前复核。
26. 能力坑 · 失败模式:capability: perplexity: _convert_message_to_dict drops AIMessage.tool_calls and raises on ToolMessage
- 严重度:low
- 证据强度:source_linked
- 发现:Developers should check this capability risk before relying on the project: perplexity: _convert_message_to_dict drops AIMessage.tool_calls and raises on ToolMessage
- 对用户的影响:Developers may hit a documented source-backed failure mode: perplexity: _convert_message_to_dict drops AIMessage.tool_calls and raises on ToolMessage
- 证据:failure_mode_cluster:github_issue | https://github.com/langchain-ai/langchain/issues/37910 | perplexity: _convert_message_to_dict drops AIMessage.tool_calls and raises on ToolMessage
27. 运行坑 · 失败模式:performance: Add Agent Magnet as a memory integration for LangChain agents
- 严重度:low
- 证据强度:source_linked
- 发现:Developers should check this performance risk before relying on the project: Add Agent Magnet as a memory integration for LangChain agents
- 对用户的影响:Developers may hit a documented source-backed failure mode: Add Agent Magnet as a memory integration for LangChain agents
- 证据:failure_mode_cluster:github_issue | https://github.com/langchain-ai/langchain/issues/37908 | Add Agent Magnet as a memory integration for LangChain agents, failure_mode_cluster:github_issue | https://github.com/langchain-ai/langchain/issues/37907 | Add Agent Magnet as a memory integration for LangChain agents
28. 维护坑 · issue/PR 响应质量未知
- 严重度:low
- 证据强度:source_linked
- 发现:issue_or_pr_quality=unknown。
- 对用户的影响:用户无法判断遇到问题后是否有人维护。
- 证据:evidence.maintainer_signals | github_repo:552661142 | https://github.com/langchain-ai/langchain | issue_or_pr_quality=unknown
29. 维护坑 · 发布节奏不明确
- 严重度:low
- 证据强度:source_linked
- 发现:release_recency=unknown。
- 对用户的影响:安装命令和文档可能落后于代码,用户踩坑概率升高。
- 证据:evidence.maintainer_signals | github_repo:552661142 | https://github.com/langchain-ai/langchain | release_recency=unknown
30. 维护坑 · 失败模式:maintenance: langchain-anthropic==1.4.4
- 严重度:low
- 证据强度:source_linked
- 发现:Developers should check this maintenance risk before relying on the project: langchain-anthropic==1.4.4
- 对用户的影响:Upgrade or migration may change expected behavior: langchain-anthropic==1.4.4
- 证据:failure_mode_cluster:github_release | https://github.com/langchain-ai/langchain/releases/tag/langchain-anthropic%3D%3D1.4.4 | langchain-anthropic==1.4.4
31. 维护坑 · 失败模式:maintenance: langchain-perplexity==1.3.1
- 严重度:low
- 证据强度:source_linked
- 发现:Developers should check this maintenance risk before relying on the project: langchain-perplexity==1.3.1
- 对用户的影响:Upgrade or migration may change expected behavior: langchain-perplexity==1.3.1
- 证据:failure_mode_cluster:github_release | https://github.com/langchain-ai/langchain/releases/tag/langchain-perplexity%3D%3D1.3.1 | langchain-perplexity==1.3.1
32. 维护坑 · 失败模式:maintenance: langchain==1.3.3
- 严重度:low
- 证据强度:source_linked
- 发现:Developers should check this maintenance risk before relying on the project: langchain==1.3.3
- 对用户的影响:Upgrade or migration may change expected behavior: langchain==1.3.3
- 证据:failure_mode_cluster:github_release | https://github.com/langchain-ai/langchain/releases/tag/langchain%3D%3D1.3.3 | langchain==1.3.3
33. 维护坑 · 失败模式:maintenance: langchain==1.3.4
- 严重度:low
- 证据强度:source_linked
- 发现:Developers should check this maintenance risk before relying on the project: langchain==1.3.4
- 对用户的影响:Upgrade or migration may change expected behavior: langchain==1.3.4
- 证据:failure_mode_cluster:github_release | https://github.com/langchain-ai/langchain/releases/tag/langchain%3D%3D1.3.4 | langchain==1.3.4
来源:Doramagic 发现、验证与编译记录