What Is an AI Agent? How AI Agents Work, With a Real Recorded Run
What is an AI agent?
An AI agent is a program in which a language model chooses the next step. Your code gives the model a goal and a set of tools, such as search or reading a server's status. The model asks for one tool, your code runs it and returns the result, and the model decides again, in a loop, until it can answer or a limit your code sets stops it. Use an agent when the next step depends on what was just found; when the steps are known in advance, a fixed workflow is cheaper and more reliable.
Answer last checked
Save your progress and get the AI Engineering cheat sheet PDF
This guide answers 10 questions about AI agents: what an agent is, how it works in plain words, who runs the tools, how an agent differs from a workflow, what a real agent run looks like, how it knows when to stop, what the architecture is and why long agent tasks fail. The facts come from our Hands-On AIOps on AWS course and the agents chapter of our AI Engineering course, with outside sources linked under each answer.
10 questions · 3 sections · answers from the course
These answers come from our course Agentic AI Engineering with LangChain, LangGraph and LangSmith: Build Real Agents, Hands-On: 38 video lessons are out now (Modules 0 to 4), about 692 minutes, of the 219 planned. Module 0 is free to watch with no sign-in.


The short version
An agent is a model calling tools in a loop until the task is done. The model only asks; your code runs the tools, keeps the history and enforces the limits, and that code is called the harness. Prefer a workflow when the steps are known, keep agent paths short because success multiplies down per step, give each request only the tools it needs, and put a person in front of anything risky.
1. What an AI agent is
The word agent is used for almost everything with a language model in it. These answers give the precise meaning engineers use, and the parts every agent has.
What is an AI agent?
An AI agent is a program in which a language model chooses the next step. Your code gives the model a goal and a list of tools, which are functions it may ask to run, such as searching documents or reading a server's status. The model asks for one tool, your code runs it and sends back the result, and the model decides again, until it can answer or a limit stops it.
LangChain's documentation puts it in one sentence: an agent is a model calling tools in a loop until a given task is complete.
Source: LangChain docs, Agents
Lesson: What an agent is, on a real broken shop (Hands-On AIOps on AWS)
How does an AI agent work, in plain words?
Think of a new trainee asked to find out why the website is down, with a phone list of the database team, the network team and the person who deployed last night. She calls one person, listens, decides whom to call next, and keeps going until she can answer. If she is still stuck after a long time, her manager steps in.
In an agent, the trainee is the model, the phones are the tools, calling and deciding again is the loop, and the manager stepping in is the stop rule your code enforces, such as a maximum number of model calls.
Lesson: What an agent is, on a real broken shop (Hands-On AIOps on AWS)
Does the model run the tools itself?
No. A language model can only read text and write text. When it wants a tool, it writes a short structured request naming the tool and its arguments; in our recorded run, the model's first reply was 18 tokens long and was exactly such a request, not an answer.
Your code reads the request, runs the real function, adds the result to the conversation and calls the model again. Everything around the model, the prompt, the tools, the loop and the limits, is called the harness, so an agent is the model plus the harness.
What is the difference between an AI agent and a workflow?
Who picks the next step. In a workflow, your code fixes the steps and their order in advance, and a model may be called inside some of them. In an agent, the model picks the next step from what it has just found. Anthropic draws the same line in its guide to building effective agents, and advises starting with the simplest thing that works.
One question decides it: does the next step depend on what you just found? If the steps are known before the run starts, write a workflow; it is cheaper, faster and does the same thing every time. Use an agent only where only the model can tell what comes next.
Source: Anthropic, Building effective agents
Lesson: Deterministic scaffolding: where code decides and the model does not
2. A worked example: an agent finds why a shop is down
In our Hands-On AIOps on AWS course we break a small online shop on purpose and give the alert to an agent. This is what it did, from the recorded runs.
What does a real AI agent run look like?
Our shop runs on Kubernetes. We told its web server to use an image version that does not exist, so the web pod showed ImagePullBackOff and the web page went down. The agent got the alert and four read-only tools. In about 9 seconds it listed the pods, read the web server's change history, read the Kubernetes events and read the web server's settings, then answered that the latest change asks for a missing image and the fix is to roll back to the version before it. The answer was right.
No line of code set that order. We broke the shop the same way five times: the agent used the same four tools in three different orders, and every run proposed the same correct fix. That is what an agent buys you, and also what it costs: the path is not fixed, so you test the outcome, not the steps.
What we measured: Recorded runs in our course: 4 tool calls in about 9 seconds; the same break five times gave 3 different tool orders and the same correct fix every time.
Lesson: What an agent is, on a real broken shop (Hands-On AIOps on AWS)
How does an AI agent know when to stop?
Two ways, and a good harness has both. The normal way is that the model writes an answer instead of another tool request, and the loop ends. The safety way is a limit your code enforces whatever the model wants: a maximum number of model calls, tool calls, tokens or seconds.
The full on-call agent in our course allows at most 14 model calls and 24 tool calls for one incident. Without such a limit, a confused agent can loop for a long time and run up a bill.
Lesson: What an agent is, on a real broken shop (Hands-On AIOps on AWS)
3. AI agent architecture and what makes agents fail
Every agent architecture is the same loop with different choices around it: how it plans, which tools it sees, what it remembers and where a person must approve. The failures are mostly about length and tools.

