Index

Free, with Google

Keep going, free.

A free account opens lessons 2 and 3 of every track, 33 more lessons, and keeps your progress and review cards on every device.

Start free with Google

A chalk plan

Open everything on chalk.

Every lesson, board, video, lab and paper, and the full review decks. Yearly is $39/year.

See plansStart free instead

Module 05 · AI · The loop and its harness · about 28 min to read

Play it as a journeyTutor comes with a plan

The Loop (an agent is a while loop around one model call)

The Loop
The Loop · Open board

Building with LLMs, the track on large language models. Structured Output and Tool Schemas (the contract between model and code) gave the model a fixed form to fill in whenever it wants something done, and a piece of code that checks the form before anything runs. This board is about what happens when that runs over and over: run the request, hand the result back, ask the model again, until it either answers or the code around it decides enough is enough. Top right times one ordinary round of that on the returns desk: two calls to the model and one lookup, 5.3 seconds start to finish. Strip the word “agent” from all of it and four steps remain, going in a circle. Everything hard is deciding when the circle stops.

Before you start. The running example is a support assistant for an online shop’s returns desk: software that answers customer messages, and that can look up an order or start a return. A model reads and writes in tokens, a token being a word or a piece of one, and it remembers nothing between calls: whatever it wrote a moment ago exists for its next call only if the code pastes it back into the text in front of it, the prompt. A tool call is the model writing out a request instead of an answer, the way the returns desk’s assistant asked to look up order 4471 in the last two lessons. This lesson is about what happens after that request: who runs it, what it costs, and who decides when to stop asking.

Lesson 45 of 83 in AI

The rest of this lesson is part of a plan.

A plan opens every lesson, board, video, lab and paper on chalk. Yearly is $39/year.

See plansAlready a member? Sign in

Or start free: a free account opens lessons 2 and 3 of every track.

In this lesson

  • March 30, 2023: a program that calls itself in a loop
  • What broke: nothing was watching the circle
  • The fix: bound the loop, and name every way out
  • One round of the returns desk
  • The circle, one stop at a time
  • Where do the 5.3 seconds go?
  • How a turn ends
  • A harder customer, then a million of them
  • All of it in code

Terms it explains: iteration, loop guard, timeout, budget, escalate, turn, window, Write its answer down, Check the form, Check for a repeat, 135 ms, 8 ms, 5.3 seconds, exit-reason histogram.

Lab

The returns desk's loop keeps asking the model until it answers. How many passes before it hands the customer to a person?

Drag Passes before a person takes over from 1 to 20, then raise Tool calls that fail, and watch the day's bill.

Open The loop cap

Related papers

Review AI