Code Safari

Chapter 69·Beginner·9 min read

What Is an AI Agent? From Chatbot to Autonomous Worker

A clear, plain-English explanation of what an AI agent actually is — how it differs from a plain LLM or chatbot, the loop of perceive-think-act that defines it, and when you actually need one.

June 30, 2026

Large language models are good at one thing: given some text, predict the next bit of text. That single ability powers everything from chat to code completion. But a model on its own is sealed in a box — it can describe how to book a flight, but it can't book one. An AI agent is what you get when you give that model hands, eyes, and a loop.

This guide assumes you know roughly what an LLM is. If "next-token prediction" is fuzzy, skim What is an LLM? first — it's the foundation everything here builds on.

A chatbot answers; an agent acts

Picture the difference with a concrete task: "Find the cheapest flight from London to Tokyo next month and hold it."

A plain chatbot will write you a plausible-sounding plan, maybe invent some prices, and stop. It produced text. That's all it can do.

An agent treats the same sentence as a goal. It searches real flight data, compares results, calls a booking API, and reports back what it actually did. The model is still just predicting text under the hood — but that text is now interpreted as actions, and the results of those actions feed back into the next prediction.

Goal
Model decides an action
Action runs
Observe result
Decide again
A plain model stops at text; an agent closes the loop with the world

That feedback loop is the entire idea. Everything else in this guide — planning, memory, tools, frameworks — is machinery for running that loop well.

The agent loop: perceive, think, act

Strip away the jargon and every agent, however fancy, runs the same cycle:

  1. Perceive — read the current state: the goal, what's happened so far, the latest tool result.
  2. Think — reason about what to do next given that state.
  3. Act — take exactly one action (call a tool, or decide it's finished).
  4. Observe — feed the action's result back in, and loop.
StageWhat it isExample
PerceiveThe context the model reads"Goal: hold a flight. So far: found 3 options."
ThinkThe model's reasoning step"Option 2 is cheapest; I should book it."
ActA concrete tool callbook_flight(option=2)
ObserveThe result, added to context"Booking confirmed, ref ABC123."

The loop ends when the model decides the goal is met, hits a step limit, or fails. Notice that the model never "remembers" anything by itself between steps — each pass, it re-reads the accumulated history. That detail will matter a lot when we reach memory.

What makes a system "agentic"

The word agent gets stretched to cover everything, so here's a useful line. A system is agentic to the degree that the model — not your code — decides the control flow.

  • A fixed pipeline ("summarize, then translate, then email") is not an agent. You wrote the steps; the model just fills in blanks.
  • A system where the model picks which step comes next, and keeps going until it's satisfied, is an agent.

Most real products live on a spectrum between the two. The more you let the model steer, the more flexible — and the less predictable — the system becomes.

When you actually need an agent

Agents are powerful and over-used. The honest test is the shape of the task:

Task shapeUse an agent?
One question, one answerNo — just call the model
Fixed, known sequence of stepsNo — write a normal pipeline
Several steps, order unknown ahead of timeYes
Needs to react to live results and adaptYes
Needs real-world actions (search, code, APIs)Usually yes

If you can write the steps down in advance, write them down — it'll be cheaper and more reliable than handing control to a model. Reach for an agent when the path to the goal genuinely can't be known until you're partway through it.

The cost of autonomy

Giving a model freedom is exactly what makes agents useful and exactly what makes them hard. The same loop that lets an agent recover from a dead end also lets it:

  • spin in circles, repeating the same failing action;
  • wander off-goal and burn tokens (and money) doing it;
  • take a damaging real-world action confidently and incorrectly.

Almost all of agent engineering is constraining this freedom: limiting steps, validating tool calls, and giving the model just enough context to decide well and no more. Keep that tension in mind — it's the thread running through every chapter ahead.

Recap

  • An AI agent is an LLM wrapped in a loop that lets it act in the world, not just produce text.
  • Every agent runs the same cycle: perceive, think, act, observe — and repeat until done.
  • A system is agentic when the model decides the control flow, rather than your code.
  • Use an agent for multi-step, open-ended tasks whose path isn't known in advance — not for things a single prompt can handle.
  • Autonomy is a trade-off: flexibility on one side, reliability and cost on the other.

We've defined the loop. The hardest part of that loop is the "think" step — how does an agent break a fuzzy goal into a sequence of doable actions? That's planning. Continue to How AI Agents Plan.

What Is an AI Agent? From Chatbot to Autonomous Worker | Code Safari