← 返回 Skills 市场
anderskev

Langgraph Code Review

作者 Kevin Anderson · GitHub ↗ · v1.0.1 · MIT-0
cross-platform ✓ 安全检测通过
176
总下载
0
收藏
2
当前安装
2
版本数
在 OpenClaw 中安装
/install langgraph-code-review
功能描述
Reviews LangGraph code for bugs, anti-patterns, and improvements. Use when reviewing code that uses StateGraph, nodes, edges, checkpointing, or other LangGra...
使用说明 (SKILL.md)

LangGraph Code Review

When reviewing LangGraph code, check for these categories of issues.

Review gates (sequenced)

Complete in order. Each step has an objective pass condition before moving on.

  1. Locate graph code — Search the review scope for StateGraph, compile(, invoke, ainvoke, add_node, add_edge, add_conditional_edges. Pass: a short list of file paths (or explicit “none in scope” after searching).

  2. Map state schema — For each graph state type (TypedDict, BaseModel, etc.), list fields that hold lists, dicts, or messages and whether Annotated + reducers (add_messages, operator.add, …) are present. Pass: every such field is either covered by a reducer pattern below or explicitly flagged as intentional overwrite.

  3. Trace persistence — If interrupts, thread_id, or checkpoint APIs appear, follow them to compile(..., checkpointer=...) and invocation config. Pass: behavior matches the interrupt/checkpointer/thread_id guidance below—or you document a concrete mismatch with file:line.

  4. Report with evidence — For each finding you will deliver, record file path and line number(s) (or a minimal quoted snippet). Pass: no critical or high-severity issue is stated without that citation.

  5. Run the checklist — Use the checklist at the end of this skill; each item is satisfied, not applicable (with reason), or open with evidence. Pass: no item left silently unchecked.

Critical Issues

1. State Mutation Instead of Return

# BAD - mutates state directly
def my_node(state: State) -> None:
    state["messages"].append(new_message)  # Mutation!

# GOOD - returns partial update
def my_node(state: State) -> dict:
    return {"messages": [new_message]}  # Let reducer handle it

2. Missing Reducer for List Fields

# BAD - no reducer, each node overwrites
class State(TypedDict):
    messages: list  # Will be overwritten, not appended!

# GOOD - reducer appends
class State(TypedDict):
    messages: Annotated[list, operator.add]
    # Or use add_messages for chat:
    messages: Annotated[list, add_messages]

3. Wrong Return Type from Conditional Edge

# BAD - returns invalid node name
def router(state) -> str:
    return "nonexistent_node"  # Runtime error!

# GOOD - use Literal type hint for safety
def router(state) -> Literal["agent", "tools", "__end__"]:
    if condition:
        return "agent"
    return END  # Use constant, not string

4. Missing Checkpointer for Interrupts

# BAD - interrupt without checkpointer
def my_node(state):
    answer = interrupt("question")  # Will fail!
    return {"answer": answer}

graph = builder.compile()  # No checkpointer!

# GOOD - checkpointer required for interrupts
graph = builder.compile(checkpointer=InMemorySaver())

5. Forgetting Thread ID with Checkpointer

# BAD - no thread_id
graph.invoke({"messages": [...]})  # Error with checkpointer!

# GOOD - always provide thread_id
config = {"configurable": {"thread_id": "user-123"}}
graph.invoke({"messages": [...]}, config)

State Schema Issues

6. Using add_messages Without Message Types

# BAD - add_messages expects message-like objects
class State(TypedDict):
    messages: Annotated[list, add_messages]

def node(state):
    return {"messages": ["plain string"]}  # May fail!

# GOOD - use proper message types or tuples
def node(state):
    return {"messages": [("assistant", "response")]}
    # Or: [AIMessage(content="response")]

7. Returning Full State Instead of Partial

# BAD - returns entire state (may reset other fields)
def my_node(state: State) -> State:
    return {
        "counter": state["counter"] + 1,
        "messages": state["messages"],  # Unnecessary!
        "other": state["other"]          # Unnecessary!
    }

# GOOD - return only changed fields
def my_node(state: State) -> dict:
    return {"counter": state["counter"] + 1}

8. Pydantic State Without Annotations

# BAD - Pydantic model without reducer loses append behavior
class State(BaseModel):
    messages: list  # No reducer!

# GOOD - use Annotated even with Pydantic
class State(BaseModel):
    messages: Annotated[list, add_messages]

Graph Structure Issues

9. Missing Entry Point

# BAD - no edge from START
builder.add_node("process", process_fn)
builder.add_edge("process", END)
graph = builder.compile()  # Error: no entrypoint!

# GOOD - connect START
builder.add_edge(START, "process")

10. Unreachable Nodes

# BAD - orphan node
builder.add_node("main", main_fn)
builder.add_node("orphan", orphan_fn)  # Never reached!
builder.add_edge(START, "main")
builder.add_edge("main", END)

# Check with visualization
print(graph.get_graph().draw_mermaid())

11. Conditional Edge Without All Paths

# BAD - missing path in conditional
def router(state) -> Literal["a", "b", "c"]:
    ...

builder.add_conditional_edges("node", router, {"a": "a", "b": "b"})
# "c" path missing!

# GOOD - include all possible returns
builder.add_conditional_edges("node", router, {"a": "a", "b": "b", "c": "c"})
# Or omit path_map to use return values as node names

12. Command Without destinations

# BAD - Command return without destinations (breaks visualization)
def dynamic(state) -> Command[Literal["next", "__end__"]]:
    return Command(goto="next")

builder.add_node("dynamic", dynamic)  # Graph viz won't show edges

# GOOD - declare destinations
builder.add_node("dynamic", dynamic, destinations=["next", END])

Async Issues

13. Mixing Sync/Async Incorrectly

# BAD - async node called with sync invoke
async def my_node(state):
    result = await async_operation()
    return {"result": result}

graph.invoke(input)  # May not await properly!

# GOOD - use ainvoke for async graphs
await graph.ainvoke(input)
# Or provide both sync and async versions

14. Blocking Calls in Async Context

# BAD - blocking call in async node
async def my_node(state):
    result = requests.get(url)  # Blocks event loop!
    return {"result": result}

# GOOD - use async HTTP client
async def my_node(state):
    async with httpx.AsyncClient() as client:
        result = await client.get(url)
    return {"result": result}

Tool Integration Issues

15. Tool Calls Without Corresponding ToolMessage

# BAD - AI message with tool_calls but no tool execution
messages = [
    HumanMessage(content="search for X"),
    AIMessage(content="", tool_calls=[{"id": "1", "name": "search", ...}])
    # Missing ToolMessage! Next LLM call will fail
]

# GOOD - always pair tool_calls with ToolMessage
messages = [
    HumanMessage(content="search for X"),
    AIMessage(content="", tool_calls=[{"id": "1", "name": "search", ...}]),
    ToolMessage(content="results", tool_call_id="1")
]

16. Parallel Tool Calls Before Interrupt

# BAD - model may call multiple tools including interrupt
model = ChatOpenAI().bind_tools([interrupt_tool, other_tool])
# If both called in parallel, interrupt behavior is undefined

# GOOD - disable parallel tool calls before interrupt
model = ChatOpenAI().bind_tools(
    [interrupt_tool, other_tool],
    parallel_tool_calls=False
)

Checkpointing Issues

17. InMemorySaver in Production

# BAD - in-memory checkpointer loses state on restart
graph = builder.compile(checkpointer=InMemorySaver())  # Testing only!

# GOOD - use persistent storage in production
from langgraph.checkpoint.postgres import PostgresSaver
checkpointer = PostgresSaver.from_conn_string(conn_string)
graph = builder.compile(checkpointer=checkpointer)

18. Subgraph Checkpointer Confusion

# BAD - subgraph with explicit False prevents persistence
subgraph = sub_builder.compile(checkpointer=False)

# GOOD - use None to inherit parent's checkpointer
subgraph = sub_builder.compile(checkpointer=None)  # Inherits from parent
# Or True for independent checkpointing
subgraph = sub_builder.compile(checkpointer=True)

Performance Issues

19. Large State in Every Update

# BAD - returning large data in every node
def node(state):
    large_data = fetch_large_data()
    return {"large_field": large_data}  # Checkpointed every step!

# GOOD - use references or store
from langgraph.store.memory import InMemoryStore

def node(state, *, store: BaseStore):
    store.put(namespace, key, large_data)
    return {"data_ref": f"{namespace}/{key}"}

20. Missing Recursion Limit Handling

# BAD - no protection against infinite loops
def router(state):
    return "agent"  # Always loops!

# GOOD - check remaining steps or use RemainingSteps
from langgraph.managed import RemainingSteps

class State(TypedDict):
    messages: Annotated[list, add_messages]
    remaining_steps: RemainingSteps

def check_limit(state):
    if state["remaining_steps"] \x3C 2:
        return END
    return "continue"

Code Review Checklist

  1. State schema uses Annotated with reducers for collections
  2. Nodes return partial state updates, not mutations
  3. Conditional edges return valid node names or END
  4. Graph has path from START to all nodes
  5. Checkpointer provided if using interrupts
  6. Thread ID provided in config when using checkpointer
  7. Tool calls paired with ToolMessages
  8. Async nodes use async operations
  9. Production uses persistent checkpointer
  10. Recursion limits considered for loops
安全使用建议
This skill appears coherent and appropriate for automated code review of LangGraph projects. Before installing, decide and limit the review scope (which files/repos the agent may read) so the skill cannot access unrelated private files. Because the agent will read source files, ensure the repository doesn't contain secrets you don't want exposed. If you need extra assurance, manually inspect SKILL.md (it's instruction-only) and run reviews in an environment without network access or with a copy of the code that has secrets removed.
功能分析
Type: OpenClaw Skill Name: langgraph-code-review Version: 1.0.1 The skill bundle is a legitimate tool designed to guide an AI agent through a structured code review process for LangGraph applications. It contains detailed instructions and examples in SKILL.md for identifying common bugs such as state mutation, missing reducers, and incorrect async patterns, without any evidence of malicious intent, data exfiltration, or unauthorized execution.
能力评估
Purpose & Capability
The name/description (LangGraph code review) aligns with the instructions: searching for StateGraph/compile/invoke/add_node/add_edge patterns, tracing state/checkpointer usage, and reporting file:line evidence. No unrelated binaries, env vars, or installs are requested.
Instruction Scope
SKILL.md gives concrete, scoped steps (search for specific symbols, map state schema, trace checkpointer usage, produce file/line citations, run a checklist). It requires reading source files in the review scope, which is appropriate for a code-review skill and does not instruct the agent to read unrelated system files or external endpoints.
Install Mechanism
No install spec and no code files — instruction-only. This minimizes disk writes and install-time risk.
Credentials
The skill declares no environment variables, credentials, or config paths. The requested access (reading repository files for review) is proportionate to the stated purpose.
Persistence & Privilege
always:false and no instructions to modify agent/system configuration or other skills. The skill does not request persistent presence or elevated privileges.
如何使用
  1. 确保已安装 OpenClaw(本地或 Docker 部署)
  2. 在对话框中输入安装命令:/install langgraph-code-review
  3. 安装完成后,直接呼叫该 Skill 的名称或使用 /langgraph-code-review 触发
  4. 根据 Skill 的参数说明提供必要输入,即可获得结构化输出
版本历史
v1.0.1
langgraph-code-review 1.0.1 improves and clarifies code review methodology for LangGraph projects. - Added a structured review workflow ("Review gates") outlining step-by-step checks, each with a clear pass/fail condition. - Checklist methodology now requires specific code evidence (file path and line) for all critical findings. - Emphasizes satisfying, explaining, or explicitly marking each checklist item. - No breaking changes to existing guidance; core bug/anti-pattern catalog remains intact. - Guides reviewers to higher consistency and rigor when reporting issues.
v1.0.0
Initial release of langgraph-code-review: automated checks for common LangGraph code issues. - Detects bugs, anti-patterns, and improvement opportunities in LangGraph code related to state management, graph structure, and async patterns. - Highlights critical problems such as state mutation, missing reducers, incorrect return types, and misplaced checkpointing logic. - Warns about common issues in schema definitions, node connectivity, edge configuration, tool integration, and performance pitfalls. - Provides concise code examples for best practices and potential mistakes. - Covers both sync and async usage, parallel tool calls, and state storage recommendations.
元数据
Slug langgraph-code-review
版本 1.0.1
许可证 MIT-0
累计安装 2
当前安装数 2
历史版本数 2
常见问题

Langgraph Code Review 是什么?

Reviews LangGraph code for bugs, anti-patterns, and improvements. Use when reviewing code that uses StateGraph, nodes, edges, checkpointing, or other LangGra... 它是一个面向 Claude Code / OpenClaw 的 AI Agent Skill 插件,目前累计下载 176 次。

如何安装 Langgraph Code Review?

在 OpenClaw 或 Claude Code 对话框中运行命令「/install langgraph-code-review」即可一键安装,无需额外配置。

Langgraph Code Review 是免费的吗?

是的,Langgraph Code Review 完全免费,采用 MIT-0 许可证,可自由下载、安装和使用。

Langgraph Code Review 支持哪些平台?

Langgraph Code Review 跨平台运行,可在任意部署了 OpenClaw / Claude Code 的环境中使用(cross-platform)。

谁开发了 Langgraph Code Review?

由 Kevin Anderson(@anderskev)开发并维护,当前版本 v1.0.1。

💬 留言讨论