Skip to content
derpx06Notes on systems, models & learning
7. Tools & Agents · lesson 59 of 68 · 1 min · January 10, 2026

LangGraph: Stateful Agents

Beyond the loop. Why ReAct hits a glass ceiling.

ReAct is a while loop. while not done: act() This works for "Search Google," but it fails for "Write Code -> Test -> Fix -> Deploy." That requires a state machine. It requires Directed Graphs.

LangGraph treats your agent as a graph.

  • Nodes: Functions that do work (e.g., AgentNode, ToolNode, HumanNode).
  • Edges: Logic that decides where to go next (e.g., if tool_called: go_to_tools else: end).

In LangChain chains, state is often implicit (hidden in memory buffers). In LangGraph, you define a explicit StateSchema.

Python
class AgentState(TypedDict):
    input: str
    chat_history: list[BaseMessage]
    agent_outcome: str | None
    intermediate_steps: list[tuple[AgentAction, str]]

Every node receives this State, modifies it, and passes it to the next node. It is Functional Programming applied to Agents.

  1. Cyclic Graphs: You can code explicit loops. Code -> Test -> Fail? -> Fix Code -> Test.
  2. Persistence: You can pause the graph at any node, save specific state to a database, and resume days later.
  3. Human-in-the-Loop: A "Node" can be "Wait for User Approval." The graph literally sleeps until the API receives a POST request.

For simple chatbots, use ReAct. For complex workflows (Coding Assistants, Research Teams), use LangGraph. Structure beats prompt engineering every time.

Key Intuition: "Draw the flowchart. That is your Agent."