Explainer
What is an AI agent? A plain explanation
An AI agent is a language model that uses tools in a loop until a task is done. What that means in practice, what agents are good at and where they go wrong.
Bookmark
Bookmarks are kept in your free account, so you can find this page again on any device.
Sign in to bookmarkOn this page
“Agent” is used to mean almost anything with AI in it, which makes it hard to discuss. A working definition that most engineers would accept: an AI agent is a language model that uses tools in a loop, deciding its own next step, until a task is done or something stops it.
Each part of that sentence matters, so let us take them one at a time.
The parts of an agent
A model. The language model does the reasoning: it reads the task and the results so far and decides what to do next. It can only produce text (and structured requests for tool calls). On its own it cannot read a file, open a web page or run a test.
Tools. Functions the surrounding program makes available: read a file, search the codebase, run a shell command, query a database, send an email. The model sees a name, a description and the expected inputs for each tool, and can ask for one to be called. The program runs it and returns the result.
A loop. After each tool result, the model is called again with everything so far. It might call another tool, or decide it has enough to answer. This repetition is what lets an agent work through a task whose steps were not written down in advance.
A stop condition. The loop ends when the model gives a final answer, when it hits a limit (a maximum number of steps, a time or cost budget), or when a human interrupts. Without a limit, a confused agent keeps going.
task ─► model ─► wants a tool? ── yes ─► run tool ─► result ─┐
▲ │
└─────────────────────────────────────────────────┘
no ─► final answer
That is all an agent is mechanically. Claude Code, Codex, Cursor’s agent, customer-service bots that can look up orders, and research assistants that browse the web all follow this loop. They differ in their tools, their instructions, how they manage context and what they are allowed to do without asking.
One run, step by step
Here is what that loop looks like in a coding agent asked to fix a failing test. This is an illustrative trace, shortened, of the kind most agents let you inspect:
user: "test_invoice_total fails, fix it"
model: call run_tests(path="tests/test_invoice.py")
tool: 1 failed: expected 107.50, got 107.5000001
model: call read_file(path="billing/invoice.py")
tool: (82 lines) ... total = sum(line.price * line.qty for line in lines) * 1.075 ...
model: call search(text="Decimal", path="billing/")
tool: billing/tax.py:3: from decimal import Decimal, ROUND_HALF_UP
model: call edit_file(path="billing/invoice.py", change="use Decimal and round to 2 places, as tax.py does")
tool: ok
model: call run_tests(path="tests/")
tool: 48 passed
model: "Fixed: invoice totals now use Decimal with 2-place rounding, matching tax.py. All 48 tests pass."
Four things to notice. The model never touched a file itself; it asked for tools and the program ran them. Each step depended on the result before it: nobody wrote “search for Decimal” in advance. The agent checked its own work by running the whole suite, not only the failing test. And the final message is a claim. The tests are the evidence, which is why a reviewer reads the diff and the test run, not just the summary.
When an agent goes wrong, the trace is where you find out why. Agent observability covers what to record for each run.
What makes it an agent rather than a chatbot
The defining feature is that the model chooses the path. A chatbot answers. A fixed pipeline (search, then summarise, then format) follows steps a programmer wrote. An agent decides, step by step, which tool to use next based on what it has found. Anthropic’s widely cited distinction puts it the same way: workflows are “orchestrated through predefined code paths”, while agents “dynamically direct their own processes and tool usage” (Anthropic, December 2024).
That is both the value and the risk. Agents can handle tasks where you cannot predict the steps: “find out why this test fails and fix it” might take three steps or thirty. They can also take steps you did not expect, repeat themselves, or go confidently in the wrong direction.
Where agents work well
Agents earn their cost when three things are true:
- The path depends on what you find. Debugging, research, codebase changes and investigations fit. Filling in a form does not.
- There is a way to check progress. Tests that pass or fail, a compiler, a search result that does or does not contain the answer. Coding agents are effective partly because code gives fast, objective feedback.
- Mistakes are recoverable. Changes in a Git branch can be reviewed and discarded. An email sent to a customer cannot.
Coding is the clearest success so far, for exactly these reasons. Agents that act in the outside world with irreversible effects need much more care.
Where they go wrong
Wandering. Without a clear goal and a way to check it, agents explore, re-read and try variations until they hit the limit. Clear tasks and sensible step limits help.
Compounding errors. A wrong assumption in step two shapes everything after it. Asking for a plan first, and reviewing it, catches many of these early.
Context overload. Long runs accumulate tool results until important details get lost. Good agents trim results, summarise history and hand big sub-tasks to sub-agents with their own context.
Untrusted input. An agent that reads web pages, emails or issues can be steered by instructions hidden in them. This is prompt injection, and it is the main security concern with agents that have real tools.
Over-claiming. Agents report success. “All tests pass” needs checking.
Agents, sub-agents and multi-agent systems
A sub-agent is an agent started by another agent to handle part of a task in its own context: “search the codebase for every call to the payments API and report back”. The parent only sees the summary, which keeps its own context clean. Claude Code and other coding agents use sub-agents this way.
Multi-agent systems coordinate several agents with different roles, for example a planner, workers and a reviewer. They can parallelise work and specialise prompts, at the cost of more tokens and harder debugging. Start with one agent and add more only when you can show it helps.
Should you build one?
Often the right answer is a simpler system: one model call, or a fixed sequence of calls with code in between. These are cheaper, faster and easier to test. Reach for an agent when the steps genuinely cannot be known in advance. A quick test:
| Question | If yes | If no |
|---|---|---|
| Can you write the steps down before you start? | A workflow: fixed steps, with a model call where judgement is needed | An agent may be worth it |
| Is there a check the system can run to see if it is done (tests, a validator, a lookup)? | An agent can correct itself | Expect to review everything it produces |
| Can a wrong step be undone? | Let it act, within limits | Keep a person approving each action |
| Will it run often enough to justify building evals for it? | Build it and measure it | A person with a chat assistant may be cheaper |
Our article Workflows vs agents goes into that decision in more depth.
The harness matters as much as the model
The same model can be a careful agent or a reckless one depending on what surrounds it: the instructions it reads, the tools it has, the tests that tell it when it is wrong, and the rules about what it may do without asking. That surrounding software is the agent harness, and OpenAI’s February 2026 report on building a product with Codex is mostly about it. Harness engineering explains how teams design it for coding agents, and Claude Code auto mode shows one product’s answer to the question of which actions an agent may take on its own.
If you want to see the loop working, the Python and TypeScript tutorials each build a small agent with three tools, a step limit and logging in under an hour.
Next steps
- Choose a framework with agent frameworks compared.
- See how agents get their tools in what is MCP? The Model Context Protocol explained.
- Measure whether an agent works with evaluate AI agents.
- Learn it in order with the agents and MCP learning path.
- See what an always-on personal agent can reach, and how to try one safely, in What is OpenClaw?
Covers
Related
- Build your first agent in Python
Three tools, a hard turn limit, a clear stop condition and a log of every tool call it makes.
- Build your first agent in TypeScript
Tools that search and read notes, a step limit, a clear stop condition and logged steps.
- Workflows vs agents: start with the simplest thing that works
Most LLM features should be a fixed workflow, not an agent. How to tell which one you need, when an agent earns its cost, and the useful patterns in between.
- Agent
A system where a model decides which actions or tools to use, in a loop, until a goal or stop condition is met, rather than following fixed steps.
- Agent frameworks compared: Claude Agent SDK, OpenAI Agents SDK, LangGraph, Pydantic AI, Mastra, Google ADK
Six agent frameworks on one fixed table: language, durable execution, tracing, MCP support and lock-in, with notes on which kind of project each one fits.