Agentic AI

Human-in-the-loop

Pause a graph for approval, edit its state, and carry on.

Pausing a graph so a person can approve, correct or redirect it, and going back through its saved steps. The module starts with breakpoints: compiled with interrupt_before, the arithmetic agent stops before the model with its state saved, get_state shows where it stopped, and None lets it continue. Then the saved state is edited with update_state, which works through the reducers and can hand the run a person's typed input as a node's output with as_node. The interrupt function moves the question and the answer inside a node, which is how a review step approves, edits or rejects the model's tool calls. Time travel replays a run from any checkpoint or forks it with changed state, and the module ends with an approval agent in one script with Gemini. Run the notebook cells in order, and try each practice task before you open its solution.

Lessons

  1. 1BreakpointsWhy pause a run (approval, debugging, editing), the arithmetic agent on MessagesState, compiling with interrupt_before and a checkpointer, running to the breakpoint, get_state and the StateSnapshot, resuming with None, a loop that meets the breakpoint again, interrupt_after and breakpoints per call, what happens without a checkpointer, interview questions and two practice tasks.
  2. 2Editing the stateCorrecting a request at a breakpoint, what update_state does (reducers, a new checkpoint), replacing and deleting messages, what deleting leaves in the history, a feedback node that waits for typed input, as_node and what it changes, interview questions and two practice tasks.
  3. 3InterruptsBreakpoints and interrupts, the feedback node rewritten with interrupt, what the caller receives and sends back, why the node runs again on resume, approving, editing or rejecting a tool call in a review node, the rules of interrupts, typed answers and several interrupts at once, interview questions and two practice tasks.
  4. 4Time travelWhy rewind, a thread's history newest first, finding a checkpoint, replaying from it and what runs again, forking with update_state on an old checkpoint, the history as a tree of branches, interrupts during time travel, uses and costs, interview questions and two practice tasks.
  5. 5An approval agent in one scriptA complete human-in-the-loop graph in one script: tools, model, a review node that pauses with interrupt, the graph and its checkpointer, a terminal review, the current branch of checkpoints, undo, and a chat loop that resumes with Command; how to run it, which piece to swap for each alternative, and two practice tasks.