LangGraph——被 Replit、Uber、LinkedIn、GitLab 等公司使用——是一个用于构建可控代理的低级编排框架。虽然 LangChain 提供了集成和可组合的组件来简化 LLM 应用程序开发,但 LangGraph 库支持代理编排,提供可定制的架构、长期记忆和人工参与,以可靠地处理复杂任务。
npm install @langchain/langgraph @langchain/core
要了解如何使用 LangGraph 的更多信息,请查看 文档。下面我们展示一个创建 ReAct 代理的简单示例。
// npm install @langchain-anthropic
import { createReactAgent } from "@langchain/langgraph/prebuilt";
import { ChatAnthropic } from "@langchain/anthropic";
import { tool } from "@langchain/core/tools";
import { z } from "zod";
const search = tool(
async ({ query }) => {
if (
query.toLowerCase().includes("sf") ||
query.toLowerCase().includes("san francisco")
) {
return "It's 60 degrees and foggy.";
}
return "It's 90 degrees and sunny.";
},
{
name: "search",
description: "Call to surf the web.",
schema: z.object({
query: z.string().describe("The query to use in your search."),
}),
}
);
const model = new ChatAnthropic({
model: "claude-3-7-sonnet-latest",
});
const agent = createReactAgent({
llm: model,
tools: [search],
});
const result = await agent.invoke({
messages: [
{
role: "user",
content: "what is the weather in sf",
},
],
});
使用 create-agent-chat-app
CLI 快速构建一个全栈 LangGraph 应用程序
npx create-agent-chat-app@latest
该 CLI 设置了一个聊天界面并帮助您配置应用程序,包括
npm
、yarn
或 pnpm
)LangGraph 专为希望构建强大、适应性强的 AI 代理的开发人员而设计。开发人员选择 LangGraph 的原因有
LangGraph 在生产环境中备受信赖,为以下公司提供代理支持:
LangGraph 既可独立使用,也可与任何 LangChain 产品无缝集成,为开发人员提供一套完整的工具来构建代理。为了改进您的 LLM 应用程序开发,请将 LangGraph 与以下产品结合使用:
虽然 LangGraph 是我们的开源代理编排框架,但需要可扩展代理部署的企业可以从 LangGraph Platform 中受益。
LangGraph Platform 可以帮助工程团队实现以下目标:
LangGraph 的灵感来源于 Pregel 和 Apache Beam。公共接口从 NetworkX 中汲取灵感。LangGraph 由 LangChain 的创建者 LangChain Inc 构建,但可以在不使用 LangChain 的情况下独立使用。