0PricingLogin
AI Agents · Lesson

Nodes, Edges and State

Define a TypedDict state, write node functions that mutate it, and connect them with directed edges.

The State Object

Every LangGraph agent has a typed state — usually a TypedDict:

from typing import TypedDict
from typing_extensions import Annotated
import operator

class AgentState(TypedDict):
    messages: Annotated[list, operator.add]   # appends instead of replaces
    plan: str
    answer: str

How State Updates Work

Each node returns a partial dict. LangGraph:

  1. Reads current state
  2. Calls the node with it
  3. Merges the returned partial dict back

For list fields with operator.add, new items append instead of overwriting.

All lessons in this course

  1. Why Graphs Beat Flat Chains
  2. Nodes, Edges and State
  3. Conditional Routing and Branching
  4. Persisting Graph State (Checkpoints)
← Back to AI Agents