> ## Documentation Index
> Fetch the complete documentation index at: https://nvd-54.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# LangChain 概述

> LangChain 是一个开源框架，提供预构建的智能体架构和任意模型或工具的集成——让你能构建随生态系统发展而不断适应的智能体

用不到 10 行代码构建完全自定义的、由大语言模型（LLM）驱动的智能体和应用程序，集成 [OpenAI、Anthropic、Google 等](/oss/javascript/integrations/providers/overview)。
LangChain 提供预构建的智能体架构和模型集成，帮助你快速入门并将 LLM 无缝集成到你的智能体和应用程序中。

<Tip>
  **LangChain vs. LangGraph vs. Deep Agents**

  从 [Deep Agents](/oss/javascript/deepagents/overview/) 开始，获得"开箱即用"的智能体，具备自动上下文压缩、虚拟文件系统和子智能体生成等功能。Deep Agents 构建在 LangChain [智能体](/oss/javascript/langchain/agents/)之上，你也可以直接使用 LangChain。

  使用 [LangGraph](/oss/javascript/langgraph/overview)——我们的底层编排框架——满足结合确定性和智能体工作流的高级需求。

  使用 [LangSmith](/langsmith/home) 来追踪、调试和评估用上述任何框架构建的智能体。按照[追踪快速入门](/langsmith/trace-with-langchain)开始设置。
</Tip>

## <Icon icon="wand" /> 创建智能体

<CodeGroup>
  ```ts OpenAI theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
  // 首先安装：npm install langchain zod @langchain/openai
  import { 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?" }],
    })
  );
  ```

  ```ts Google Gemini theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
  // 首先安装：npm install langchain zod @langchain/google-genai
  import { 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: "google-genai:gemini-2.5-flash-lite",
    tools: [getWeather],
  });

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

  ```ts Claude (Anthropic) theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
  // 首先安装：npm install langchain zod @langchain/anthropic
  import { 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: "claude-sonnet-4-6",
    tools: [getWeather],
  });

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

  ```ts OpenRouter theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
  // 首先安装：npm install langchain zod @langchain/openrouter
  import { 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: "openrouter:anthropic/claude-sonnet-4-6",
    tools: [getWeather],
  });

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

  ```ts Fireworks theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
  // 首先安装：npm install langchain zod @langchain/community
  import { 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: "fireworks:accounts/fireworks/models/qwen3p5-397b-a17b",
    tools: [getWeather],
  });

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

  ```ts Baseten theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
  // 首先安装：npm install langchain zod @langchain/community
  import { 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: "baseten:zai-org/GLM-5",
    tools: [getWeather],
  });

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

  ```ts Ollama theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
  // 首先安装：npm install langchain zod @langchain/ollama
  import { 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: "ollama:devstral-2",
    tools: [getWeather],
  });

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

  ```ts Azure theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
  // 首先安装：npm install langchain zod @langchain/openai
  import { 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: "azure_openai:gpt-5.4",
    tools: [getWeather],
  });

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

  ```ts AWS Bedrock theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
  // 首先安装：npm install langchain zod @langchain/aws
  import { 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: "bedrock:gpt-5.4",
    tools: [getWeather],
  });

  console.log(
    await agent.invoke({
      messages: [{ role: "user", content: "What's the weather in San Francisco?" }],
    })
  );
  ```
</CodeGroup>

请参阅[安装说明](/oss/javascript/langchain/install)和[快速入门指南](/oss/javascript/langchain/quickstart)，开始使用 LangChain 构建你自己的智能体和应用程序。

<Tip>
  使用 [LangSmith](/langsmith/home) 追踪请求、调试智能体行为并评估输出。设置 `LANGSMITH_TRACING=true` 和你的 API 密钥即可开始。
</Tip>

## <Icon icon="star" size={20} /> 核心优势

<Columns cols={2}>
  <Card title="标准化模型接口" icon="refresh" href="/oss/javascript/langchain/models" arrow cta="了解更多">
    不同的提供商有各自独特的模型交互 API，包括响应格式。LangChain 标准化了你与模型的交互方式，让你能无缝切换提供商并避免锁定。
  </Card>

  <Card title="易用且高度灵活的智能体" icon="wand" href="/oss/javascript/langchain/agents" arrow cta="了解更多">
    LangChain 的智能体抽象设计为易于上手，让你用不到 10 行代码就能构建一个简单的智能体。同时它也提供足够的灵活性，让你能进行所有你想要的上下文工程。
  </Card>

  <Card title="构建在 LangGraph 之上" icon="https://mintcdn.com/nvd-54/mlZOzzR6zl-4_HH7/images/brand/langgraph-icon.png?fit=max&auto=format&n=mlZOzzR6zl-4_HH7&q=85&s=e2b4d1b969dd3a127e9091f71784b8c7" href="/oss/javascript/langgraph/overview" arrow cta="了解更多" width="195" height="195" data-path="images/brand/langgraph-icon.png">
    LangChain 的智能体构建在 LangGraph 之上。这使我们能够利用 LangGraph 的持久化执行、人机协作支持、持久性等功能。
  </Card>

  <Card title="使用 LangSmith 调试" icon="https://mintcdn.com/nvd-54/mlZOzzR6zl-4_HH7/images/brand/observability-icon-dark.png?fit=max&auto=format&n=mlZOzzR6zl-4_HH7&q=85&s=0fdee54d28f455ccd083349da651c3fa" href="/langsmith/observability" arrow cta="了解更多" width="200" height="200" data-path="images/brand/observability-icon-dark.png">
    通过可视化工具深入了解复杂的智能体行为，追踪执行路径、捕获状态转换，并提供详细的运行时指标。
  </Card>
</Columns>

***

<div className="source-links">
  <Callout icon="terminal-2">
    [将这些文档连接](/use-these-docs)到 Claude、VSCode 等，通过 MCP 获取实时答案。
  </Callout>

  <Callout icon="edit">
    [在 GitHub 上编辑此页面](https://github.com/langchain-ai/docs/edit/main/src/oss/langchain/overview.mdx)或[提交问题](https://github.com/langchain-ai/docs/issues/new/choose)。
  </Callout>
</div>
