Skip to main content
Watch: Claude Code Just Killed After Effects
Agents

Build AI agents with LangGraph

LangGraph models agents as state machines. Instead of free-form ReAct loops, you define explicit nodes and edges, which makes complex flows debuggable and resumable.

Prerequisites

  • +Python 3.11+ or Node 20+
  • +OpenAI or Anthropic API key
  • +Basic understanding of state machines

Step-by-Step

  1. 1

    Install LangGraph

    Both TS and Python SDKs are first-class. Pick the one your team already runs.

    pip install langgraph langchain-openai
  2. 2

    Define your state shape

    State is the single source of truth between nodes. Keep it small and serializable.

    from typing import TypedDict, list
    
    class AgentState(TypedDict):
        question: str
        plan: list[str]
        findings: list[str]
        answer: str
  3. 3

    Build nodes for each step

    Each node is a pure function: state in, partial state out.

    from langchain_openai import ChatOpenAI
    llm = ChatOpenAI(model='gpt-4o')
    
    def plan(state):
        msg = llm.invoke(f'Plan steps to answer: {state["question"]}')
        return { 'plan': msg.content.split('\n') }
  4. 4

    Wire the graph

    Add nodes, then add edges. Conditional edges let you branch on state.

    from langgraph.graph import StateGraph, END
    
    g = StateGraph(AgentState)
    g.add_node('plan', plan)
    g.set_entry_point('plan')
    g.add_edge('plan', END)
    app = g.compile()
  5. 5

    Add checkpointing

    Checkpointers persist state between turns. Use SqliteSaver locally and Postgres in prod.

    from langgraph.checkpoint.sqlite import SqliteSaver
    memory = SqliteSaver.from_conn_string(':memory:')
    app = g.compile(checkpointer=memory)
  6. 6

    Stream and inspect

    Stream events to see exactly which node fired. This is huge when debugging.

    for event in app.stream({ 'question': 'compare X and Y' }, config={'configurable': {'thread_id': '1'}}):
        print(event)

Common Pitfalls

  • !Putting too much in state. Anything you do not branch on does not belong there.
  • !Forgetting to set recursion_limit. Buggy loops will hammer your API bill.
  • !Skipping checkpoints. You lose every long-running session on a crash.
From the Developers Digest stack

Agent Hub

Run, monitor, and orchestrate your agent fleet from one dashboard. Built for multi-agent teams.

What's Next

  • ->Add human-in-the-loop interrupts before destructive tools.
  • ->Deploy with LangGraph Cloud or your own FastAPI wrapper.

More Build AI agents

AI Development Stack

Get Smarter About AI Dev

New tutorials, open-source projects, and deep dives on coding agents - delivered weekly.

One email per weekReal code, not theoryFree forever