← frameworks directory○ community

Framework · Both · LangChain

LangGraph.

When your agent has loops, retries, conditional branches, and human-in-the-loop checkpoints, LangGraph's state-machine model is the cleanest way to express that without it turning into spaghetti.

$ pip install langgraph

LangGraph started as a side project inside LangChain and quietly became the more interesting part of the ecosystem. The pitch is simple. An agent is a state machine, so model it as one. Define nodes (LLM calls, tools, decisions), edges (transitions, conditional or otherwise), and let the graph runtime handle the choreography.

It is the right framework when your agent is more than a single loop. When it has multiple specialists, branching paths, persistent state across steps, or needs to pause for human approval before continuing. Most production agentic systems eventually grow into one of those shapes, and the question is whether you express that growth as a hand-rolled mess or as a graph.

§01The mental model

The graph runtime works with four primitives:

  • Nodes are functions that take state and return updated state. Usually an LLM call, a tool call, or a decision.
  • Edges are transitions between nodes. Conditional edges let the graph branch on state.
  • State is a typed object that flows through the graph and accumulates as it runs.
  • The checkpointer is a persistence layer that lets you pause, resume, or time-travel through runs.

§02Why graphs over loops

A naive agent loop (call model, run tool, repeat) breaks down the moment you need parallel work, conditional handoff between specialists, or a way to ask a human a question and resume. The graph model handles all three natively, and the visualization that comes for free with the runtime makes debugging actually possible. Writing the same behavior as a flat loop produces code that is fine for a week and unmaintainable by month two.

§03Setup

pip install langgraph

from langgraph.graph import StateGraph, END

graph = StateGraph(MyState)
graph.add_node("research", do_research)
graph.add_node("write", do_write)
graph.add_conditional_edges(
    "research",
    lambda s: "write" if s.notes else "research",
)
graph.add_edge("write", END)
app = graph.compile()

TypeScript users get a parallel API in @langchain/langgraph. The docs are slightly less polished, but the primitives match.

§04Caveats

  • Graphs feel heavy until they earn their keep. For a single-loop agent, the abstraction is overhead. Reach for it once branches and persistent state appear.
  • LangChain dependency lineage. LangGraph is leaner than full LangChain, but it inherits some of the imports and conventions. Read what comes in.
  • State design matters more than node design. A messy state object makes the graph painful to reason about. Spend time on the schema before writing any nodes.