LangChain

LangChain is an MIT-licensed framework for building AI agents with model integrations, tools and customizable agent loops

来源语言 · EN

先看实际效果

作者示例

Author diagram: model and agent harness

Author illustration of an agent harness: memory, skills, tools, context, subagents and system prompt surround the model. This is an architecture diagram from the documentation, rather than an application screenshot or tested output.

LangChain author diagram showing model surrounded by memory, skills, tools, context, subagents and system prompt
查看完整图片
许可

SVG decoded at declared1200×760 viewport; platform font rendering, no crop/upscale. Pixel equality is against that complete rendered RGBA, not a pre-existing publisher bitmap. Lossless WebP matches the full rendered RGBA.

MIT License

Copyright (c) 2025 LangChain

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
作者示例

Source example: first model invocation

Complete Python block from the official README initializes the stated openai:gpt-5.5 model and invokes a greeting. Requires LangChain, the matching provider integration, credentials and model access; the exact source model string is retained, with no generated answer or independent availability test.

示例输入

from langchain.chat_models import init_chat_model

model = init_chat_model("openai:gpt-5.5")
result = model.invoke("Hello, world!")
许可

Complete original source file/block(s) unchanged. Outer README fence omitted for copying; grouped complete files keep their own language fences. Editorial title/prerequisites added. Nothing executed.

MIT License

Copyright (c) LangChain, Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
作者示例

Source example: thread ID and typed context

Complete author Python file combines a fresh thread ID, typed user context and InMemorySaver. It uses the source Claude model and requires its provider integration/credentials. No weather tool is provided, so its weather question is not a live-weather integration. Helper assertions are unexecuted.

示例输入

# :snippet-start: agent-invocation-thread-and-context-py
from dataclasses import dataclass

from langchain.agents import create_agent
from langchain_core.utils.uuid import uuid7
from langgraph.checkpoint.memory import InMemorySaver


@dataclass
class Context:
    user_id: str


agent = create_agent(
    model="claude-sonnet-4-6",
    tools=[],
    context_schema=Context,
    checkpointer=InMemorySaver(),
)

result = agent.invoke(
    {"messages": [{"role": "user", "content": "What's the weather in San Francisco?"}]},
    config={"configurable": {"thread_id": str(uuid7())}},
    context=Context(user_id="user-123"),
)
# :snippet-end:

# :remove-start:
if __name__ == "__main__":
    last = result["messages"][-1]
    text = last.content_blocks[0]["text"] if last.content_blocks else str(last.content)
    assert text.strip(), "expected non-empty assistant reply"
    print("✓ thread_id and context invoke together without error")
# :remove-end:
许可

Complete original source file/block(s) unchanged. Outer README fence omitted for copying; grouped complete files keep their own language fences. Editorial title/prerequisites added. Nothing executed.

MIT License

Copyright (c) 2025 LangChain

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
作者示例

Source example: read a profile from memory

Complete author Python file stores fictional John Smith data and exposes a context-selected lookup tool to an agent. Requires LangChain/LangGraph and the stated model provider credentials. InMemoryStore is a demo; use durable storage for production. No real profile lookup or model result was run.

示例输入

# :snippet-start: long-term-memory-read-tool-inmemory-py
from dataclasses import dataclass

from langchain.agents import create_agent
from langchain.tools import ToolRuntime, tool
from langchain_core.runnables import Runnable
from langgraph.store.memory import InMemoryStore


@dataclass
class Context:
    user_id: str


# InMemoryStore saves data to an in-memory dictionary. Use a DB-backed store in production.
store = InMemoryStore()

# Write sample data to the store using the put method
store.put(
    (
        "users",
    ),  # Namespace to group related data together (users namespace for user data)
    "user_123",  # Key within the namespace (user ID as key)
    {
        "name": "John Smith",
        "language": "English",
    },  # Data to store for the given user
)


@tool
def get_user_info(runtime: ToolRuntime[Context]) -> str:
    """Look up user info."""
    # Access the store - same as that provided to `create_agent`
    assert runtime.store is not None
    user_id = runtime.context.user_id
    # Retrieve data from store - returns StoreValue object with value and metadata
    user_info = runtime.store.get(("users",), user_id)
    return str(user_info.value) if user_info else "Unknown user"


agent: Runnable = create_agent(
    model="claude-sonnet-4-6",
    tools=[get_user_info],
    # Pass store to agent - enables agent to access store when running tools
    store=store,
    context_schema=Context,
)

# Run the agent
agent.invoke(
    {"messages": [{"role": "user", "content": "look up user information"}]},
    context=Context(user_id="user_123"),
)
# :snippet-end:

# :remove-start:
if __name__ == "__main__":
    # Verify the store has the data
    result = store.get(("users",), "user_123")
    assert result is not None
    assert result.value["name"] == "John Smith"

    print("✓ Read tool with InMemoryStore works correctly")
# :remove-end:
许可

Complete original source file/block(s) unchanged. Outer README fence omitted for copying; grouped complete files keep their own language fences. Editorial title/prerequisites added. Nothing executed.

MIT License

Copyright (c) 2025 LangChain

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
主要功能

LangChain 能做什么

  1. 01Build agent loops with create_agent on LangGraph
  2. 02Connect model providers, tools and databases through integrations
  3. 03Customize context and human review through middleware
  4. 04Maintain workflow state with LangGraph checkpointing and persistence
来源语言 · EN
差异特点

它有什么不同

Developers configure the agent loop, tools, application data and checkpoint storage for their use case. The framework is free to use under MIT; model access, hosting and optional LangSmith tracing, evaluation or deployment services need their own setup and may incur separate charges.

来源语言 · EN
适合人群

谁值得考虑

  • Developers building tool-calling agents around their own application data
  • Engineering teams customizing model, context and human-review workflows
来源语言 · EN
选择之前

需要核对的事项

  • 用一个真实任务试用,并对照自己的要求检查结果。
  • 核实服务会保存、共享或用于训练哪些数据。
  • 在官网确认当前价格、使用限额和取消条款。
官网核验日期

官网链接核查于 2026年10月25日;功能声明尚未经过独立测试。

按任务相关推荐

产品价格使用方式相关用途
LangChain免费API自动化工作流
LangGraph未核实API自动化工作流
LangBot未核实Web, API自动化工作流
nanobot未核实Web, API, Windows, macOS, Linux生成可用于生产的代码 · 自动化工作流
Flowise未核实API自动化工作流