Skip to content

LangChain 是开始构建由大语言模型(LLM)驱动的智能体(agent)和应用程序的最简单方式。只需不到 10 行代码,您就可以连接到 OpenAI、Anthropic、Google 以及更多模型提供商。LangChain 提供了预构建的智能体架构和模型集成,帮助您快速入门,并将 LLM 无缝地融入您的智能体和应用程序中。

如果您希望快速构建智能体和自主应用程序,我们推荐您使用 LangChain。当您有更高级的需求,需要结合确定性工作流和智能体工作流、进行重度定制以及严格控制延迟时,请使用我们的底层智能体编排框架和运行时 LangGraph

LangChain 的智能体构建在 LangGraph 之上,以提供持久化执行、流式处理、人在回路(human-in-the-loop)、持久化存储等功能。对于基本的 LangChain 智能体使用,您无需了解 LangGraph。

创建一个智能体

python
# pip install -qU langchain "langchain[anthropic]"
from langchain.agents import create_agent

def get_weather(city: str) -> str:
    """Get weather for a given city."""
    return f"It's always sunny in {city}!"

agent = create_agent(
    model="claude-sonnet-4-5-20250929",
    tools=[get_weather],
    system_prompt="You are a helpful assistant",
)

# Run the agent
agent.invoke(
    {"messages": [{"role": "user", "content": "what is the weather in sf"}]}
)

请参阅安装说明快速入门指南,开始使用 LangChain 构建您自己的智能体和应用程序。

核心优势

LangChain 中文文档