Building an agent loop

An agent is a loop: call the model, run the tool it asked for, feed the result back, repeat. Every loop needs a stopping condition it cannot argue with.

Lesson 3.215m 50sIntermediate16.8k students

Chapters

15:50
  1. 0:00Demo – Agent writes and runs Hello World
  2. 0:22What is OpenClaw?
  3. 1:54Overview of today’s build
  4. 2:40The Agent Loop explained
  5. 4:19Code walkthrough (loop.py
  6. 8:09Tools architecture
  7. 11:07Session storage (JSONL
  8. 12:00Live CLI demo
  9. 14:31File system + session inspection
  10. 15:15What’s next (Personality

What this lesson covers

  • Structure the call, execute, feed back cycle
  • Bound the loop with iteration and token limits
  • Log each step so failures can be replayed

This lesson sits in Tool Calling and Agents, part of Building AI Apps with LLMs. It assumes what came before it and leads directly into the next lesson in the module.

In this lesson you will

  • Structure the call, execute, feed back cycle
  • Bound the loop with iteration and token limits
  • Log each step so failures can be replayed

Resources