Cette page est affichée en anglais. Une traduction française est en cours.
SkillsApr 6, 2026·2 min de lecture

LangGraph — Stateful AI Agent Graphs by LangChain

Framework for building stateful, multi-actor AI agent applications as directed graphs. Supports cycles, branching, persistence, and human-in-the-loop patterns. By LangChain. 8,000+ stars.

LangChain
LangChain · Community
Prêt pour agents

Installation avec revue préalable

Cet actif nécessite une revue. Le prompt copié demande un dry-run, affiche les écritures, puis continue seulement après confirmation.

Needs Confirmation · 66/100Policy : confirmer
Surface agent
Tout agent MCP/CLI
Type
Skill
Installation
Single
Confiance
Confiance : Community
Point d'entrée
LangGraph — Stateful AI Agent Graphs by LangChain
Commande avec revue préalable
npx -y tokrepo@latest install dbf0bc9a-0bb1-4efb-a033-3bdd498f6a63 --target codex

Dry-run d'abord, confirmez les écritures, puis lancez cette commande.

TL;DR
LangGraph models AI agents as stateful directed graphs with cycles, branching, and human-in-the-loop patterns.
§01

What it is

LangGraph is a framework by LangChain for building stateful, multi-actor AI agent applications as directed graphs. Instead of linear chains, LangGraph lets agents loop, branch, wait for human input, and checkpoint state automatically.

It targets AI engineers and teams building production agent systems that require retry logic, parallel tool calls, approval gates, or long-running workflows.

§02

How it saves time or tokens

LangGraph eliminates the boilerplate of building state machines for agent orchestration. Its built-in persistence means you do not need to implement checkpointing or crash recovery. The human-in-the-loop primitives (interrupt_before, interrupt_after) replace custom webhook and polling logic. By modeling agents as graphs, you can visualize and debug complex multi-step flows instead of tracing through nested function calls.

§03

How to use

  1. Install LangGraph:
pip install langgraph
  1. Define state and nodes:
from langgraph.graph import StateGraph, END
from typing import TypedDict

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

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

def writer(state: State):
    return {'messages': state['messages'] + ['draft complete']}
  1. Build and compile the graph:
graph = StateGraph(State)
graph.add_node('research', researcher)
graph.add_node('write', writer)
graph.add_edge('research', 'write')
graph.add_edge('write', END)
graph.set_entry_point('research')
app = graph.compile()
result = app.invoke({'messages': [], 'next_step': ''})
§04

Example

A ReAct agent with validation loop:

def should_continue(state: State):
    if 'valid' in state['messages'][-1]:
        return 'end'
    return 'retry'

graph = StateGraph(State)
graph.add_node('act', researcher)
graph.add_node('validate', writer)
graph.add_conditional_edges('validate', should_continue, {
    'retry': 'act',
    'end': END
})
graph.add_edge('act', 'validate')
graph.set_entry_point('act')
app = graph.compile()
§05

Related on TokRepo

§06

Common pitfalls

  • Creating infinite loops without a max-iteration guard causes runaway token spend. Always add a counter or timeout to conditional edges.
  • Storing large objects in graph state slows checkpoint serialization. Keep state lean and reference external storage for big payloads.
  • Mixing synchronous blocking calls inside async graph nodes degrades throughput. Use async-native tool implementations.

Questions fréquentes

What is the difference between LangGraph and LangChain?+

LangChain provides building blocks like LLM wrappers, tool schemas, and prompt templates. LangGraph is the orchestration layer that connects those blocks into stateful agent graphs with loops, branching, and persistence. LangChain recommends LangGraph for non-trivial agent applications.

Does LangGraph support persistence across restarts?+

Yes. State is automatically checkpointed between nodes. LangGraph supports PostgreSQL, SQLite, and Redis as checkpoint backends. If a node fails, the agent resumes from the last checkpoint.

How does human-in-the-loop work in LangGraph?+

Use interrupt_before or interrupt_after on any node. Execution pauses and returns control to your application. When you provide input (approval, edit, rejection), the graph resumes from that point.

Can LangGraph run without LangChain?+

Technically yes. LangGraph depends only on langchain-core, which is lightweight. You can build graph-based workflows without using LangChain's full LLM abstractions, though most users pair them.

What observability does LangGraph provide?+

When a LANGCHAIN_API_KEY is set, every node execution is traced in LangSmith with token usage, latency, and tool call details. LangSmith offers a free tier for small projects.

Sources citées (3)
🙏

Source et remerciements

Created by LangChain. Licensed under MIT.

langgraph — ⭐ 8,000+

Thanks to the LangChain team for making complex agent workflows manageable.

Fil de discussion

Connectez-vous pour rejoindre la discussion.
Aucun commentaire pour l'instant. Soyez le premier à partager votre avis.

Actifs similaires