LangGraph Tutor

### Skill Name: LangGraph Agent Pipeline Architect

Safety Notice

This listing is from the official public ClawHub registry. Review SKILL.md and referenced scripts before running.

Copy this and send it to your AI assistant to learn

Install skill "LangGraph Tutor" with this command: npx skills add duanc-chao/langgraph

Skill Name: LangGraph Agent Pipeline Architect

Skill Description

This 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.

Core Instruction Set

1. State Schema Definition

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: Use Python's TypedDict to define the structure of the state.
  • Reducers: Crucially, define how state updates are handled. Use Annotated types with reducers (e.g., add_messages) to specify that certain fields (like chat history) should be appended to rather than overwritten.
  • Example:
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

2. Graph Construction & Nodes

Treat the agent pipeline as a directed graph where nodes represent units of computation.

  • StateGraph Initialization: Initialize the graph builder using StateGraph(AgentState).
  • Node Definition: Define nodes as standard Python functions (or LangChain runnables) that accept the current state and return a dictionary of updates.
    • Logic: Nodes can perform LLM calls, execute tools, or process data.
    • ToolNode: For standard tool execution, utilize the prebuilt ToolNode to handle tool calling logic automatically.
  • Adding Nodes: Register functions to the graph using graph.add_node("node_name", function).

3. Control Flow & Edges

Define the logic that dictates how the agent moves from one step to the next.

  • Entry Point: Set the starting node using graph.set_entry_point("node_name") or graph.add_edge(START, "node_name").
  • Normal Edges: Use graph.add_edge("node_a", "node_b") for deterministic transitions (e.g., Step 1 always goes to Step 2).
  • Conditional Edges (Routing): Use graph.add_conditional_edges() to implement dynamic logic.
    • Router Function: Create a function that inspects the state and returns a string indicating the next node (e.g., checking if the LLM invoked a tool).
    • Mapping: Map the router's return values to specific node names or END.
    • Cycles: To create an agent loop, map the tool execution node back to the agent node (e.g., toolsagent).

4. Advanced Production Patterns

To build production-ready pipelines, the Agent must implement specific architectural patterns.

  • Human-in-the-Loop:
    • Use 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.
  • Persistence (Checkpoints):
    • Configure a 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.
  • Streaming:
    • Implement streaming to provide real-time feedback. Use app.stream(inputs) to yield events as they happen, rather than waiting for the final response.

5. Execution & Compilation

Finalize the pipeline by compiling the graph into a runnable application.

  • Compilation: Call graph.compile() to validate the graph structure and prepare it for execution.
  • Invocation: Run the agent using app.invoke(inputs) for standard execution or app.stream(inputs) for streaming responses.

Troubleshooting & Common Pitfalls

Infinite Loops

  • Symptom: The agent cycles between nodes (e.g., Agent → Tool → Agent) forever.
  • Fix: Ensure your router logic has a clear exit condition (returning END). Verify that the LLM is correctly bound to tools so it knows when to stop calling them.

State Overwriting

  • Symptom: Chat history disappears after a node update.
  • Fix: Check your 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.

"Graph structure is not valid"

  • Symptom: Compilation fails.
  • Fix: Ensure every node referenced in an edge is actually added to the graph via add_node. Also, ensure there are no "orphan" nodes that are unreachable from the entry point.

Skill Extension Suggestions

Multi-Agent Collaboration

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.

Subgraphs

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.

Dynamic Tool Binding

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.

Source Transparency

This detail page is rendered from real SKILL.md content. Trust labels are metadata-based hints, not a safety guarantee.

Related Skills

Related by shared tags or category signals.

General

Img2img

Generate images from text descriptions using DALL-E 3 while adhering to usage policies and avoiding realistic human faces.

Registry SourceRecently Updated
General

Habitat-GS-Navigator

Navigate and interact with photo-realistic 3DGS environments via the Habitat-GS Bridge. Use when: user asks to explore a 3D scene, perform embodied navigatio...

Registry SourceRecently Updated
General

Memory Palace

持久化记忆管理。Use when: 用户告诉你个人信息/偏好/习惯、需要记住项目状态/技术决策、完成任务后有可复用经验、用户说"记住""别忘了""下次注意"、需要回忆之前的对话内容。支持语义搜索和时间推理。

Registry SourceRecently Updated
General

Podcast Transcript Mining Authority Positioning

Extract guest appearances, speaking topics, and soundbites from podcast transcripts to build authority portfolios and generate podcast pitch templates. Use w...

Registry SourceRecently Updated