How AI agents work: the loop, the tools and the limits
An AI agent is a model that uses tools in a loop until the task is done. How it works, how risky it is and when a single API call is enough.
Published on · updated on November 26, 2026 · 10 min
An AI agent is a language model, the engine behind assistants such as ChatGPT and Claude, that uses tools (operations it can have carried out, such as a search or saving a piece of data) in a loop: it decides on an action, the software carries it out, the model reads the result and chooses the next step, until the task is finished or a rule stops it. A chatbot answers a question; an agent completes a job with several steps, such as searching, reading, writing and updating data. In practice the difference comes down to one thing: an agent takes actions, so it needs limits and, for actions that leave a mark, a person to approve them.
AI agents and chatbots: the difference
In the guide Building effective agents (December 2024), Anthropic distinguishes two kinds of systems: workflows, where the model and the tools follow paths already written into the code, and agents, where the model itself dynamically decides the steps and which tools to use. The same guide describes agents as typically "LLMs using tools based on environmental feedback in a loop": language models that use tools, round after round, based on what they observe.
| Chatbot | AI workflow | AI agent | |
|---|---|---|---|
| Who decides the steps | Nobody: question and answer | The developer, in the code | The model, at every round |
| What it produces | Text | A result in a fixed format | Actions and a final result |
| Tools | None or few | Called in a fixed order | Chosen by the model |
| When it stops | After one answer | At the end of the path | When the task is done or the round limit is reached |
| Main risk | A wrong answer | A step that fails | Errors that compound from one step to the next |
The loop: model, tool, result, next step
The mechanism is called tool use at Anthropic, the company behind Claude, and function calling at OpenAI, the company behind ChatGPT, and it works the same way. According to Anthropic's documentation on the tool loop, consulted on 19 November 2026, the model never executes anything by itself: it sends a request in a fixed format, your code runs it and the result goes back into the conversation. There are five steps:
- The software sends the request with the task and the list of available tools, each with a name, a description and a parameter schema, meaning the data it accepts.
- The model replies by asking for a tool: for example "look up order 1234 in the database", with the parameters in a fixed format.
- The code carries out the operation: a query (a question put to the database), an HTTP call to another web service, writing a file.
- The result goes back to the model in a new request, together with the whole conversation so far.
- It repeats as long as the model asks for tools; when it replies with the final text, the loop closes.
The OpenAI guide to function calling describes the same loop in five steps, ending with a "final response from the model (or more tool calls)". The point that matters: the code does the executing, not the model. That is where permissions, checks and limits go.
Memory and context: what an agent remembers
A model remembers nothing from one request to the next. What it "knows" while it works is the context window, which Anthropic's documentation calls its "working memory": instructions, messages, tool results and tool definitions, all sent again at every round. On current Claude models it reaches one million tokens, the units models break text into (a short word or part of a word).
Bigger does not mean better: the same documentation warns that as the number of tokens grows, accuracy and recall, meaning the ability to find the right information again, get worse (context rot). Memory from one session to the next has to be built outside the model: files, databases, notes the agent rereads when it starts again.
MCP: a standard socket for tools
The Model Context Protocol (specification dated 28 July 2026) is an open protocol, meaning a set of public rules, for connecting AI applications to external data and tools. It uses a standard message format (JSON-RPC 2.0) between a host (the AI application), its clients and a number of servers, the programs that act as a bridge to a service. Servers offer three things: resources (data and context), prompts (ready-made messages) and tools (functions the model can have executed). The specification takes its inspiration from a standard created for developers' programs, the Language Server Protocol: you write the connection once and every compatible application can use it.
For a business, the advantage is reusing the same connection to your business software with several assistants. On security the specification is clear: tools amount to "arbitrary code execution", meaning they can make the system do anything at all, and the host must obtain the user's explicit consent before using one.
The limits: errors, costs, security
| Limit | What happens | How I contain it |
|---|---|---|
| Compounding errors | A wrong step early on contaminates the ones that follow | Checks in the code on every result, testing in a separate environment |
| Costs | Every round sends the whole context again, tool definitions included | A cap on rounds and on spending, a small model where it is enough |
| Prompt injection | A text the agent reads (email, web page, PDF) contains instructions that try to hijack it | The data it reads does not decide the actions; fixed formats between one step and the next |
| Actions with effects | A sent email or a deleted record cannot be undone | Human approval before the action |
Anthropic writes that the autonomous nature of agents means "higher costs, and the potential for compounding errors", and recommends testing in isolated environments and stopping conditions, such as a maximum number of rounds. In the guide Safety in building agents, OpenAI defines prompt injection as untrusted text that tries to override the instructions, and suggests as remedies approvals on operations, replies in a fixed format (structured outputs) and flows in which untrusted data never directly drives the agent.
When you need an agent and when an API call is enough
Almost always, something less than an agent will do, for example an API call: a single request to the model made by your software. Anthropic advises looking for "the simplest solution possible" and adds that for many applications it is enough to optimise a single call to the model, with retrieval of the right documents and a few examples.
- An API call is enough when the task has a clear input and output: reading a PDF and extracting the fields, classifying a request, writing a draft reply. These are the use cases I described in integrating ChatGPT or Claude into business software.
- You need a workflow when the steps are always the same: first extract, then check, then save.
- You need an agent when the steps cannot be predicted: a search that depends on what you find, work across several sources, a long task with checks along the way.
A real example: the agent that runs this blog
The blog you are reading is run by an AI editor agent. It plans the articles, finds and reads the sources, writes the text, runs the automatic checks and uploads drafts to the website through a protected API. Every round of the loop is a tool: a search, reading an official page, writing a file, a check that flags a figure to verify or a missing link.
The rule that matters: the agent only uploads drafts. Before publication every article goes through a human review, because that is the action with effects, the one that reaches readers.
I apply the same principle in the software I build. In CuraPiù, the care home management software I designed, AI turns a dictated note into data to be confirmed and flags at-risk residents, but every flag goes through validation by a doctor or a nurse. In D@to, VacanzeDigital's tourism management platform that I work on, the d-Buddy assistant works as Copilot, Concierge or Autopilot: the same assistant, in different modes.
Why you need a human in the loop
An agent makes mistakes confidently and without noticing, and it makes them fast. The three sources reach the same conclusion: Anthropic builds in pauses for human judgement, OpenAI advises keeping approvals switched on, and the MCP specification asks for consent before every tool. Reading and proposing can be automated. Sending, paying, deleting and publishing need approval.
Frequently asked questions
What is the difference between an AI agent and a chatbot?
A chatbot answers a question with a text. An AI agent uses tools in a loop to complete a task: it searches, reads, writes and updates data, and at every round it decides the next step based on the result. That is why an agent needs permissions, spending limits and checks that a chatbot does not require.
Can an AI agent work on its own, without supervision?
Technically yes, but for actions with effects it is not a good idea. Anthropic, OpenAI and the MCP specification point to human approvals, stopping conditions and testing in isolated environments. I leave the agent the tasks that can be redone, such as searching, reading and proposing, and I have a person approve sending, payments, deletions and publishing.
What is MCP and what is it for?
The Model Context Protocol is an open protocol that connects AI applications to external data and tools through a standard format, based on JSON-RPC 2.0. An MCP server exposes resources, prompts and tools; any compatible application can use them. The specification requires the user's explicit consent before a tool is invoked.
Does an AI agent cost more than an API call?
Yes, usually. Every round of the loop is a new request that sends the whole context again, including the tool results and their definitions, so the number of tokens grows at every step. That is why I start from the simplest solution, a single call, and move to an agent only when the task really requires it.
Where to start
The problem comes before the agent: a repetitive task that today costs someone hours. With AI integration into the software you already have I start from there, choose the simplest solution that solves it, test it on your data and leave to a person the actions that leave a mark. If you want to see concrete use cases, with API costs, read integrating ChatGPT or Claude into business software. Book your free 30-minute analysis: together we look at your processes and work out whether you need an API call, a workflow or really an agent.