Agent
A program that drives a language model in a loop: it reads a goal, takes actions with tools (read a file, run a command, edit code), observes the results, and keeps going until the task is done or it gives up. The difference from a chatbot is the loop and the tools; an agent changes things on your machine rather than only answering.
At a glance
- Core idea
- A model called in a loop with tools
- Inputs
- Goal, system prompt, tool definitions, history
- Actions
- Tool calls: read, run, edit, search
- Stops when
- Final answer, turn limit, or a person interrupts
- Memory
- Only what is in the current session
How it works
Under the hood an agent is a short loop around a model API call. The harness sends the model a system prompt, the conversation so far, and a list of tools it may call, each described by a name and a JSON schema. The model replies with either text or a request to call a tool. The harness runs that tool (read a file, run npm test, apply an edit), appends the result to the conversation, and calls the model again. The loop ends when the model replies without asking for a tool, hits a turn limit, or is stopped by a person.
Much of the behavior lives in the harness rather than the model: which tools exist, what needs approval, how long output is truncated, and what happens when the conversation gets too long. Two agents built on the same model can behave very differently because of those choices.
Why it matters
A chat assistant hands you a snippet and stops. An agent can write the snippet, run the type checker, read the error, and fix it before you look. That feedback from real tools is what lets it finish multi-file changes in a codebase it has never seen, and it is also why your tests and scripts set a ceiling on its work. If the test suite is flaky or slow, the agent's loop inherits that.
It also changes what your job is. Once the agent can verify its own work, your effort moves to defining the task precisely and reviewing the result, which is why running several agents at once becomes possible at all.
Agent vs. scripted workflow
A scripted workflow calls a model at fixed points in code you wrote, so the control flow belongs to you. In an agent the model decides the next step. A subagent sits in between: an agent started by another agent with a narrower task and a fresh context, whose summary goes back to the parent.
Example
{
"type": "tool_use",
"name": "run_command",
"input": { "command": "pnpm test src/lib/date.test.ts" }
}Common mistakes
- Steering every step like autocomplete instead of giving a clear goal and a command that proves it is done.
- Handing over a vague goal and walking away, then getting back a large diff that solves a different problem.
- Assuming the agent remembers earlier sessions when it only knows what it has read in this one.
Related terms
Frequently asked questions
Is an AI agent the same as a chatbot?
No. A chatbot answers in text and stops. An agent runs in a loop with tools, so it can read files, run commands and edit code until a task is done.
Does a coding agent remember previous sessions?
Not by itself. Each session starts empty apart from what the harness loads, which is why projects keep conventions in a committed instructions file the agent reads at startup.
What stops an agent loop?
The model returning a final answer with no tool request, a turn or budget limit set by the harness, or a person interrupting it.