AI-101 Day 40: The agentic loop, think, act, observe, repeat
Let's demystify one thing: mechanically, an agent is a while loop wrapped around an API call.

There is no magic. A round goes: your prompt goes in → what comes back isn't an answer but a tool request ("read this file for me") → the surrounding program, the harness, actually reads it → the result is appended to the conversation as a new message → the model is called again. Repeat until the model stops asking for tools and returns an answer instead.
The pattern has a name: ReAct (Reason + Act, 2022).
🔌 And here is the part people most often get wrong:
The model has no hands. All it ever does is emit text saying "I would like to run this". The thing that actually opens the file, sends the email or writes to the database is the harness around it.
So the question "what can this agent do?" isn't answered by the model. It's answered by which tools you gave it, and what those tools can actually reach.
🔁 Why loop at all, instead of answering in one go?
Because one-shot means guessing blind. The model has to write the whole plan before seeing anything.
With a loop it can be wrong and then *watch itself be wrong*. The command fails at step three, and step four gets to fix it. That difference isn't intelligence, it's feedback.
⚠️ But the loop has three real failure modes:
1. It doesn't converge, the same failing action, attempted again and again. The most effective fix is unglamorous: paste the raw error back verbatim instead of rewriting it as "that didn't work". Models repair far better from actual stderr than from your summary of it.
The model has to write the whole plan before seeing anything.
2. Context blow-up, every observation is appended and nothing is ever removed. A 30-step task can produce a conversation longer than the document you started with. And each step re-sends the whole conversation (this is precisely what Day 38's KV cache exists for), so cost scales roughly with the square of the step count, not linearly. Day 26's prompt caching stops being a saving and becomes a feasibility requirement.
3. Compounding error, take a wrong turn at step two and the next ten steps are built on it. Models rarely overturn their own earlier judgements unprompted.
Three things worth keeping:
• 🛑 The loop has no natural end, it stops only when the model stops calling tools. So you must impose the bounds yourself: max steps, max spend, timeout. Without them you've written a blank cheque
• 🔍 Debugging an agent means reading the whole trace, not the final answer, the step where it went wrong is usually a long way from where the error surfaced
• 🧰 The ceiling is the tools, not the model. Same model, read-only tools: it's a consultant. Add a send tool: it's an employee
📌 Takeaway: agent = model + loop + tools. The model does the thinking, the loop tells it whether it was right, the tools do the actual reaching. Two of those three are entirely under your control.
More in Teaching
All →
AI-101 Day 41: Evals & benchmarks, can you trust the score?
AI-101 Day 42: Diffusion, why image models work nothing like text models
AI-101 Day 43: Computer-use agents, the model watches your screen and moves the mouse
AI-101 Day 44: Function calling and structured output, making a model emit something a…