Subjects › AGI Agents (6-week course)
W3 · Stateful graphs, memory & planning
LangGraph state, nodes, edges and checkpoints; long-term memory; plan-and-execute and replanning.
The idea
stateful_agent.py rebuilds the ReAct loop as an explicit LangGraph: a typed state whose reducers merge node updates (operator.add appends to the scratchpad), nodes that update it, conditional edges that route, and a checkpointer keyed by thread_id that makes runs resumable (and, as a milestone stretch, interruptible for human approval). Short-term memory is the thread's checkpointed state; long-term memory is a per-user store shared across threads (memory_nodes.py reuses Week 1's EpisodicMemory). Long transcripts are managed like Week 1 working memory — summarise old turns. Plan-and-execute separates planning from doing so a failed step can trigger a bounded replan. In your repo: Week03_ReAct_LangGraph/stateful_agent.py, memory_nodes.py, planning_nodes.py; Exercises 3.3 and 3.4.
Lesson
No lesson built yet. The worked solutions below are the material it would be assembled from.
Questions (5)
| Question | Type | Difficulty | Drift | Accuracy |
|---|---|---|---|---|
| In stateful_agent.py the state declares scratchpad: Annotated[list[str], operator.add] The scratchpad cu… | mcq | Easy -1.20 | — | — (0) |
| In memory_nodes.py's demo, Ada says 'Hi! My name is Ada and I love robotics.' in thread 'monday'. Later, in a … | mcq | Easy -0.50 | — | — (0) |
| Exercise 3.3's adaptive_route (max_replans=2) returns "replan" when the latest step result contains "ERROR" or… | mcq | Moderate 0.40 | — | — (0) |
| Exercise 3.4 adds a summarize node: once a chat's history is long, it asks the LLM to summarise every message … | short | Hard 0.90 | — | — (0) |
| build_react_graph(max_steps=6): the reason node makes one LLM call and increments steps. After reason, route c… | numeric | Very hard 1.60 | — | — (0) |