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

安装

pip install -U langchain

创建代理

# pip install -qU "langchain[anthropic]" to call the model

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"}]}
)

核心优势


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