The agent loop
Think → act → observe → repeat, stepped through one tool call at a time.
An agent is just a language model using tools in a loop. Instead of answering in one shot, it can think, call a tool, read what comes back, and decide what to do next — repeating until it has enough to respond. Run the example below to watch a single loop play out.
- ThinkTo suggest clothing I need today's weather in Lisbon. I don't know it, so I'll call a tool.
- Act · tool callget_weather({ city: "Lisbon" })
- Observe · result→ 21°C, sunny, light breeze
- Think21°C and sunny: light, breathable clothes, with a thin layer for the evening.
- AnswerPack a t-shirt, light trousers, and a light jacket for the evening — it's 21°C and sunny in Lisbon today.
That's the whole trick behind “agents”: a model in a loop that can call tools, read the results, and decide what to do next — until it has enough to answer. The hard part isn't the loop; it's giving the model good tools and knowing when to stop.
The loop is the whole idea
Think → act → observe → repeat. The model proposes a tool call; your code actually runs it and feeds the result back; the model reasons over that new information. Strip away the buzzwords and that cycle is the entire mechanism.
Where it gets hard
The loop is easy; the surrounding harness is not. Good tools with clear descriptions, sensible stopping conditions (so the agent doesn't loop forever or quit too early), and recovery from failed calls are where most of the real engineering lives.