Install
openclaw skills install langgraphArchitect and deploy advanced LangGraph AI pipelines with stateful graphs, conditional routing, human-in-the-loop, persistence, and streaming execution featu...
openclaw skills install langgraphThis skill instructs an Agent to architect, build, and deploy robust AI agent pipelines using LangGraph. It focuses on moving beyond simple linear chains to create stateful, cyclical, and multi-actor systems. The Agent will learn to define state schemas, construct graph nodes, manage control flow with conditional edges, and implement production-grade features like human-in-the-loop and persistence.
The foundation of any LangGraph pipeline is the State. The Agent must define a shared state object that acts as the "memory" passed between nodes.
TypedDict to define the structure of the state.Annotated types with reducers (e.g., add_messages) to specify that certain fields (like chat history) should be appended to rather than overwritten.from typing import Annotated, TypedDict
from langgraph.graph.message import add_messages
from langchain_core.messages import BaseMessage
class AgentState(TypedDict):
# 'add_messages' ensures new messages are appended to the history
messages: Annotated[list[BaseMessage], add_messages]
query_type: str # A simple string field for routing logic
Treat the agent pipeline as a directed graph where nodes represent units of computation.
StateGraph(AgentState).state and return a dictionary of updates.
ToolNode to handle tool calling logic automatically.graph.add_node("node_name", function).Define the logic that dictates how the agent moves from one step to the next.
graph.set_entry_point("node_name") or graph.add_edge(START, "node_name").graph.add_edge("node_a", "node_b") for deterministic transitions (e.g., Step 1 always goes to Step 2).graph.add_conditional_edges() to implement dynamic logic.
state and returns a string indicating the next node (e.g., checking if the LLM invoked a tool).END.tools → agent).To build production-ready pipelines, the Agent must implement specific architectural patterns.
interrupt_before=["node_name"] in the compile method. This pauses the graph execution before a specific node (e.g., before executing a sensitive tool), allowing a human to approve or modify the state before resuming.checkpointer (e.g., MemorySaver or a database) when compiling the graph. This allows the agent to pause, resume, and retain memory across long-running conversations or distinct threads.app.stream(inputs) to yield events as they happen, rather than waiting for the final response.Finalize the pipeline by compiling the graph into a runnable application.
graph.compile() to validate the graph structure and prepare it for execution.app.invoke(inputs) for standard execution or app.stream(inputs) for streaming responses.END). Verify that the LLM is correctly bound to tools so it knows when to stop calling them.State definition. Ensure you are using Annotated[..., add_messages] for the messages list. Without the reducer, the default behavior is to overwrite the key with the new value.add_node. Also, ensure there are no "orphan" nodes that are unreachable from the entry point.Expand the pipeline to include multiple specialized agents (e.g., "Researcher", "Writer", "Editor"). Use a "Supervisor" node to route tasks between them based on the current context.
Teach the Agent to encapsulate complex logic into a subgraph (a graph within a graph). This allows for modular design, where a "Research" node might actually trigger an entire internal research workflow.
Implement logic where the available tools change dynamically based on the user's query or the current state, requiring the Agent to re-bind the LLM to different tool sets at runtime.