AI Agents
An AI agent uses a model together with tools, memory, and a control loop to decide on and take actions toward a goal across multiple steps — not just answer a single prompt.
Prerequisites
What Is an AI Agent?
A single call to a language model takes a prompt and returns a response — one request, one answer. An AI agent is different: it wraps a model in a loop that can take an action, observe the result, and decide on the next action, repeating until the task is done.
Key Idea
An agent is more than "an LLM with a prompt." It’s a model plus tools, some form of state or memory, and a control loop that decides what happens next based on what just happened.
The Agent Loop
Goal
Starting TaskWhat the agent is trying to accomplish.
Reason / Plan
Model ThinksThe model decides what to do next.
Action
Takes a StepResponds directly, or reaches for a tool.
Tool
External CallRuns and returns a result outside the model.
Observation
New ResultThe tool's output, fed back to the model.
Next Action
Loop ContinuesThe model decides whether to act again.
Result
Task DoneThe final answer once the goal is met.
Given a goal, the agent reasons about what to do, takes an action — often calling a tool — observes what came back, and decides whether it has enough to finish or needs to take another step. This is the same tool-calling pattern from earlier lessons, run in a loop with the model deciding when to stop rather than after a single exchange.
What an Agent Needs
- Tools
- The external capabilities the agent can call — search, a database, an API — the same tool-calling pattern used by a single request.
- State
- What the agent is tracking during a task: the goal, what it has tried so far, and what it has learned.
- Control Loop
- The logic that decides, after every observation, whether to take another action, ask for clarification, or stop.
- Stopping Conditions
- The rules that end the loop — the task is complete, a step limit is reached, or an error requires it to give up.
Why This Is Hard in Practice
A loop that keeps taking actions is powerful, but it also means mistakes can compound — an agent that misinterprets an early result can keep acting on that wrong assumption for several more steps before anyone notices. That is why real agent systems need explicit stopping conditions, error handling for failed tool calls, and observability into what the agent actually did at each step, not just its final answer.
Common Mistakes
Assuming an agent is just a clever prompt
The prompt matters, but the loop, tools, state, and stopping conditions are what actually make it an agent rather than a single request.
No stopping condition
Without a clear limit or success check, an agent can loop far longer than useful, burning time and cost without making progress.
No observability into intermediate steps
If you can only see the final answer, you can’t tell whether the agent reasoned well or got lucky — or debug it when it fails.
Giving an agent too much autonomy too early
Broad, unchecked permissions on real tools raise the cost of a mistake — start narrow and expand as reliability is proven.
Interview Question
What is an AI agent?
An AI agent is a system that wraps a language model in a loop: given a goal, it reasons about what to do, takes an action — usually calling a tool — observes the result, and decides whether to act again or stop. It's more than an LLM with a prompt, because it needs state to track progress, a control loop to decide the next step, and stopping conditions so it doesn't run indefinitely. The practical challenge is that mistakes can compound across steps, so reliable agents also need error handling and observability into what happened at each step, not just the final output.
What an interviewer may ask next
- How is an AI agent different from a single tool-calling request?
- What would you use as a stopping condition for an agent?
- What could go wrong if an agent has too much autonomy?
Explain It in 30 Seconds
An AI agent wraps a language model in a loop — reason, act, observe, repeat — rather than answering one prompt and stopping. It typically needs tools to act on, state to track progress, and stopping conditions so it knows when to finish. The tradeoff is that mistakes can compound across steps, so a reliable agent also needs error handling and visibility into what it actually did, not just its final answer.