Skip to content
← All writing
June 30, 2026·7 min read

AI Agents Explained: From Chatbots to Tools

"AI agent" is one of the most overused phrases in software right now, and one of the least clearly defined — depending on who's talking, it means anything from a chatbot with a personality to a fully autonomous employee replacement. Strip away the marketing and an agent is a specific, understandable idea: a language model that can take actions in a loop until a goal is met, rather than just producing one reply. That's it. No mystery, no emergent consciousness — a loop, some function calls, and a model deciding what to do next.

This post explains what that means mechanically, when it's genuinely worth the added complexity, and how to keep one from embarrassing you in production.

From answering to acting

A plain LLM call is a single turn: you send text, it sends text back. Useful, but passive — it can tell you how to do something, but it can't do it. Ask a plain model "how many orders shipped last week?" and it can only explain how one might find out.

An agent adds two things:

  1. Tools — functions the model is allowed to call, like "search the web," "query the database," "send an email," or "run a calculation."
  2. A loop — the model can call a tool, see the result, reason about it, and decide what to do next, repeating until the task is finished.

That loop is the whole difference. The model becomes a decision-maker that can gather information and change the world, not just describe it. Ask the agent version about last week's orders and it calls your query_orders tool, reads the result, maybe notices it needs to clarify the date range, queries again, and answers with real numbers.

The agent loop, step by step

Most agents — from toy demos to serious coding assistants — follow the same basic cycle:

  1. Observe — the model receives the goal and the current state.
  2. Think — it decides what to do next: answer directly, or call a tool.
  3. Act — if it chose a tool, your code runs that tool and captures the result.
  4. Feed back — the result is appended to the context, and the loop repeats.
  5. Finish — when the model decides the goal is met, it returns a final answer.

Notice who runs the loop: you do. The model never executes anything itself — it only ever emits a request, and your code decides whether and how to honour it. That's worth internalizing, because it means every safety property of an agent is a property of your code, not the model's goodwill. Your job as the developer is to define the tools, run them safely, and keep the loop from running forever.

Tool calling is the core mechanism

Modern models support "tool calling" (also called function calling): you describe your tools — their names, purpose, and parameters, as JSON schemas — and instead of replying with prose, the model can reply with a structured request to call one, arguments filled in. Your code executes it and returns the result. This structured hand-off is what makes agents reliable enough to build on; before it, "agents" meant parsing actions out of freeform text and hoping.

You define:   getWeather(city: string)
Model emits:  { tool: "getWeather", args: { city: "Cairo" } }
You run it:   → "34°C, sunny"
Model uses that result to answer.

The craft of writing these definitions well — naming, descriptions, parameter design, error messages — turns out to be most of what separates a reliable agent from a flaky one. I've written a whole post on designing good tools, because in practice most "the agent is being dumb" bugs are tool-design bugs.

Where agents genuinely help

Agents earn their complexity when a task:

  • Requires several steps that can't be known in advance ("research this topic and summarize the top sources" — how many searches? depends on what the first ones find).
  • Needs live information or actions the model can't do alone (look something up, modify a record, check today's data).
  • Branches based on intermediate results — the next step depends on what the last step returned.

Customer-support assistants that look up orders before answering, coding assistants that read files, run tests, and fix what failed, and research assistants that gather and synthesize sources are all natural fits. What they share: the path through the task is genuinely unknowable up front, so something has to decide at each step, and that something might as well be the model.

Where agents hurt

Agents are powerful and extremely easy to overuse — right now the industry default is to reach for one wherever an API call would do. Avoid them when:

  • A single call would do. If the task is one step — classify this, summarize that — an agent adds latency, cost, and failure modes in exchange for nothing.
  • Reliability is critical and the path is fixed. If the steps are always "fetch, transform, summarize, save," write that as a workflow that calls the model at known points. A hard-coded sequence is more predictable, more debuggable, and cheaper than letting the model improvise the same sequence with occasional creative deviations.
  • The tools are dangerous. Every tool an agent can call is something it might call wrongly — with the wrong arguments, at the wrong time, or under the influence of injected instructions in the content it's processing. Giving an agent unrestricted power to delete data or spend money is asking for trouble.

A good rule: use the least autonomy that solves the problem. Often a fixed workflow with a couple of model calls beats a fully autonomous agent on every axis that matters in production. Anthropic's essay on building effective agents makes the same argument with patterns for the middle ground — workflows, routers, and orchestrators that use model judgement without surrendering the steering wheel.

Making agents safe and affordable

  • Cap the loop. Set a maximum number of steps so a confused agent can't spin forever, burning tokens. A stuck agent should become a logged error, not an invoice.
  • Constrain tools. Give read-only tools wherever possible, and require confirmation — human or two-phase — for anything destructive or costly. Least privilege applies to models even more than to people, because models can be talked into things.
  • Validate tool inputs. Treat the model's tool arguments as untrusted input — check types, ranges, and authorization in code before acting. Never rely on the prompt to enforce a security rule.
  • Log the trace. Record every step: what the model saw, what it called, what came back. When the agent does something surprising in production — and it will — the trace is the only way to understand why. It's also your best source of evaluation cases.
  • Watch the cost. Each loop step is another model call carrying the growing conversation, so token usage compounds per step. Multi-step agents can get expensive fast; monitor tokens per completed task, not per call.

Summary

An AI agent is a language model given tools and a loop, so it can decide, act, and iterate toward a goal instead of just replying once — and the loop always runs in your code, which is where every safety guarantee has to live. That unlocks genuinely useful multi-step behaviour, but it multiplies cost, latency, and risk with every step. Reach for an agent only when the task truly needs open-ended, multi-step action; prefer fixed workflows when the path is known; give whatever you build the least power that works; and always cap the loop and log the trace. Used deliberately, agents are a strong tool. Used reflexively, they're an expensive way to make software less predictable.

Further reading