What is the architecture of an AI agent?
Five parts. The model, which decides. The tools, functions with a name, a description and typed arguments. The loop, code that runs the requested tool and calls the model again. Memory, the conversation so far plus anything saved between runs. And the guardrails: limits, permission checks, and a human approval step before anything risky such as a deployment or a payment.
Planning styles sit on top. ReAct thinks and acts one step at a time, which adapts well but calls the strongest model at every step. Plan-and-execute writes the whole plan once and lets cheaper steps carry it out, which costs less but breaks when an early step finds a surprise.
Why do AI agents fail more often on long tasks?
Because reliability multiplies. A task succeeds only if every step does. If each step works 95% of the time, a 5-step task works about 77% of the time and a 20-step task about 36%. A demo with three happy steps hides this; real work with twenty steps shows it.
The fixes are to shorten the path, to put checks between stages so a wrong step is caught early, to retry only the errors that are safe to retry, and to move every step that does not need judgement out of the model and into plain code.
What we measured: Whole-task success = per-step success to the power of the step count: 0.95 over 5 steps is about 77%, over 20 steps about 36%; 0.99 over 20 steps about 82%.
How many tools should an AI agent have?
As few as each request needs. In our lab, two small models got 60 requests with 5 to 100 tools. Choosing the right tool held up surprisingly well, 55 and 56 of 60 right even at 100 tools, but every tool is described in the prompt on every call, so the prompt grew from 428 to 5,862 tokens and the median reply went from 2.7 to 35.5 seconds.
The same lab found the bigger problems elsewhere: right choices written as broken JSON, and valid tool calls that a local chat API silently dropped. So validate every tool request before running it, and show each request only the tools it needs.
What we measured: 60 requests, 5 to 100 tools: 55 and 56 of 60 right at 100 tools; prompt 428 to 5,862 tokens; median reply 2.7 to 35.5 seconds.
Do you need several agents working together?
Usually not at first. Several agents add hand-offs, waiting, duplicated work and errors passed from one to the next, and each fills its own context window with tokens. Anthropic reported that its multi-agent research system used about 15 times the tokens of a normal chat.
Start with one agent and good tools. Split into several only when a task truly divides into independent parts that can run in parallel, and when you can check each part's result.
Where to go next
Everything on this page comes from Agentic AI Engineering with LangChain, LangGraph and LangSmith: Build Real Agents, Hands-On. 38 video lessons are out now (Modules 0 to 4), about 692 minutes, of the 219 planned. Module 0 is free to watch with no sign-in. Start with the free lessons before you decide.
These questions are a start. The interview asks more.
Get all 120 questions in the Agentic AI Engineering pack
Each question has why it is asked, a full answer, what the interviewer listens for, the follow-ups, the common mistakes and a diagram (153 diagrams in all). A PDF you keep, junior to staff level.
Pay by UPI, cards or netbanking through Razorpay. Pay by card or PayPal, in US dollars. Download at once from My packs.
