The whole idea: one loop

Products like OpenAI Dots, Meta Muse and Grok Bot look magical, but each step they take is the same: the model picks an action, your code runs it, the result goes back to the model. Repeat until done.

The 40-line agent

How it works

Tools are plain functions in a dictionary. The model (stubbed as fake_llm) returns either {"tool", "input"} or {"final"}. The loop runs the tool, stores the result in history, and asks again. The guard rails — max_steps and the unknown-tool check — keep it from looping forever or calling something it shouldn’t.

Extend it

Open it in the editor and ask the AI assistant: "add a tool that reverses a string" or "add memory so the agent remembers past goals." Then follow the LLM API guide to replace the stub with a real model. If it breaks, check the 7 most common agent bugs.