SkillsApr 8, 2026·2 min read

LangGraph — Build Stateful AI Agent Workflows

Framework for building stateful, multi-step AI agent workflows as graphs. LangGraph enables cycles, branching, human-in-the-loop, and persistent state for complex agent systems.

Agent ready

Review-first install path

This asset needs a review step. The copied prompt tells the agent to dry-run, show the writes, then proceed only after confirmation.

Needs Confirmation · 66/100Policy: confirm
Agent surface
Any MCP/CLI agent
Kind
Skill
Install
Single
Trust
Trust: Community
Entrypoint
LangGraph — Build Stateful AI Agent Workflows
Review-first command
npx -y tokrepo@latest install b985ba42-4ba9-452d-93f1-9efa434df107 --target codex

Dry-run first, confirm the writes, then run this command.

TL;DR
LangGraph models AI agent workflows as stateful directed graphs with cycles, branching, persistence, and human-in-the-loop controls.
§01

What it is

LangGraph is a framework for building stateful AI agent workflows as directed graphs. Each node in the graph represents a step (LLM call, tool invocation, decision point), and edges define the flow between steps. Unlike linear chain abstractions, LangGraph supports cycles, conditional branching, and parallel execution.

LangGraph targets developers building production AI agents that need reliability features like state persistence, human approval gates, and automatic retries. It is part of the LangChain ecosystem.

§02

How it saves time or tokens

Building a multi-step agent from scratch requires implementing state management, retry logic, and conversation persistence manually. LangGraph provides these as built-in primitives. State is automatically checkpointed between nodes, so agents can resume after failures without restarting.

The estimated token cost for this workflow is approximately 3,900 tokens. LangGraph's graph structure makes it easy to add or remove steps without rewriting the entire agent.

§03

How to use

  1. Install LangGraph:
pip install langgraph
  1. Define a state schema and build a graph:
from langgraph.graph import StateGraph, START, END
from typing import TypedDict

class State(TypedDict):
    messages: list
    next_step: str

def research(state: State):
    # Call LLM or tool
    return {'messages': state['messages'] + ['research done']}

def draft(state: State):
    return {'messages': state['messages'] + ['draft done']}

graph = StateGraph(State)
graph.add_node('research', research)
graph.add_node('draft', draft)
graph.add_edge(START, 'research')
graph.add_edge('research', 'draft')
graph.add_edge('draft', END)
app = graph.compile()
  1. Run the graph:
result = app.invoke({'messages': [], 'next_step': ''})
§04

Example

# Conditional branching example
from langgraph.graph import StateGraph, START, END

def router(state):
    if len(state['messages']) > 5:
        return 'summarize'
    return 'continue'

graph = StateGraph(State)
graph.add_node('process', process_fn)
graph.add_node('summarize', summarize_fn)
graph.add_conditional_edges('process', router, {
    'continue': 'process',
    'summarize': 'summarize'
})
graph.add_edge('summarize', END)
graph.add_edge(START, 'process')
app = graph.compile()
§05

Related on TokRepo

§06

Common pitfalls

  • LangGraph graphs must have at least one path from START to END. Infinite loops without exit conditions will run until timeout or token limits.
  • State must be serializable for persistence to work. Avoid putting non-serializable objects (database connections, file handles) in the state dict.
  • Conditional edges require returning string keys that exactly match the routing map. Typos in routing keys cause silent failures.

Frequently Asked Questions

How is this LangGraph workflow different from the other LangGraph entry?+

TokRepo hosts multiple community-contributed workflows for the same tool. This entry focuses on multi-step workflow patterns, while other entries may cover different aspects like basic agent setup or specific integration patterns.

Does LangGraph require LangChain?+

LangGraph depends on langchain-core, which is lightweight. You do not need the full LangChain library. However, most users combine LangGraph with LangChain's LLM wrappers and tool abstractions.

What persistence backends does LangGraph support?+

LangGraph supports PostgreSQL, SQLite, and Redis for state checkpointing. In-memory persistence is available for development. Production deployments typically use PostgreSQL.

Can LangGraph run multiple agents in parallel?+

Yes. LangGraph supports parallel node execution via fan-out patterns. Multiple nodes can execute simultaneously, and a merge node collects their results before continuing.

What is human-in-the-loop in LangGraph?+

Use interrupt_before or interrupt_after on any node to pause execution. The agent waits for external input (approval, edits, rejection) before continuing. This is how you build approval gates in production agents.

Citations (3)
🙏

Source & Thanks

Created by LangChain. Licensed under MIT.

langchain-ai/langgraph — 8k+ stars

Discussion

Sign in to join the discussion.
No comments yet. Be the first to share your thoughts.

Related Assets