SpunkArt
Long reads and site policies

What an AI agent is, and where it goes wrong

An AI agent is a language model that can take actions, look at the results, and decide what to do next. The idea is simple. The engineering and the safety questions are not. This guide explains the three parts, then the limits.

The three parts

Almost every agent system, whatever it is called, combines the same three pieces.

1. The model

A large language model reads text and predicts useful text in reply. On its own it cannot open a file, search the web or send an email. It only produces words. In an agent, the model’s job is to reason about the goal and to choose the next action.

2. The tools

A tool is a function that the surrounding program lets the model call. Each tool has a name, a description and a list of inputs. Examples: “read a file at this path”, “run this search query”, “add an event to a calendar”. The model writes a structured request such as {"tool": "read_file", "path": "notes.txt"}. The program, not the model, actually runs it.

3. The loop

The loop is what turns a chatbot into an agent:

  1. Give the model the goal, the tool list and everything that has happened so far.
  2. The model either answers, or asks for a tool call.
  3. The program runs the tool and adds the result to the conversation.
  4. Go back to step 1 until the model says it is finished, or a limit is reached.

That is the whole mechanism. Sophisticated agents add planning steps, memory files, sub-agents and checks, but the core is still observe, decide, act, repeat.

A small worked example

Goal: “Find which of my three project folders has no README and draft one.”

  • Turn 1: the model calls list_dir on each folder.
  • Turn 2: it sees that one folder has no README file and calls read_file on its main source file.
  • Turn 3: it writes a draft README and calls write_file.
  • Turn 4: it reports what it did and stops.

Four model calls, five tool calls. Each step depended on the result of the one before. A single prompt could not have done this, because the model did not know the folder contents in advance.

Where agents go wrong

FailureWhat it looks likeTypical guard
Confident errorThe model misreads a tool result and builds on the mistake.Ask it to verify key facts with a second tool call; review the output.
LoopingIt repeats the same failed action.A hard cap on steps and on cost.
Scope creepIt “helpfully” changes things nobody asked for.Narrow instructions and narrow tools.
Prompt injectionText inside a web page or file tells the agent to do something else.Treat tool output as data; require approval for risky actions.
Lost contextLong tasks overflow the model’s context window and early details drop out.Write progress to a notes file the agent can reread.

Safety: give the smallest power that works

An agent can do anything its tools can do. Design the tools first and the prompt second.

  • Read before write. Start with read-only tools. Add write tools only when needed.
  • Ask before irreversible actions. Deleting files, sending messages, spending money and publishing should need a human click.
  • Separate credentials. Give the agent its own limited account or token, never your main one.
  • Log everything. Keep a record of each tool call and its result so you can see what happened.
  • Run it in a sandbox when it executes code, so a mistake cannot reach the rest of your machine.

When an agent is the wrong choice

If the steps are always the same, write a normal script. It is cheaper, faster and predictable. Agents earn their cost when the next step genuinely depends on what the last step found: messy research, debugging, sorting through unfamiliar files. For a fixed pipeline, a model call at one step inside ordinary code is often the better design.

Questions

Is an agent the same as a chatbot?

No. A chatbot answers in text. An agent can also call tools and keep going over several steps without a human typing each instruction.

Does the agent “understand” the task?

It produces useful next steps from patterns in its training and the context you give it. It can still be wrong in fluent, convincing language, so check its work the way you would check a new colleague’s.

How many steps can an agent handle?

It depends on the model, the tools and the task. Long tasks are more reliable when they are split into smaller checked stages.