
You type into a support chat: “Where is my order BD-1042, and can you move the delivery to Friday?” The bot answers with three friendly paragraphs about how delivery windows usually work. It never looks at your order. It cannot change anything. Ten minutes later you are on the phone with a human anyway.
Now picture the same request reaching a system that opens the order database, sees that the parcel is already out for delivery, tells you a reschedule is no longer possible, and offers to leave a note for the courier instead. The language model behind both experiences could be the same one. What differs is that the second system was allowed to act, look at what happened, and decide its next move. That gap between talking about a task and actually doing it is what people mean when they say AI agent.
What Is an AI Agent? The Short Answer
An AI agent is a software system that uses a language model to work toward a goal on its own: it decides what to do next, uses tools such as APIs, databases, code runners or a browser to act, checks the result, and repeats until the job is done or it needs a human. A chatbot answers once, while an agent keeps going until the goal is met. That loop, more than raw model intelligence, is what separates the two.

The Loop That Makes an Agent
Strip away the marketing and almost every agent is the same small loop. The model reads the goal and everything that has happened so far, then picks the next action. Your code runs that action and hands the result back as new information. The model looks at it and decides again.
flowchart TD
A[User gives a goal] --> B[Model decides the next step]
B --> C{Needs a tool?}
C -->|Yes| D[Run the tool]
D --> E[Send the result back to the model]
E --> B
C -->|No| F[Return the final answer]Flow summary: The user gives a goal and the model picks the next step. If a tool is needed, your code runs it and returns the result to the model, and this repeats until the model decides no tool is needed and returns the final answer.
Here is that loop as a runnable TypeScript file. It uses the Anthropic SDK and a fake in-memory order lookup, so an API key is the only thing you need to try it:
// agent/loop.ts
import Anthropic from '@anthropic-ai/sdk';
const client = new Anthropic();
const orders: Record<string, { status: string; eta: string }> = {
'BD-1042': { status: 'out for delivery', eta: 'today' },
'BD-1043': { status: 'processing', eta: '5 days' },
};
const tools: Anthropic.Tool[] = [
{
name: 'get_order_status',
description: 'Look up the status and delivery estimate of an order by its ID',
input_schema: {
type: 'object',
properties: { order_id: { type: 'string' } },
required: ['order_id'],
},
},
];
function runTool(name: string, input: { order_id: string }) {
if (name === 'get_order_status') {
return orders[input.order_id] ?? { error: 'order not found' };
}
return { error: 'unknown tool' };
}
async function runAgent(goal: string) {
const messages: Anthropic.MessageParam[] = [{ role: 'user', content: goal }];
for (let step = 0; step < 5; step++) {
const response = await client.messages.create({
model: 'claude-sonnet-5',
max_tokens: 1024,
tools,
messages,
});
messages.push({ role: 'assistant', content: response.content });
if (response.stop_reason !== 'tool_use') {
const block = response.content.find((b): b is Anthropic.TextBlock => b.type === 'text');
return block?.text ?? '';
}
const results: Anthropic.ToolResultBlockParam[] = response.content
.filter((b): b is Anthropic.ToolUseBlock => b.type === 'tool_use')
.map((b) => ({
type: 'tool_result',
tool_use_id: b.id,
content: JSON.stringify(runTool(b.name, b.input as { order_id: string })),
}));
messages.push({ role: 'user', content: results });
}
return 'Stopped: step limit reached';
}
runAgent('Where is my order BD-1042?').then(console.log);
Three parts of that file carry the whole idea. The tools array tells the model what it is allowed to do. The for loop keeps returning real results so the model can react to what actually happened. The cap of five steps stops a confused model from circling forever. Memory, retries, planning and everything else in a production agent grows out of this shape. Install the SDK with npm install @anthropic-ai/sdk, set ANTHROPIC_API_KEY, run npx tsx agent/loop.ts, then change the question to an order ID that does not exist to see how the model handles a tool error.
Why Everyone Is Talking About Agents Now
The idea itself is old; researchers have used the word agent for decades. What changed recently is that the pieces became dependable enough to ship.
Tool use got reliable. Early language models could describe an action but often fumbled the exact format needed to trigger it. Current models produce structured tool calls that code can execute, and they read error messages and try again. That single improvement moved agents out of demo territory.
Loops became affordable. One job can take five, ten or twenty model calls. When every call was slow and expensive, that arithmetic failed. Lower prices and faster models fixed it.
The plumbing became standard. Major model APIs all support function calling now, and open protocols such as MCP, which Anthropic introduced in late 2024, let one agent connect to many tools without custom glue for each.
People saw finished work. Coding agents that read a repository, edit files, run the tests and fix their own failures showed developers something new: not a suggestion to copy and paste, but a task that comes back done. After watching that happen on your own project, a plain chat window starts to feel slow. Companies noticed too. Nobody wants a paragraph about closing a ticket; they want the ticket closed.

