AI How language models work, from tokens to reasoning
AI agents explained: when a chatbot starts taking actions
What an AI agent is beyond the marketing: tool use, loops, memory and permissions, plus the failure modes that appear as soon as a model can act rather than answer.
The short answer
- An AI agent is a language model running in a loop: you give it a goal and a set of tools, and it picks each next action by reading the result of the last one.
- The model never runs anything itself. It emits a request to call a named tool, and separate software decides whether that call actually happens, which is where every permission control belongs.
- Reliability drops as the chain gets longer, because a wrong step early on quietly becomes the input to every step after it.
- Agents work best where each step has a cheap automatic check, such as a test that passes or a schema that validates, and struggle where success is a matter of judgment.
- The question to answer before you turn one loose is the blast radius: what is the worst thing it can do in a single step with nobody watching?
An AI agent is a language model in a loop, with tools and a goal. A chatbot answers once and stops. An agent picks an action, runs it, reads what came back, and decides again, until it thinks the goal is met or it hits a limit you set. That is the entire idea. Everything else in the marketing is detail about which tools it was given, who authorized them, and what happens when a step goes wrong.
The loop is the whole idea
An ordinary chat turn is one pass: text in, text out, done. An agent wraps that same model in four extra pieces:
- A goal, stated once at the start, in normal language.
- Tools: search a calendar, read a file, run a query, send an email, execute code.
- A runner (the scaffold) that performs whichever tool the model asks for and feeds the result back in.
- A stopping rule: the model declares itself finished, or it hits a step cap, a spending cap, an unrecoverable error, or a human pressing stop.
Each time round the loop, the whole conversation so far, including every tool result, is sent back through the model. It does not remember the last step. It rereads the transcript and predicts the next action, which is the same operation as predicting the next word in a sentence. Agency is not a new capability inside the model, it is a wiring choice outside it.
| Chatbot | Fixed automation | Agent | |
|---|---|---|---|
| Who decides the next step | You do, each turn | A developer, in advance | The model, at runtime |
| Handles an unexpected result | You read it and retype | Crashes or skips | Tries something else |
| Predictable cost | Yes, one call | Yes | No, varies by run |
| Typical failure | A wrong answer you can see | A broken rule you can trace | A wrong action you find out about later |
| Best for | Thinking, drafting, explaining | Same input, same steps, every time | Steps that depend on what the last step returned |
A worked example: booking a meeting
Goal: find a 30 minute slot with Priya next week and send the invite.
- The model reads the goal and decides it needs availability. It emits a call to
calendar.list_busywith a date range and two email addresses. - The runner executes that call against the real calendar and returns a block of structured data: busy periods, nothing else.
- The model reads it, finds three candidate gaps, and notices every time is stamped in one time zone. It calls
directory.lookupto check where Priya works. - The result says her office is five hours ahead. Two of the three gaps land at 7pm for her, so the model discards them.
- It calls
calendar.create_eventfor the surviving slot, with a title and both attendees. - The tool returns an event ID. The model writes a one line summary to you and stops.
Nobody programmed that time zone check. It happened because the first result contained something that prompted it, and that responsiveness is the capability you are buying.
The failures come from the same place. There are two Priyas in the directory and it picked the wrong one. The free looking gap is a tentative hold she cares about, and busy data carries no such nuance. A person hits either of these and asks. An agent has no instinct that it should ask, unless asking is itself one of its tools.
Tool use is just structured text
This is the part most explanations skip, and it is what makes permissions make sense. Tools reach the model as a list: each has a name, a plain English description of when to use it, and a schema for its parameters. When the model wants one, it executes nothing. It produces a structured block of text naming the tool and filling in the arguments, much as it would produce any other structured format you asked for. Your code parses that, decides whether to allow it, runs it, and appends the result to the conversation.
Two things follow. The tool descriptions are prompts: the model chooses by reading them, so a vague description gets a tool used in the wrong situation and two overlapping descriptions get picked between more or less at random. And more tools is not better, because selection accuracy degrades as the list grows. A tight set of well named tools generally beats a sprawling one.
Every tool result also lands in the context window, which is finite. An agent that dumps a 40 page document into the transcript on step two has spent most of its working space and will lose the early instructions later. Those characters are billed on every subsequent loop too, which is why the token arithmetic gets away from people so quickly.
Memory and what actually carries across steps
Agents use the word memory for three different mechanisms, and confusing them causes trouble.
The transcript is the short term one: everything said and returned so far, resent on every loop. It is exact, and it is capped. When it fills, the scaffold usually summarizes the earlier part and drops the original, at which point precise details such as an account number can silently disappear.
Scratch storage is the middle one. The agent writes a plan or partial results to a file and reads them back later. This survives summarizing, which is why many agents are told to keep a running checklist.
Long term memory is a database the agent can search: past conversations, your documents, company records. Nothing is recalled automatically. Something has to fetch the relevant pieces and paste them in, which is retrieval rather than training, and it fails the way you would expect. If the retrieval misses, the agent carries on confidently without the fact.
Why small errors compound
Take a step that is right 95 percent of the time. Chain twenty of those and the arithmetic leaves roughly a one in three chance the whole run is clean. That is a caricature, since the steps are not independent and a good agent catches some of its own mistakes. But the direction is right, and it explains what people find puzzling: an agent that impresses on a four step demo falls apart on a thirty step job.
What makes it worse than plain unreliability is that a wrong step becomes an input. If step three retrieved the wrong customer record, steps four through twelve are performed competently on the wrong data and the final summary reads as a confident success. The model cannot check reality, so a fabricated detail is treated exactly like a real one for the rest of the run. Empty tool results are a classic trigger: a search returns nothing, and the model fills the gap instead of reporting it.
The mitigations are unglamorous. Keep chains short. Use real code for anything deterministic instead of asking the model to do arithmetic or sorting. Make each step verifiable, and put a check step after the steps that matter. Where you already know the sequence, do not use a loop at all: a fixed chain of prompts with defined handoffs is more reliable, cheaper and far easier to debug. Models that work through a problem before answering plan the next action better, which reduces the rate of bad steps without removing the compounding problem.
Permissions and the blast radius question
Ask one question before any agent touches a real system: what is the worst thing it can do in a single step with nobody watching? Sort its tools into read only, reversible writes, irreversible writes, spending money, and messaging another human. The last three deserve an approval step, because a correction email cannot be recalled and a deleted record may not come back.
The controls that work are ordinary ones: give the agent its own account rather than yours so its actions are distinguishable in the logs, grant the narrowest access that lets it finish, cap the steps and the spend per run, allowlist the destinations it can send to, and log every tool call and result.
One risk is specific to agents. When an agent reads a web page, an email or a shared document, that text enters the same context as its instructions, and the model has no dependable way to separate data from commands. Text planted in a document telling it to forward the contents of the inbox is a real attack, and it works because the instruction layers are all just text in the end. Wide read access plus outbound sending is the combination worth avoiding. If you are buying rather than building, access scope, log retention and liability wording are the clauses to read, which is covered in what to check in an AI vendor contract.
How to try one without regret
Start with a task whose output you can check in seconds, not one you would have to audit. Give read only tools on day one and watch the full trace rather than the summary, because the summary is written by the thing you are evaluating. Then add a single write tool with approval still switched on, and remove that approval only for actions you have watched succeed dozens of times. Set the step cap and the spend cap before the first run rather than after the first surprise. And write down who is accountable for what the agent does, because the answer is never the agent: if several people will be using one, a short written policy saves the argument later.
Common questions
Is an AI agent just a chatbot with a new name?
No, though it uses the same model underneath. The difference is that an agent is allowed to act: it can call tools, read the results and choose what to do next, repeating that cycle without you typing between steps. A chatbot produces text and waits for you. Moving from one to the other changes almost nothing about the model and almost everything about the consequences of a mistake.
Can an AI agent get into my email and files?
Only what it has been given access to. Access comes from credentials that someone connected on purpose, usually when you clicked through an authorization screen, and the agent can do exactly what those credentials permit and nothing more. Check what you granted in the account security settings of the service itself, since that list is often broader than the task required.
Why do agents fail halfway through a long task?
Usually because one early step returned something slightly wrong and every later step built on it. The agent has no way to verify the world independently, so it treats a bad result as fact and continues. The second common cause is a full transcript: once earlier turns get summarized away, the original instructions and exact details go with them.
Do I need an agent or just a workflow automation tool?
If the steps are the same every time, use the automation tool. It is cheaper, it runs in predictable time and you can tell exactly why it broke. Choose an agent when the next step depends on something unpredictable in the last result, such as reading an unstructured reply and deciding which of five paths applies. Many good systems are an automation with one model call inside it.
What does function calling actually mean?
It is the mechanism that lets a model request a tool. The developer supplies a list of available functions with their names, descriptions and expected parameters. Instead of prose, the model returns a structured block naming one function and its arguments. Your own code receives that, decides whether to run it, and returns the result to the model as the next piece of the conversation.