# LangChain

**LangChain** 是一个用于在大语言模型（LLM）之上构建应用的开源框架，始于 2022 年 10 月，最初是用于串联 LLM 操作的通用工具，此后发展为一整套智能体工程产品家族：LangChain 智能体框架、[LangGraph](https://www.edgepedia.org/zh/langgraph) 编排运行时、[LangSmith](https://www.edgepedia.org/zh/langsmith) 可观测性平台，以及 Deep Agents 智能体 harness。<sup>[1](https://bytepointer.com/llm-orchestration-frameworks-compared-langchain-vs-llamaindex-vs-raw-api-calls/)</sup><sup> • </sup><sup>[2](https://docs.langchain.com/oss/python/langgraph/overview)</sup> 它由哈里森·蔡斯（Harrison Chase）和安库什·戈拉（Ankush Gola）共同创立，其公司在 2025 年 10 月以 12.5 亿美元估值完成了 1.25 亿美元的 B 轮融资。<sup>[3](https://fortune.com/2025/10/20/exclusive-early-ai-darling-langchain-is-now-a-unicorn-with-a-fresh-125-million-in-funding/)</sup><sup> • </sup><sup>[4](https://www.langchain.com/blog/series-b)</sup>

| 关键事实 | 详情 |
|---|---|
| 起源 | 2022 年 10 月作为串联 LLM 操作的框架起步；由哈里森·蔡斯和安库什·戈拉共同创立<sup>[1](https://bytepointer.com/llm-orchestration-frameworks-compared-langchain-vs-llamaindex-vs-raw-api-calls/)</sup><sup> • </sup><sup>[3](https://fortune.com/2025/10/20/exclusive-early-ai-darling-langchain-is-now-a-unicorn-with-a-fresh-125-million-in-funding/)</sup> |
| 产品家族 | LangChain（智能体框架）、LangGraph（编排运行时）、LangSmith（追踪、评估、部署）、Deep Agents（智能体 harness）<sup>[2](https://docs.langchain.com/oss/python/langgraph/overview)</sup> |
| 采用情况 | langchain 与 langgraph 合计月下载量 9000 万次；据报告《财富》500 强中 35% 为其用户；在优步（Uber）、摩根大通（J.P. Morgan）、贝莱德（BlackRock）和思科（Cisco）有生产环境使用<sup>[4](https://www.langchain.com/blog/series-b)</sup><sup> • </sup><sup>[5](https://www.langchain.com/blog/langchain-langgraph-1dot0)</sup> |
| 融资 | 1000 万美元种子轮（Benchmark，2023 年 4 月）、2500 万美元 A 轮，估值 2 亿美元（红杉，2024 年）、1.25 亿美元 B 轮，估值 12.5 亿美元（IVP 领投，2025 年）<sup>[3](https://fortune.com/2025/10/20/exclusive-early-ai-darling-langchain-is-now-a-unicorn-with-a-fresh-125-million-in-funding/)</sup><sup> • </sup><sup>[4](https://www.langchain.com/blog/series-b)</sup> |
| 稳定性里程碑 | LangChain 1.0 与 LangGraph 1.0 于 2025-10-22 发布，为首个稳定大版本，并承诺在 2.0 之前不做破坏性变更<sup>[5](https://www.langchain.com/blog/langchain-langgraph-1dot0)</sup><sup> • </sup><sup>[6](https://research.modelcitizendeveloper.com/survey/1-200/)</sup> |
| 实测开销 | LangChain 每步框架开销约 10 毫秒，LangGraph 约 14 毫秒，而直接 API 调用约为零；每次查询约 2.4K token 的提示词开销<sup>[1](https://bytepointer.com/llm-orchestration-frameworks-compared-langchain-vs-llamaindex-vs-raw-api-calls/)</sup> |
| 已记录的安全问题 | LangDrained 协同披露（2026 年 3 月 27 日），涵盖序列化注入（CVE-2025-68664，CVSS 9.3）与检查点层缺陷；2025 年 6 月一个可能暴露 API 密钥的 LangSmith 问题<sup>[7](https://labs.cloudsecurityalliance.org/research/csa-research-note-langchain-langgraph-vulnerabilities-202603/)</sup><sup> • </sup><sup>[8](https://xenoss.io/blog/langchain-langgraph-llamaindex-llm-frameworks)</sup> |

## 它解决什么问题

直接调用 LLM API 可以提供文本输入、文本输出的交互。真实应用需要模型查阅外部数据、调用工具、记住先前步骤、重试失败操作，并遵守模型自身无法强制执行的约束。LangChain 提供模块化原语——模型、提示词、检索器和工具——用 LangChain 表达式语言（LCEL）将它们连接起来，使这些部件在代码中组合，而非临时拼接。<sup>[9](https://byaiteam.com/blog/2025/11/15/ai-orchestration-frameworks-langchain-vs-llamaindex-vs-semantic-kernel/)</sup> 其生态十分广泛：据一项对比，拥有 100 多个数据加载器、50 多个向量存储和 20 多个 LLM 提供商。<sup>[10](https://getathenic.com/blog/langchain-vs-llamaindex-vs-haystack-rag-frameworks)</sup>

一项在固定模型、工具和提示词条件下对智能体框架进行的基准研究，呈现了价值问题的两面。在一个多议题任务上，LangChain 和 LangGraph 的正确率中位数为 0.50，是所测六个框架中最低的，而 [Claude Agent SDK](https://www.edgepedia.org/zh/claude-agent-sdk) 为 0.88；在多智能体编排场景中，六个框架全部收敛到 0.77，表明针对场景的编排代码并未带来正确率优势。但该研究仍发现，框架在处理模型自身无法施加的控制方面仍有其用途，包括请求速率限制、身份验证、合规日志、确定性路由，以及与 CI/CD 和可观测性工具的连接。<sup>[11](https://dl.acm.org/doi/pdf/10.1145/3786335.3813233)</sup> 另一项对八个基础模型的评估在推理类工作负载上发现了相反的取舍：对于检索密集的 RAG，[LlamaIndex](https://www.edgepedia.org/zh/llamaindex) 的延迟低 3% 到 15%，峰值内存低约 60%，但对于推理密集的数学任务，LangChain 在所有被测模型上都取得了更高的准确率，且延迟特征更可预测。<sup>[12](https://dl.acm.org/doi/abs/10.1145/3777884.3797017)</sup>

## 架构与核心组件

**模块化原语与 LCEL。** LangChain 的架构由模型、提示词、检索器和工具组成，用 LCEL 连接；LCEL 于 2024 年引入，以管道操作符语法取代了大部分旧的基于类的链式构建方式。<sup>[9](https://byaiteam.com/blog/2025/11/15/ai-orchestration-frameworks-langchain-vs-llamaindex-vs-semantic-kernel/)</sup><sup> • </sup><sup>[13](https://enterprisedna.co/resources/blog/practitioner-langchain-2026/)</sup> LangGraph 宣称的能力包括短期与长期记忆，以及持久化执行和人在回路的状态检查。<sup>[14](https://github.com/langchain-ai/langgraph)</sup>

**智能体。** 在 LangChain 1.0 中，create_agent 是构建智能体的标准方式：一个在循环中调用工具直到产出最终答案的模型。它比早先的 langgraph.prebuilt.create_react_agent 提供更简单的接口，同时允许通过中间件进行更大程度的定制，底层运行在 LangGraph 上。<sup>[15](https://docs.langchain.com/oss/python/releases/langchain-v1)</sup><sup> • </sup><sup>[5](https://www.langchain.com/blog/langchain-langgraph-1dot0)</sup> 旧版 AgentExecutor 已弃用，维护至 2026 年 12 月，新的智能体工作被引导至 create_agent() 或 LangGraph 的 StateGraph。<sup>[6](https://research.modelcitizendeveloper.com/survey/1-200/)</sup>

**1.0 版本重组。** 2025 年 10 月发布的 LangChain 1.0 要求 Python 3.10+，并将旧版链、MultiQueryRetriever 等检索器、索引 API 以及 langchain-community 的导出内容移入单独的 langchain-classic 包，以保持核心精简。<sup>[5](https://www.langchain.com/blog/langchain-langgraph-1dot0)</sup><sup> • </sup><sup>[15](https://docs.langchain.com/oss/python/releases/langchain-v1)</sup> langchain-core 也升级至 1.0，在各提供商之间统一了内容块标准，支持推理轨迹、引用和工具调用。<sup>[5](https://www.langchain.com/blog/langchain-langgraph-1dot0)</sup>

## LangGraph 与智能体工作流

LangGraph 创建于 2023 年 8 月，是一个低层编排框架和运行时，用于构建、管理和部署长时间运行的有状态智能体。它让开发者可以在同一张图中混合确定性的手写步骤与 LLM 驱动的智能体步骤，不对提示词或架构做抽象，核心关注持久化执行、流式传输和人在回路控制。<sup>[14](https://github.com/langchain-ai/langgraph)</sup><sup> • </sup><sup>[2](https://docs.langchain.com/oss/python/langgraph/overview)</sup> LangGraph 的核心设计是持久化执行，智能体运行会自动设置检查点，可在进程死亡、人工等待或提供商临时故障后恢复。<sup>[6](https://research.modelcitizendeveloper.com/survey/1-200/)</sup>

1.0 生态中的分工是：LangChain 是组件库和模型/工具抽象，而 LangGraph 是执行已定义图的运行时；开发者可以从 LangChain 的高层 API 起步，再下沉到 LangGraph 以获得更多控制。<sup>[6](https://research.modelcitizendeveloper.com/survey/1-200/)</sup><sup> • </sup><sup>[5](https://www.langchain.com/blog/langchain-langgraph-1dot0)</sup> LangGraph 面向长时间运行的业务流程自动化、人在回路工作流，以及对延迟和成本敏感的应用。<sup>[5](https://www.langchain.com/blog/langchain-langgraph-1dot0)</sup> 在调试方面，LangGraph Studio 提供时间旅行调试、可视化图检查和状态/线程管理；Studio v2（2025 年 5 月）增加了 LangSmith 集成和就地配置编辑，而大多数高级调试能力存在于 LangGraph Server 而非开源库中。<sup>[8](https://xenoss.io/blog/langchain-langgraph-llamaindex-llm-frameworks)</sup> Deep Agents 位于 LangGraph 之上，是一个智能体 harness，具备规划、子智能体、文件系统工具和上下文管理能力。<sup>[2](https://docs.langchain.com/oss/python/langgraph/overview)</sup>

## LangSmith 与可观测性

LangSmith 是公司的商业平台，用于追踪、调试、评估数据集，以及随时间监控性能和成本；它可与 LangChain 应用配合使用，也可通过框架无关的集成接入。<sup>[9](https://byaiteam.com/blog/2025/11/15/ai-orchestration-frameworks-langchain-vs-llamaindex-vs-semantic-kernel/)</sup> 截至 B 轮融资公告时，月度追踪量增至上年同期的 12 倍。<sup>[4](https://www.langchain.com/blog/series-b)</sup> 较新的组件包括 LangSmith Engine，它能检测 LangGraph 智能体追踪中的问题并提出可作为拉取请求提交的修复方案，以及 LangSmith Fleet，一个无代码智能体构建器。<sup>[2](https://docs.langchain.com/oss/python/langgraph/overview)</sup> 一位从业者的说法是，团队版定价约为每席位每月 39 美元。<sup>[13](https://enterprisedna.co/resources/blog/practitioner-langchain-2026/)</sup>

## 采用情况与用例

在 1.0 发布时，生态报告月下载量达 9000 万次，并在优步、摩根大通、[贝莱德](https://www.edgepedia.org/zh/blackrock)和思科有生产环境使用；仅 LangGraph 就被认为已被优步、领英（LinkedIn）和 Klarna 采用，其仓库将 Klarna、Replit 和 Elastic 列为用户。<sup>[5](https://www.langchain.com/blog/langchain-langgraph-1dot0)</sup><sup> • </sup><sup>[2](https://docs.langchain.com/oss/python/langgraph/overview)</sup><sup> • </sup><sup>[14](https://github.com/langchain-ai/langgraph)</sup> 根据项目自身文档数据，仅 langchain 包截至 2026 年 1 月 19 日就录得 1.04 亿次下载。<sup>[16](https://github.com/langchain-ai/docs/blob/fb79c64ed1fbaa27cd808cbdd2e0fe3d51bd440c/packages.yml)</sup> 典型应用是对文档语料库的检索增强生成（RAG）、聊天机器人，以及长时间运行的业务流程自动化；在 1 万到 50 万份文档上运行文档问答的团队报告，使用 pgvector 或 Pinecone 时检索延迟为 200 到 800 毫秒，配置得当时 LangChain 自身的编排开销通常每次调用低于 50 毫秒。<sup>[5](https://www.langchain.com/blog/langchain-langgraph-1dot0)</sup><sup> • </sup><sup>[13](https://enterprisedna.co/resources/blog/practitioner-langchain-2026/)</sup>

## 与其他框架的比较

**LlamaIndex** 于 2022 年 11 月以 GPT Index 之名推出，专注于数据连接器和检索；据一项对比，它有 4.4 万 GitHub 星标，通过 LlamaHub 提供 300 多个连接器，而 LangChain 有 11.9 万星标和 500 多个集成。其编排原语是事件驱动的 Workflows，与 LangGraph 的状态机形态不同，且在版本 0.14.23 时仍处于 1.0 之前，而 LangChain 已达到 1.4.3。<sup>[1](https://bytepointer.com/llm-orchestration-frameworks-compared-langchain-vs-llamaindex-vs-raw-api-calls/)</sup><sup> • </sup><sup>[6](https://research.modelcitizendeveloper.com/survey/1-200/)</sup> 在一项 RAG 基准中，LangChain 录得摄取 145 秒、p95 查询延迟 2.3 秒、NDCG@10 为 0.78、内存 1.2 GB，而 LlamaIndex 为 132 秒、1.8 秒、0.81 和 950 MB，Haystack 为 158 秒、2.1 秒、0.82 和 1.1 GB。<sup>[10](https://getathenic.com/blog/langchain-vs-llamaindex-vs-haystack-rag-frameworks)</sup>

**Haystack** 占据同一市场，而随着模型厂商吸收框架功能，竞争格局已经改变：《财富》报道称，OpenAI、Anthropic 和谷歌现在提供的内置能力曾是 LangChain 的差异化优势。<sup>[3](https://fortune.com/2025/10/20/exclusive-early-ai-darling-langchain-is-now-a-unicorn-with-a-fresh-125-million-in-funding/)</sup> 与直接 API 调用相比，实测成本是具体的：LangChain 每步约 10 毫秒框架开销，LangGraph 约 14 毫秒，每次查询约 2.4K token 的提示词开销，而 LlamaIndex 约 1.6K、直接调用为零；一个有记录的案例中，基本 RAG 管线的成本为原生实现的 2.7 倍；生产环境错误堆栈跟踪通常跨越 15 到 40 层框架内部代码，而直接调用为 2 到 5 层。<sup>[1](https://bytepointer.com/llm-orchestration-frameworks-compared-langchain-vs-llamaindex-vs-raw-api-calls/)</sup>

## 反响、批评与安全

**赞誉与批评。** 评论者称赞 LangChain 拥有该类别中最大、最活跃的开源社区，并与几乎所有流行的 LLM、向量存储和第三方 API 都有连接。<sup>[9](https://byaiteam.com/blog/2025/11/15/ai-orchestration-frameworks-langchain-vs-llamaindex-vs-semantic-kernel/)</sup> 有记录的批评包括：对简单用例存在实实在在的抽象税；文档频繁变动，仍会向新用户呈现已弃用的 1.0 之前 AgentExecutor 模式；图调试困难，促使团队转向商业产品 LangSmith。<sup>[6](https://research.modelcitizendeveloper.com/survey/1-200/)</sup> v0.1 到 v0.3 期间，在 2025 年 10 月 v1.0 稳定性承诺之前，用户曾被迫进行多次破坏性迁移，且每 2 到 3 个月就发布新版本，附带已记录的破坏性变更和功能移除。<sup>[1](https://bytepointer.com/llm-orchestration-frameworks-compared-langchain-vs-llamaindex-vs-raw-api-calls/)</sup><sup> • </sup><sup>[8](https://xenoss.io/blog/langchain-langgraph-llamaindex-llm-frameworks)</sup> 对于简单 RAG，一些团队已转向原生 OpenAI 或 Anthropic SDK 加上 200 到 400 行 Python 的自定义编排层。<sup>[13](https://enterprisedna.co/resources/blog/practitioner-langchain-2026/)</sup>

**使用工具的智能体的安全性。** 由于智能体执行工具并反序列化状态，框架代码成为攻击面的一部分。Cyera Research 于 2026 年 3 月 27 日进行的一次协同披露名为 LangDrained，在 LangChain 和 LangGraph 中发现了多个高危和严重漏洞。<sup>[7](https://labs.cloudsecurityalliance.org/research/csa-research-note-langchain-langgraph-vulnerabilities-202603/)</sup> 最严重的 CVE-2025-68664（CVSS 9.3，被 Cyata 昵称为 LangGrinch）是 langchain-core 的 dumps()/dumpd() 中的序列化注入，未能清理包含保留键 "lc" 的用户控制字典，使提示注入可升级为任意代码执行和从环境变量中提取机密；0.3.81 补丁增加了 allowed_objects 允许列表，将 secrets_from_env 默认设为 False，并阻止从反序列化路径进行 Jinja2 模板渲染。<sup>[7](https://labs.cloudsecurityalliance.org/research/csa-research-note-langchain-langgraph-vulnerabilities-202603/)</sup> LangGraph 的检查点持久化层有两个可独立利用的缺陷：CVE-2025-64439（通过反序列化的检查点数据实现远程代码执行）和 CVE-2025-67644（SQLite 检查点后端中的 SQL 注入，CVSS 7.3）。<sup>[7](https://labs.cloudsecurityalliance.org/research/csa-research-note-langchain-langgraph-vulnerabilities-202603/)</sup> 更早的 CVE-2024-8309（2024 年 10 月披露）影响 langchain-community 0.2.5 中的 GraphCypherQAChain，该链执行 LLM 生成的 Cypher 查询而不做验证；严重性评级存在分歧，NVD 给出 CVSS 9.8，而厂商评为 4.9 中等，GitHub Advisory 评为 2.1 低危，修复方式为显式的 allow_dangerous_requests=True 选择加入，被描述为一种设计上的承认：此类链默认不应具备生产安全性。<sup>[7](https://labs.cloudsecurityalliance.org/research/csa-research-note-langchain-langgraph-vulnerabilities-202603/)</sup> 2025 年 6 月，一个此后已修复的 LangSmith 问题可能通过恶意智能体暴露 API 密钥。<sup>[8](https://xenoss.io/blog/langchain-langgraph-llamaindex-llm-frameworks)</sup> 在防御方面，一项对智能体 AI 框架的调查发现，LangGraph 与 AutoGen、Agno 和 OpenAI SDK 一道，提供了最强的原生护栏支持，不过大多数框架仍需要外部逻辑或手动设置才能实现稳健的护栏。<sup>[17](https://arxiv.org/pdf/2508.10146v1.pdf)</sup>

LangChain 式框架究竟是有助于还是有损于 LLM 工程，在测量文献中确实存在争议：固定模型的智能体基准发现 LangChain 和 LangGraph 在一个场景中得分在六个框架中最低，在另一个场景中编排代码未带来正确率优势，<sup>[11](https://dl.acm.org/doi/pdf/10.1145/3786335.3813233)</sup> 而八模型评估发现框架选择显著影响性能，任务特定的取舍有利于 LangChain 的推理准确率和 LlamaIndex 的检索工作负载。<sup>[12](https://dl.acm.org/doi/abs/10.1145/3777884.3797017)</sup> 两个结果可以同时成立：框架的价值取决于工作负载，而无论哪种情况开销都是可测量的。

## References

1. [LLM Orchestration Frameworks Compared: LangChain vs. LlamaIndex vs. Raw API Calls, BytePointer](https://bytepointer.com/llm-orchestration-frameworks-compared-langchain-vs-llamaindex-vs-raw-api-calls/)
2. [LangGraph overview, official docs](https://docs.langchain.com/oss/python/langgraph/overview)
3. [Early AI darling LangChain is now a unicorn with a fresh $125 million in funding, Fortune](https://fortune.com/2025/10/20/exclusive-early-ai-darling-langchain-is-now-a-unicorn-with-a-fresh-125-million-in-funding/)
4. [LangChain raises $125M to build the platform for agent engineering, LangChain blog](https://www.langchain.com/blog/series-b)
5. [LangChain and LangGraph Agent Frameworks Reach v1.0 Milestones, LangChain blog](https://www.langchain.com/blog/langchain-langgraph-1dot0)
6. [1.200 LLM Orchestration Frameworks | Survey of Software, Model Citizen Developer](https://research.modelcitizendeveloper.com/survey/1-200/)
7. [LangChain and LangGraph: Critical Vulnerabilities in AI Orchestration, Cloud Security Alliance](https://labs.cloudsecurityalliance.org/research/csa-research-note-langchain-langgraph-vulnerabilities-202603/)
8. [LangChain vs LangGraph vs LlamaIndex: Best LLM framework, Xenoss](https://xenoss.io/blog/langchain-langgraph-llamaindex-llm-frameworks)
9. [AI Orchestration Frameworks: LangChain vs LlamaIndex vs Semantic Kernel, ByAI Team](https://byaiteam.com/blog/2025/11/15/ai-orchestration-frameworks-langchain-vs-llamaindex-vs-semantic-kernel/)
10. [LangChain vs LlamaIndex vs Haystack: RAG Framework Comparison, Athenic](https://getathenic.com/blog/langchain-vs-llamaindex-vs-haystack-rag-frameworks)
11. [Arena: Benchmarking AI Agent Frameworks Under Fixed-Model Conditions, ACM](https://dl.acm.org/doi/pdf/10.1145/3786335.3813233)
12. [An Evaluation Study of Generative AI Systems: Framework-Aware Performance Under Real-World Constraints, ACM](https://dl.acm.org/doi/abs/10.1145/3777884.3797017)
13. [LangChain: What Engineers Actually Found, Enterprise DNA](https://enterprisedna.co/resources/blog/practitioner-langchain-2026/)
14. [langchain-ai/langgraph, GitHub repository](https://github.com/langchain-ai/langgraph)
15. [LangChain v1.0 release notes, official docs](https://docs.langchain.com/oss/python/releases/langchain-v1)
16. [packages.yml, langchain-ai/docs, GitHub](https://github.com/langchain-ai/docs/blob/fb79c64ed1fbaa27cd808cbdd2e0fe3d51bd440c/packages.yml)
17. [Agentic AI Frameworks: Architectures, Protocols, and Design Challenges, arXiv](https://arxiv.org/pdf/2508.10146v1.pdf)

---
*Initially written Sep 17, 2026 · Reviewed: Oct 15, 2026 · Edited: Oct 11, 2026; Oct 15, 2026 · Last review: Oct 15, 2026*

Topic: 技术与人造世界 › 计算技术与数字系统 › 现代人工智能：基础模型、生成式人工智能与人工智能产业 › AI companies, people, and products › AI products and assistants › AI agents and developer tools

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/langchain

English original: https://www.edgepedia.org/langchain
