先看实际效果
Author diagram: chained calls with a gate
Original documentation illustration of calls linked by a gate. It explains a workflow pattern; it is not a product interface, an executed trace or a measured quality result.

许可
Complete source PNG converted losslessly to WebP without crop or resize.
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.
Author diagram: parallel calls and aggregation
Original documentation illustration of parallel calls joined by an aggregator. The image shows structure; no independent timing or reliability comparison is implied.

许可
Complete source PNG converted losslessly to WebP without crop or resize.
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: pause and resume an approval
Complete Python source routes an in-memory approval to proceed or cancel, then resumes the same thread. The Transfer $500 string is dummy action text: no payment is implemented. Requires compatible LangGraph; production needs durable persistence. Source assertions/prints are not site-run results.
示例输入
# :snippet-start: langgraph-interrupts-approval-py
from typing import Literal, Optional, TypedDict
from langgraph.checkpoint.memory import InMemorySaver
from langgraph.graph import END, START, StateGraph
from langgraph.types import Command, interrupt
class ApprovalState(TypedDict):
action_details: str
status: Optional[Literal["pending", "approved", "rejected"]]
def approval_node(state: ApprovalState) -> Command[Literal["proceed", "cancel"]]:
# Expose details so the caller can render them in a UI
decision = interrupt(
{
"question": "Approve this action?",
"details": state["action_details"],
}
)
# Route to the appropriate node after resume
return Command(goto="proceed" if decision else "cancel")
def proceed_node(state: ApprovalState):
return {"status": "approved"}
def cancel_node(state: ApprovalState):
return {"status": "rejected"}
builder = StateGraph(ApprovalState)
builder.add_node("approval", approval_node)
builder.add_node("proceed", proceed_node)
builder.add_node("cancel", cancel_node)
builder.add_edge(START, "approval")
builder.add_edge("proceed", END)
builder.add_edge("cancel", END)
# Use a more durable checkpointer in production
checkpointer = InMemorySaver()
graph = builder.compile(checkpointer=checkpointer)
config = {"configurable": {"thread_id": "approval-123"}}
initial = graph.stream_events(
{"action_details": "Transfer $500", "status": "pending"},
config=config,
version="v3",
)
_ = initial.output # drive the stream to completion
print(initial.interrupts) # -> (Interrupt(value={'question': ..., 'details': ...}),)
# Resume with the decision; True routes to proceed, False to cancel
resumed = graph.stream_events(Command(resume=True), config=config, version="v3")
print(resumed.output["status"])
# :snippet-end:
# :remove-start:
if __name__ == "__main__":
assert resumed.output["status"] == "approved"
print("✓ langgraph-interrupts-approval")
# :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: tool state and run context
Complete Python source passes a user ID in graph state and an organization ID in per-run context to a ToolNode. Uses an authored tool-call message and sample identifiers, without a model or real user lookup. Requires LangChain/LangGraph; the included assertions are unexecuted.
示例输入
# :snippet-start: workflows-agents-tool-runtime-state-context-py
from dataclasses import dataclass
from langchain.messages import AIMessage
from langchain.tools import ToolRuntime, tool
from langgraph.graph import MessagesState, START, StateGraph
from langgraph.prebuilt import ToolNode
class State(MessagesState):
user_id: str
@dataclass
class Context:
organization_id: str
@tool
def get_user_info(runtime: ToolRuntime[Context, State]) -> str:
"""Look up user information."""
# Read the current graph state passed to the ToolNode.
user_id = runtime.state["user_id"]
# Read explicit per-run values that are not part of graph state.
organization_id = runtime.context.organization_id
return f"User {user_id} in organization {organization_id}"
builder = StateGraph(State, context_schema=Context)
builder.add_node("tools", ToolNode([get_user_info]))
builder.add_edge(START, "tools")
graph = builder.compile()
result = graph.invoke(
{
"messages": [
AIMessage(
content="",
tool_calls=[
{
"name": "get_user_info",
"args": {},
"id": "call_user_info",
}
],
)
],
"user_id": "user_123",
},
context=Context(organization_id="org_456"),
)
# :snippet-end:
# :remove-start:
if __name__ == "__main__":
expected = "User user_123 in organization org_456"
contents = [str(getattr(message, "content", "")) for message in result["messages"]]
assert any(expected in content for content in contents), contents
print("✓ workflows-agents tool runtime state/context sample completed")
# :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 is the agent framework: abstractions and integrations for models, tools, and agent loops.
来源语言 · ENLangGraph 能做什么
- 01Compose deterministic and model-driven steps
- 02Persist and resume execution state
- 03Pause workflows for human input
它有什么不同
It provides lower-level orchestration primitives rather than a prebuilt conversational assistant. LangChain integrations are optional; developers define the state, transitions and tools their workflow requires.
来源语言 · EN谁值得考虑
- Developers building stateful agent workflows
- Teams needing resumable execution and human checkpoints
需要核对的事项
- 用一个真实任务试用,并对照自己的要求检查结果。
- 核实服务会保存、共享或用于训练哪些数据。
- 在官网确认当前价格、使用限额和取消条款。
官网链接核查于 2026年11月9日;功能声明尚未经过独立测试。




