跳到主要内容
LangChain 是开始构建完全自定义的代理和应用程序的简便方法,这些代理和应用程序由 LLM 提供支持。只需不到 10 行代码,您就可以连接到 OpenAI、Anthropic、Google 和 更多。LangChain 提供了一个预构建的代理架构和模型集成,可帮助您快速入门并无缝地将 LLM 融入您的代理和应用程序。
LangChain 与 LangGraph 与深度代理如果您希望构建代理,我们建议您从 深度代理 开始,它“开箱即用”,具有现代功能,例如自动压缩长对话、虚拟文件系统以及用于管理和隔离上下文的子代理生成。深度代理是 LangChain 代理 的实现。如果您不需要这些功能或希望为您的代理和自主应用程序自定义它们,请从 LangChain 开始。当您具有更高级的需求,需要结合确定性和代理工作流程以及大量自定义时,请使用 LangGraph,我们的低级代理编排框架和运行时。
LangChain 代理 构建在 LangGraph 之上,以提供持久执行、流式传输、人工参与循环、持久性等。您不需要了解 LangGraph 即可进行基本的 LangChain 代理使用。 我们建议您使用 LangChain,如果您想快速构建代理和自主应用程序。

创建代理

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?" }],
  })
);
请参阅 安装说明快速入门指南,开始使用 LangChain 构建您自己的代理和应用程序。

核心优势


将这些文档连接到 Claude、VSCode 等,以获得实时答案。
© . This site is unofficial and not affiliated with LangChain, Inc.