随着 AI Agent 的爆发式发展,LangChain 在 1.0 版本完成了一次重要的架构重构。
LangChain 0.x版本的工作流编排写法已经被官方彻底废弃,取而代之的是基于LangGraph封装的Agent抽象,实现真正的Agent。
如果说 LangChain 0.x 是 LLM 写死的工作流 ,那么 LangChain 1.0 更像一个 灵活的Agent 应用框架。
LangChain 被设计出来主要基于两个核心目标:
1 标准化模型接口
不同 LLM Provider API 差异巨大,例如:
- OpenAI
- Anthropic
- 本地模型
LangChain提供统一接口,使开发者可以随时替换模型。
2 让模型可以编排复杂流程
LLM 不应该只用于文本生成,而应该:
- 调用工具
- 访问数据
- 规划任务
- 控制工作流
LangChain 的目标是让 LLM 成为应用的 orchestrator(调度器) 。
不同时间节点的架构演进
LangChain 的发展大致经历了四个阶段:
| 时间 | 架构 |
|---|---|
| 2022 | LLM + Chains |
| 2023 | Agents |
| 2024 | LangGraph |
| 2025 | LangChain 1.0 Agent Runtime |
官方时间线:
- 2022:LangChain 发布
- 2023:Agents 引入
- 2024:LangGraph 发布
- 2025:LangChain 1.0 发布
从LangChain1.0之后,老版本的固定工作流形式被官方彻底抛弃,不再维护。
新版LangChain以LangGraph为运行底座进行了新的抽象和封装。
新版 LangChain 架构结构
LangChain 1.0 的架构分为三层:

核心思想:
LangChain = Agent API
LangGraph = Agent Runtime
新版 LangChain Agent 的工作原理
LangChain Agent 的核心逻辑是:
scss
Observe → Reason → Act → Repeat
这来源于著名的 ReAct Agent 模式。
Agent 工作流程:

这一流程的核心是:
LLM 决定下一步行动。
LangChain 0.x 的问题
旧版 LangChain 存在几个问题:
1 Chains 过于固定
Chain 是固定流程,例如:
Retriever → Prompt → LLM
难以处理复杂逻辑。
2 Agent 不够稳定
早期 Agent的JSON parsing和prompt engineering容易失败。
3 控制流程能力弱
例如retry、human-in-loop、streaming很难实现。
为了解决这些问题,LangChain 团队推出:
LangGraph
它是一个 Agent 运行时 / 工作流引擎。
LangGraph 架构:

核心能力:
- 状态管理
- 工作流控制
- Streaming
- Memory
- Human-in-loop
LangChain 1.0 版本的核心变化
LangChain 1.0 主要做了三件事:
1. Agent 成为唯一的抽象
arduino
// 旧版:
Chains
Agents
Tools
Memory
// 新版:
Agent
所有逻辑统一到 Agent。
2. Chains 被官方彻底废弃
旧版:
LLMChain
ConversationChain
RetrievalQAChain
新版统一使用 Agent。
3 引入标准消息格式
c
// 旧版:
content: string
// 新版:
contentBlocks
新版支持:
- text
- reasoning
- citations
- tool calls
LangChain 1.0 Agent 架构
LangChain Agent 运行时:

| 组件 | 作用 |
|---|---|
| Agent | 决策逻辑 |
| Middleware | 控制 Agent 行为 |
| Tools | 执行外部操作 |
| Models | 推理能力 |
| Memory | 状态管理 |
代码示例对比
老版本示例
typescript
// 旧版 LangChain 0.x:使用 initializeAgentExecutorWithOptions + DynamicTool
import { ChatOpenAI } from "@langchain/openai";
import { DynamicTool } from "@langchain/core/tools";
import { initializeAgentExecutorWithOptions } from "langchain/agents";
const model = new ChatOpenAI({
modelName: "gpt-4.1", // 或 gpt-4o 等
temperature: 0,
});
// 老版工具通常是"字符串输入 + 手动解析"
const weatherTool = new DynamicTool({
name: "getWeather",
description: "Get weather information. Input should be a JSON string like {"city":"Tokyo"}.",
async func(input: string) {
let city = input;
try {
const parsed = JSON.parse(input);
city = parsed.city ?? input;
} catch {
// 如果不是 JSON,就当成城市名本身
}
return `Weather in ${city} is sunny`;
},
});
const tools = [weatherTool];
const executor = await initializeAgentExecutorWithOptions(tools, model, {
agentType: "chat-zero-shot-react-description",
verbose: true,
});
// 调用 Agent(旧版是 input 一个字符串)
const result = await executor.call({
input: "What's the weather in Tokyo?",
});
console.log(result.output);
新版本示例
javascript
// 创建Agent
import { createAgent, tool } from "langchain";
import { initChatModel } from "langchain";
const model = await initChatModel("gpt-4.1");
const weatherTool = tool({
name: "getWeather",
description: "Get weather information",
schema: {
city: "string"
},
async call({ city }) {
return `Weather in ${city} is sunny`;
}
});
const agent = createAgent({
model,
tools: [weatherTool],
systemPrompt: "You are a helpful assistant"
});
// 调用Agent
const result = await agent.invoke({
messages: [
{
role: "user",
content: "What's the weather in Tokyo?"
}
]
});
console.log(result);
总结
LangChain 1.0 的核心升级:
| 能力 | 旧版 | 新版 |
|---|---|---|
| 架构 | Chains | Agent |
| 工作流 | 隐式 | LangGraph |
| 消息格式 | string | contentBlocks |
| Hook | pre/post hook | middleware |
| Tool 调用 | JSON | structured |
因为ReAct Agent的范式已经成为业内的"默认事实",所以建议使用0.x的老版工作流编排形式的langchain的同学可以迁移成新版1.0之后的版本,以获得更好的开发体验和跟上Agent的主流发展趋势。