How AI agents use tools
An agent is a model in a loop with a list of available actions. It reads the goal, chooses an action and its arguments, the surrounding program runs that action for real, the result comes back as text, and the loop repeats until the goal is met or a limit is hit.
What does one turn of the loop look like?
- 1The program sends the goal, the history so far and the list of tools.
- 2The model replies either with an answer or with a structured tool call.
- 3The program validates the arguments and runs the tool.
- 4The result — data or an error — is appended to the history.
- 5The loop repeats with the new information.
The model is not executing anything. Every real effect happens in the program around it, which is where your limits, checks and logging belong.
Why do good tool descriptions matter so much?
The description is the only thing the model has when choosing between tools. 'Get data' is a coin flip; 'Return the last 30 days of orders for a customer, by email' is a decision. Ambiguous names and overlapping tools are the main cause of an agent doing something reasonable-looking and wrong.
- Name the tool after the intent, not the endpoint.
- Say what it returns, including what happens when nothing matches.
- Constrain the input schema tightly — enums instead of free text where possible.
- Avoid two tools that could both plausibly answer the same request.
How do agents fail?
| Failure | What it looks like | Mitigation |
|---|---|---|
| Wrong tool chosen | A plausible action on the wrong data | Clearer descriptions, fewer overlapping tools |
| Bad arguments | Validation error, or the right action on the wrong record | Strict schemas, validate before running |
| Looping | The same call repeated with small variations | Step limits and loop detection |
| Silent success | Reports done without checking | Make the tool return verifiable state |
| Prompt injection | Fetched content instructs the model | Treat tool output as untrusted data |
Where should a human sit in the loop?
At the actions that are hard to undo. Reading is cheap to get wrong; sending an email, charging a card, deleting records and pushing code are not. A confirmation step at exactly those points buys most of the safety without making the agent useless.
Reversibility is a better rule than importance. Ask whether you could undo it in a minute, and gate what you could not.
How do you debug one?
- 1Read the trace: every tool call, its arguments and its result.
- 2Find the first step that was wrong, not the step where it became obvious.
- 3Decide whether the model chose badly or the tool behaved badly.
- 4Fix the description or the schema if it chose badly; fix the tool if it returned something misleading.
- 5Re-run the same goal and confirm the earlier step now goes the other way.
Frequently asked questions
- What makes an agent different from a chatbot?
- The loop and the tools. A chatbot answers; an agent takes actions and reads the results of those actions before deciding what to do next.
- Do agents need MCP?
- No. MCP is one standardised way to supply tools. Many agents use tools defined directly in their own code.
- Why did it say it finished when it did not?
- Because it reported on the actions it took rather than checking the outcome. Tools that return verifiable state fix this better than stern instructions.
Practice this in MessyDev
Reading it once helps. Doing it once sticks. These are the hands-on parts of MessyDev that cover the same ground.
Keep going
- What is MCP?The Model Context Protocol as a technical shape: hosts, clients, servers, tools, resources and prompts — and what changes when a tool is exposed through it.
- How AI coding tools workInside an AI coding tool: the model, the context window, the tool calls, the build loop, and why the wrapper around the model matters as much as the model.
- MCP explained for beginnersA plain-language introduction to what MCP is for, using the everyday situations where an AI assistant needs something it cannot see.