LangChain vs. LangGraph vs. Deep Agents从 Deep Agents 开始,获得”开箱即用”的智能体,具备自动上下文压缩、虚拟文件系统和子智能体生成等功能。Deep Agents 构建在 LangChain 智能体之上,你也可以直接使用 LangChain。使用 LangGraph——我们的底层编排框架——满足结合确定性和智能体工作流的高级需求。使用 LangSmith 来追踪、调试和评估用上述任何框架构建的智能体。按照追踪快速入门开始设置。
// 首先安装:npm install langchain zod @langchain/openaiimport { createAgent, tool } from "langchain";import * as z from "zod";const getWeather = tool( (input) => `It's always sunny in ${input.city}!`, { name: "get_weather", description: "Get the weather for a given city", schema: z.object({ city: z.string().describe("The city to get the weather for"), }), });const agent = createAgent({ model: "gpt-5.4", tools: [getWeather],});console.log( await agent.invoke({ messages: [{ role: "user", content: "What's the weather in San Francisco?" }], }));