跳到主要内容
LangChain v1.0 现已推出!有关更改的完整列表以及如何升级代码的说明,请参阅发布说明迁移指南如果您遇到任何问题或有反馈,请提出问题,以便我们改进。要查看 v0.x 文档,请转到存档内容
LangChain 是开始构建由大型语言模型(LLM)驱动的智能体和应用程序的最简单方法。只需不到 10 行代码,您就可以连接到 OpenAI、Anthropic、Google 和更多平台。LangChain 提供预构建的智能体架构和模型集成,帮助您快速入门并将 LLM 无缝集成到您的智能体和应用程序中。 如果您想快速构建智能体和自主应用程序,我们建议您使用 LangChain。当您有更高级的需求时,需要结合确定性和智能体工作流、大量定制和精心控制的延迟,请使用我们的低级智能体编排框架和运行时LangGraph LangChain 智能体基于 LangGraph 构建,以提供持久执行、流式传输、人机交互、持久化等功能。基本 LangChain 智能体使用不需要了解 LangGraph。

安装

npm install langchain @langchain/core

创建智能体

import * as z from "zod";
// npm install @langchain/anthropic to call the model
import { createAgent, tool } from "langchain";

const getWeather = tool(
  ({ city }) => `It's always sunny in ${city}!`,
  {
    name: "get_weather",
    description: "Get the weather for a given city",
    schema: z.object({
      city: z.string(),
    }),
  },
);

const agent = createAgent({
  model: "claude-sonnet-4-5-20250929",
  tools: [getWeather],
});

console.log(
  await agent.invoke({
    messages: [{ role: "user", content: "What's the weather in Tokyo?" }],
  })
);

核心优势


以编程方式连接这些文档到 Claude、VSCode 等,通过 MCP 获取实时答案。
© . This site is unofficial and not affiliated with LangChain, Inc.