What Is an Agent?
Model + tools + loop. The definition that actually matters.
An agent is a system that uses a language model to decide what to do next, takes an action, observes the result, and repeats.
The minimal formula
Agent = Model + Tools + Loop
- Model β reasons and plans.
- Tools β let it act (edit files, run commands, search).
- Loop β keeps it going until the goal is met.
Chat vs agent
A chatbot gives you one answer. An agent:
- Reads the request.
- Decides the first action.
- Executes it.
- Looks at the result.
- Decides the next action.
- Repeats until done β or until it runs out of steps or money.
That's why an agent can do a multi-step task (rename a function across 40 files, run tests, fix the fallout) while a chatbot can only describe how to do it.
The loop in code
A minimal agent loop is surprisingly small:
async function agentLoop(goal, tools, maxSteps = 10) {
const history = [{ role: 'user', content: goal }];
for (let i = 0; i < maxSteps; i++) {
const reply = await model(history, tools); // model decides
if (reply.done) return reply.answer; // finished?
const result = await runTool(reply.toolCall); // act
history.push(reply.message, result); // observe
}
return 'Stopped after ' + maxSteps + ' steps.';
}
That's the whole magic: decide β act β observe β repeat.
Why limits matter
Without a maxSteps cap and a budget, an agent loops forever. Real agents add:
- A step/budget limit.
- A "done" signal.
- Permission checks before risky actions.
If you remember one idea from this course: an agent is a loop, and the loop is where all the interesting engineering happens.