An AI agent is a program where the language model, not your code, picks the next step: which tool to call, and when to stop. Get that choice wrong and you either pay agent prices for a job a script could do, or ship a loop that never stops.
A language model, the kind of AI behind a chatbot, can only produce text. So you give it a list of tools. A tool is just a function you wrote, plus a short description of what it does and what it needs. The model can then reply with a structured request, like "call get_weather with location=Boston". In Anthropic's API (the interface programs use to talk to Claude), that request arrives as a tool_use block, a labelled piece of the reply.
The model never runs your function itself. Your code does, then sends the output back as a tool_result block, and the model reads it and picks again. That repeats until the model decides it's done, so the path the program takes isn't known until it runs.
When should the model steer? If you can write the steps down in advance, build a fixed workflow: plain code that follows those steps. Hand the steering to the model only when you can't predict how many steps the task will take. Anthropic notes that agents often trade speed and cost for better results, and that mistakes can compound across steps.
Every real agent loop also needs a hard cap on iterations (trips around the loop), written in ordinary code. Nothing guarantees the model will ever decide it's finished. A confused model that keeps retrying a failing tool can run up a large bill before anyone notices. The cap gives you a clear place to decide what happens on timeout: return a partial result, or hand the task to a person.