From answering to acting
Everything so far has the model producing text for a human to read. An agent produces text for a machine to act on — then reads what happened and decides what to do next.
The mechanic is unglamorous. You describe some tools in the prompt:
search_orders(customer_id, status) -> list of orders
issue_refund(order_id, amount) -> confirmation
The model, instead of answering, emits a request to call one:
search_orders("c_8812", "shipped")
Your code — not the model — runs it, and puts the result back in the context. The model reads the result and either calls another tool or answers.
That loop, repeated, is an agent:
observe -> decide -> act -> observe -> decide -> ...
Two things follow immediately
The model never executes anything. It writes a request. Your code decides whether to honour it. Every guarantee you have lives in that gap — this is the most important sentence in the topic.
The loop needs a stopping condition. Nothing in "predict the next token"
produces "I'm done." You cap the iterations, or you pay for a model that calls
search_orders forty times in a row because the results never quite satisfied
it.