langgraph-zh
Installation
Review the source and dependencies with a prompt. A package is available to download.
Install with an AI assistant
Copy the prompt so your assistant can review the pinned revision and dependencies first.
View promptHide prompt
Check whether SkillPI Skill Finder is installed for your current agent. If it is missing, install and enable it using the official instructions at https://github.com/Findskills/skillpi. Then use Skill Finder to locate and install "langgraph-zh" from this exact SkillPI detail page: https://skillpi.com/skills/deepskill-38f4eea74f0b68e316f259134f712c0ad36871cce8d7725ebf9815af3bf1b8a2. Verify the upstream source and version against https://skillhub.cn/skills/org-02qudk26/langgraph-zh before installing. If they do not match, stop and report the mismatch. Report the installed path and source version.
Source and setup
skillhub.cn
Setup guidance pending
See the original source for supported tools, dependencies, and permissions.
Installation test pending
LangGraph Expert: a production-grade framework for building stateful, multi-participant AI applications, covering graph construction, state management, loops and branching, checkpoint persistence, human-in-the-loop patterns, and ReAct intelligence.
Introduction source: third_party · org-02qudk26 · 1.0.0 Reference
SkillPi interpretation
- Tasks
- Translation pending; see source documentation.
- Audience
- Not specified in the source documentation.
- Inputs and outputs
- Not specified in the source documentation.
- Software, accounts and paid services
- Not specified in the source documentation.
- Limits and differences
- Translation pending; see source documentation.
- Testing
- Not tested
Browse files
Frontmatter
name: langgraph
displayName: LangGraph 智能体框架
description: "LangGraph 专家——用于构建有状态、多参与者 AI 应用的生产级框架。涵盖图构建、状态管理、循环与分支、检查点持久化、人在环路模式以及 ReAct 智能体模式。在 LinkedIn、Uber 等 400 多家公司生产环境中使用。这是 LangChain 推荐的智能体构建方法。适用于:langgraph、langchain 智能体、有状态智能体、智能体图、react 智能体。"
source: vibeship-spawner-skills (Apache 2.0)LangGraph
角色: LangGraph 智能体架构师
您是使用 LangGraph 构建生产级 AI 智能体的专家。您理解智能体需要明确的结构——图使流程可视化和可调试。您精心设计状态,适当使用归约器(reducer),并始终考虑生产环境中的持久化。您知道何时需要循环以及如何防止无限循环。
能力
- 图构建 (StateGraph)
- 状态管理和归约器
- 节点和边定义
- 条件路由
- 检查点和持久化
- 人在环路模式
- 工具集成
- 流式传输和异步执行
要求
- Python 3.9+
- langgraph 包
- LLM API 访问权限 (OpenAI, Anthropic 等)
- 理解图的概念
模式
基本智能体图
带工具的简单 ReAct 风格智能体
适用场景: 带工具调用的单一智能体
from typing import Annotated, TypedDict
from langgraph.graph import StateGraph, START, END
from langgraph.graph.message import add_messages
from langgraph.prebuilt import ToolNode
from langchain_openai import ChatOpenAI
from langchain_core.tools import tool
# 1. Define State
class AgentState(TypedDict):
messages: Annotated[list, add_messages]
# add_messages reducer appends, doesn't overwrite
# 2. Define Tools
@tool
def search(query: str) -> str:
"""Search the web for information."""
# Implementation here
return f"Results for: {query}"
@tool
def calculator(expression: str) -> str:
"""Evaluate a math expression."""
return str(eval(expression))
tools = [search, calculator]
# 3. Create LLM with tools
llm = ChatOpenAI(model="gpt-4o").bind_tools(tools)
# 4. Define Nodes
def agent(state: AgentState) -> dict:
"""The agent node - calls LLM."""
response = llm.invoke(state["messages"])
return {"messages": [response]}
# Tool node handles tool execution
tool_node = ToolNode(tools)
# 5. Define Routing
def should_continue(state: AgentState) -> str:
"""Route based on whether tools were called."""
last_message = state["messages"][-1]
if last_message.tool_calls:
return "tools"
return END
# 6. Build Graph
graph = StateGraph(AgentState)
# Add nodes
graph.add_node("agent", agent)
graph.add_node("tools", tool_node)
# Add edges
graph.add_edge(START, "agent")
graph.add_conditional_edges("agent", should_continue, ["tools", END])
graph.add_edge("tools", "agent") # Loop back
# Compile
app = graph.compile()
# 7. Run
result = app.invoke({
"messages": [("user", "What is 25 * 4?")]
})
带归约器的状态管理
使用自定义归约器进行复杂状态管理
适用场景: 多个智能体更新共享状态
from typing import Annotated, TypedDict
from operator import add
from langgraph.graph import StateGraph
# Custom reducer for merging dictionaries
def merge_dicts(left: dict, right: dict) -> dict:
return {**left, **right}
# State with multiple reducers
class ResearchState(TypedDict):
# Messages append (don't overwrite)
messages: Annotated[list, add_messages]
# Research findings merge
findings: Annotated[dict, merge_dicts]
# Sources accumulate
sources: Annotated[list[str], add]
# Current step (overwrites - no reducer)
current_step: str
# Error count (custom reducer)
errors: Annotated[int, lambda a, b: a + b]
# Nodes return partial state updates
def researcher(state: ResearchState) -> dict:
# Only return fields being updated
return {
"findings": {"topic_a": "New finding"},
"sources": ["source1.com"],
"current_step": "researching"
}
def writer(state: ResearchState) -> dict:
# Access accumulated state
all_findings = state["findings"]
all_sources = state["sources"]
return {
"messages": [("assistant", f"Report based on {len(all_sources)} sources")],
"current_step": "writing"
}
# Build graph
graph = StateGraph(ResearchState)
graph.add_node("researcher", researcher)
graph.add_node("writer", writer)
# ... add edges
条件分支
根据状态路由到不同路径
适用场景: 多种可能的工作流
from langgraph.graph import StateGraph, START, END
class RouterState(TypedDict):
query: str
query_type: str
result: str
def classifier(state: RouterState) -> dict:
"""Classify the query type."""
query = state["query"].lower()
if "code" in query or "program" in query:
return {"query_type": "coding"}
elif "search" in query or "find" in query:
return {"query_type": "search"}
else:
return {"query_type": "chat"}
def coding_agent(state: RouterState) -> dict:
return {"result": "Here's your code..."}
def search_agent(state: RouterState) -> dict:
return {"result": "Search results..."}
def chat_agent(state: RouterState) -> dict:
return {"result": "Let me help..."}
# Routing function
def route_query(state: RouterState) -> str:
"""Route to appropriate agent."""
query_type = state["query_type"]
return query_type # Returns node name
# Build graph
graph = StateGraph(RouterState)
graph.add_node("classifier", classifier)
graph.add_node("coding", coding_agent)
graph.add_node("search", search_agent)
graph.add_node("chat", chat_agent)
graph.add_edge(START, "classifier")
# Conditional edges from classifier
graph.add_conditional_edges(
"classifier",
route_query,
{
"coding": "coding",
"search": "search",
"chat": "chat"
}
)
# All agents lead to END
graph.add_edge("coding", END)
graph.add_edge("search", END)
graph.add_edge("chat", END)
app = graph.compile()
反模式
❌ 无出口的无限循环
为什么不好: 智能体无限循环,消耗 Token 和成本,最终出错。
正确做法: 始终设置退出条件:
- 在状态中添加最大迭代计数器
- 路由中设置明确的 END 条件
- 在应用层面设置超时
def should_continue(state): if state["iterations"] > 10: return END if state["task_complete"]: return END return "agent"
❌ 无状态节点
为什么不好: 失去 LangGraph 的优势。状态未持久化。无法恢复对话。
正确做法: 始终使用状态进行数据流转。从节点返回状态更新。使用归约器进行累积。让 LangGraph 管理状态。
❌ 庞大单一状态
为什么不好: 难以推理。上下文中有不必要的数据。序列化开销大。
正确做法: 使用输入/输出模式定义清晰的接口。使用私有状态存储内部数据。清晰分离关注点。
限制
- 仅支持 Python (TypeScript 处于早期阶段)
- 图概念存在学习曲线
- 状态管理复杂度
- 调试可能具有挑战性
相关技能
与以下技能配合良好:crewai、autonomous-agents、langfuse、structured-output
Current listing version
1.0.0
Safety and assessment details
Quality assessment
Out of 100 · Assessment report from SkillPi LAB.
Highlights
- 提供 LangGraph 智能体框架的完整生产级实现方案
- 涵盖图构建、状态管理、循环分支、检查点持久化等核心功能
- 适用于 LinkedIn、Uber 等 400 多家公司生产环境
Highlights
- 触发词覆盖全面且精准(langgraph、langchain 智能体、有状态智能体等)
- 边界清晰,变体覆盖合理
Areas to improve
-
缺少 When to Use 显式章节 Reported severity: Minor
文档内容已涵盖适用场景,但未设置显式的 When to Use 章节标题
Recommendation: 建议添加显式的 When to Use 章节以提升可读性
Highlights
- 结构清晰,包含多个完整可运行的代码示例
- 提供了反模式说明和生产级最佳实践
- frontmatter 完整,文档组织良好
Highlights
- 工具来源明确(langgraph 包),参数使用正确
- 覆盖了主要异常处理(如无限循环防护)
- 提供了生产级持久化和状态管理最佳实践
The arithmetic mean of the first four original scores, rounded to a whole number.
Static text checks
100 / 100 · skillpi-20261123-no-r3-v1
No current rules matched the text.
This score reflects rule matches in the text and is provided for reference before use. It excludes attachments and runtime behavior.
Permissions and checks before use
Automatically summarized from this main document. Matches may be examples or defensive advice; they are not actual permission declarations. Attachments, external dependencies and runtime behavior are not covered.
These common operations were not identified in the main document. This does not mean no permissions or risks exist.
Security rating and access scope
safe · Static evidence review; not a runtime safety guarantee.
Not specified in the source documentation.
Before use, confirm and authorize actual file access, external services and network destinations in your host. This review grants no runtime permissions.
User discussion
No verified reviews yet.