Skills2026年4月8日·1 分钟阅读

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 就绪

先审查再安装

这个资产需要先审查。复制的指令会要求 Agent dry-run、列出写入项,确认后再继续。

Needs Confirmation · 66/100策略:需确认
Agent 入口
任意 MCP/CLI Agent
类型
Skill
安装
Single
信任
信任等级:Community
入口
LangGraph — Build Stateful AI Agent Workflows
先审查命令
npx -y tokrepo@latest install b985ba42-4ba9-452d-93f1-9efa434df107 --target codex

先 dry-run,确认写入项后再运行此命令。

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.

常见问题

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.

引用来源 (3)
🙏

来源与感谢

langchain-ai/langgraph — 8k+ stars, MIT

讨论

登录后参与讨论。
还没有评论,来写第一条吧。

相关资产