The Agent Loop, From Scratch

Build the loop every AI agent runs on, in plain Python, and learn exactly where it breaks.

Text courseBeginnerFree

Frameworks hide the loop. This short course takes it apart: one model call, one tool, one stopping rule at a time. By the end you can read any agent framework's source and know what it is doing, and why your agent loops forever or quits too early.

What you'll learn

  • Write a working agent loop in about 30 lines
  • Expose tools so the model can act, and handle their errors
  • Stop the loop on purpose: budgets, step limits and done-checks
  • Decide what state to keep between steps and between runs
  • Debug a run from its trace, and replay it without paying for model calls
  • Build a codebase Q&A agent end to end, and find the same loop inside any framework

Course content