The bottom of the iceberg, and the smallest idea on it: a model that can call functions, in a loop, until it is done. Ask a question, and instead of answering from memory the model decides which tool it needs, this page runs that tool locally and hands back the result, and the model decides again. Every step of that loop is printed below as it happens, because the loop is the entire lesson. There is no agent framework here, just a while loop and a switch statement.
Each is a plain JavaScript function in this file. The model never runs code; it only ever asks for one of these by name, and this page decides whether to honour the request.
The page sends your message to the model along with a description of the four tools it may use and a strict instruction about how to ask for one: reply with a single line naming the tool and its argument, and nothing else. When a reply comes back in that shape, the page parses it, runs the real function locally, appends the result to the conversation as a new turn, and sends the whole thing back, which is the agent loop in its entirety. The loop is capped at five iterations so a confused model cannot spin forever, and each pass is printed in the transcript so you can watch the model choose, receive, and reconsider. The tools are deliberately things a language model genuinely cannot do on its own: it has no clock, no calculator, and no memory between requests, so it has to ask. Production agents differ mainly in using the API's structured tool-calling format instead of parsed text, and in having tools that touch real systems, which is exactly where the safety questions start.