Where Agents Already Do Real Work
The same loop shows up in very different jobs:
- Coding: reading a codebase, editing several files, running tests and iterating on failures.
- Support: looking up an order, checking the refund policy, replying, and handing over to a human when unsure.
- Research: searching several sources, comparing what they say, and drafting a summary with links.
- Operations: watching logs or dashboards, spotting an anomaly, and opening a ticket with the details attached.
None of this is magic. Each one is a model, a set of tools, a loop, and rules about what the tools may touch.
Agents Still Fail, and That Matters
Do not read the excitement as proof that the problem is solved. Agents pick the wrong tool, get stuck repeating themselves, and sometimes finish the wrong task with complete confidence. The topic is loud now because the failure rate fell far enough for real work, not because it reached zero. That is why the boring parts of agent building, such as limits, logging and human approval, matter at least as much as the prompt.
The Mistake I Made First
The first time I wired a language model into something that looked like a support assistant, I kept rewriting the system prompt. When I tested it with questions about delivery dates, it answered with total confidence, and the dates were made up. I blamed my wording. The real problem was simpler: the model had no way to look anything up, so it did what language models do and produced a plausible answer. One lookup tool fixed what no amount of prompt rewriting had.
Since then I watch for three mistakes, in my own code and in other people's:
- Calling everything an agent. A script that calls a model, then a function, then the model again in a fixed order is a workflow. That is often the better design, but it is not an agent, and the difference matters when you debug.
- Skipping the step limit. Without a cap, a confused model can keep looping and spend your API budget while you sleep.
- Granting write access too early. Let an agent read first. Add tools that change things, like sending email or issuing refunds, only after you trust its behavior, and start with a human approval step.
Where This Series Goes
This is the first post in a series where I build the ideas and the code up step by step, from how an agent is put together to running one in production. For now, keep one sentence: an agent is a model plus tools plus a loop, and almost everything else is detail added on top.
Frequently Asked Questions
Do I need machine learning knowledge to build an AI agent?
No. Most agents are built by calling a hosted model through an API and writing ordinary application code around it: tools, loops, error handling and storage. Comfort with APIs and a language like TypeScript or Python matters far more than knowing how to train a model.
Can an AI agent be trusted to act on its own?
Only within the limits you set for it. Start with read-only tools, cap the number of steps, log every action, and require human approval before anything that spends money, sends messages or deletes data. Widen its permissions only after you have watched it behave.
Will AI agents replace developers?
They are taking over repetitive, well-defined tasks, which changes what developers spend their time on. Someone still has to decide what an agent should do, design its tools, review its output and take responsibility when it is wrong. Today that someone is usually a developer.
Need a High-Performance Web App or Custom AI Solution?
I help founders, businesses, and engineering teams build lightning-fast web applications, resilient backend architectures, and intelligent AI workflows. Have an idea in mind? Let’s bring it to life.
Found this article helpful?
Give some claps to support more in-depth engineering logs!
Tags
Zahid Hasan Tonmoy
Author & Developer
MERN Full Stack Developer & AI Agent Developer based in Dhaka, Bangladesh. Writing about web development, React, PostgreSQL and my learning journey.