First, retire the marketing
"AI agent" has been stretched until it means almost anything. Strip the buzz and the definition is precise: an agent is a program that uses a model to make decisions in a loop, acting on its environment, observing the result, and repeating — until a goal is met or it gives up.
A chat completion is not an agent. It is one inference. An agent is the loop around the inference.
The agentic loop
Every agent, from a simple web search tool to a multi-day engineering workforce, runs the same cycle:
- Perceive — gather state from the environment (tool results, files, logs).
- Decide — ask the model what to do next, given the goal and current state.
- Act — execute the chosen action through a tool.
- Observe — capture the outcome and feed it back in.
async function runAgent<T>(goal: string, execute: (action: AgentAction) => Promise<Observation>) {
const messages: Message[] = [{ role: "system", content: systemPrompt(goal) }];
for (let step = 0; step < MAX_STEPS; step++) {
const decision = await model.complete(messages); // decide
if (decision.finished) return finalize(decision); // goal met
const observation = await execute(decision.action); // act + observe
messages.push(decision.message, observation.message); // perceive next
}
throw new Error("step limit exceeded");
}
The whole field is, in one form or another, an optimization of this loop: better perception, better decisions, safer actions.
The three capabilities that make it work
An agent is not the model. It is the combination of three things:
- Tools — the agent's hands. Search, file IO, shell, HTTP, databases. A model without tools can only produce text; an agent with tools produces change in the world.
- Memory — context that persists across turns. Short-term (the running conversation), long-term (a knowledge base, past runs), and episodic (records of what worked before). Without memory, every turn starts from zero.
- A planning layer — the ability to break a goal into steps. Simple agents plan implicitly inside the model's reasoning. Reliable agents plan explicitly, with checkpoints a human can inspect.
An agent is only as trustworthy as the sandbox it runs in. Capability without containment is just a faster way to break things.
Where they actually add value
The agents that earn their keep share a profile:
- The task has a clear success condition that can be checked.
- The environment is observable — actions produce results you can read.
- Failure is recoverable — a bad step can be rolled back or retried.
- The cost of iteration is acceptable.
Code generation, test writing, data cleanup, document analysis, and researcher-style information gathering all fit. Open-ended creative work and any task where a mistake is expensive and irreversible do not — yet.
Design principles for a reliable agent
From building them in anger, these are the rules that hold up:
- Constrain the loop. A step limit, a time budget, and an explicit stop condition. An agent that cannot conclude is not smart, it is stuck.
- Make tools small and typed. Each tool is a function with a schema. Validation on input, structured output. A tool that can return anything is a hallucination waiting to happen.
- Log the loop. Record every decision, action, and observation. The debug story of an agentic system is the trace, not the final answer.
- Human checkpoints on irreversible actions. Delete, pay, deploy, merge — gate them. Autonomy is a dial, and you control where it stops.
- Let it verify its own work. Give the agent a way to run tests against its output. Self-verification converts "probably right" into "checkable".
const toolSchema = {
name: "run_tests",
input: { type: "string", description: "test command" },
output: { type: "string", description: "test output" },
};
What to watch out for
The failure modes are consistent across every implementation:
- Confabulation of tool results. The model believes it called a tool it never did. Always execute tools deterministically and show the real output.
- Loops. The same action, the same failure, forever. Detect repeated (action, observation) pairs and force a strategy change.
- Context bloat. Every observation is tokens. Long agents run out of attention; summarization and retrieval are not optional at scale.
- Brittle evaluation. A demo that passed once teaches you nothing. Measure over a test set with pass/fail checks, and track regressions.
The honest summary
An AI agent is a decision loop wrapped around a model, amplified by tools and memory, and bounded by engineering. The models improve every quarter; the engineering — sandboxes, schemas, observability, checkpoints — is what separates a demo from a system people trust.
Build the loop small, make the tools honest, and gate the irreversible. The magic is real, but it lives in the plumbing, not the hype.