Build the core agent loop: the model is given a tool and a goal, and it keeps thinking and calling the tool until it can answer. You run the loop, execute each tool call, and feed results back until the model is done.
What separates an agent from a one-shot prompt is the loop. The model does not produce the answer in one step; it takes an action, observes the result, and decides what to do next, repeating until the goal is met. Building this loop once shows you that an "agent" is mostly a model plus tools plus a while loop with a stopping condition.
calculator tool that evaluates a simple arithmetic expression.The agent uses the calculator to do the arithmetic rather than computing it itself, then reports the result.
The loop is the agent. Each pass lets the model see the conversation so far, decide whether to act or answer, and either request a tool or finish. Appending both the model's tool request and the tool's result keeps the history consistent so the next decision is informed. The two stopping conditions, no tool call and the turn limit, are what keep the loop both responsive and safe; everything more sophisticated (more tools, planning, memory) is built on this skeleton.
An agent with one tool has no decision to make. Give it two (a calculator and a word counter) and the interesting behavior appears: it must read the question and pick the right tool. Choosing among tools is the core agent skill that scales to dozens of tools.
calculator and word_count.The agent recognizes a counting question and calls word_count, not the calculator.
With more than one tool, the model's job includes routing: it matches the question to the tool whose description fits. This is why clear tool names and descriptions matter, they are what the model reads to choose. The loop is unchanged from the single-tool version; the new capability comes entirely from offering a choice, which is the same mechanism that lets a real agent select among many tools.