Lab: The agent loop moves into the package
45 min read·13 Oct 2026
Module 5 · Lab · About 75 minutes · Needs: the Module 3 lab'stools.py, and lessons 1 and 3 (run_agent,over_limit,actandbuild_graph;interrupt, the SQLite checkpointer andRunControl); Lesson 2 for the reasons a loop is worth its cost
What you are building
This lab moves the module's loop into returns_desk/loop.py, so later modules import it instead of pasting it. The file holds Lesson 1's loop with its four limits and named stop reasons, the same loop as a LangGraph graph, and Lesson 3's approval graph: it pauses before Aisha's $129.00 refund, survives a restart, and stops when Priya cancels. Every tool call still goes through Module 3's call, imported from tools.py, never copied. Tests pin the stop reasons with a stand-in model, then a real model works two requests. Everything at BrightCart is simulated.