What Is an AI Agent
Definition
An AI agent is an LLM that works in a loop: it looks at a goal, decides on the next action (usually a tool call), sees the result, and repeats until the goal is done. A normal chatbot answers once. An agent can take many steps on its own.
- Model: the LLM that decides what to do next.
- Tools: functions it can call (look up an order, search docs, send an email).
- Loop: your code runs the tools and sends the results back to the model.
- Memory / state: the conversation so far, plus any notes the agent saves.
- Stopping rule: the model says it is done, or a budget runs out.
Why Agents Exist
A single model call can only use what is already in the prompt. Many real tasks need two things the model does not have: fresh information (today's status of order SE1042 lives in your database, not in the model's training data) and the ability to act (book a pickup, issue a coupon). Tools give the model both. The loop lets it use them as many times as the task needs.
Think of a new support executive at a help desk. They read the ticket, open the order screen, read what it says, decide which screen to open next, and reply only when they have enough facts. The executive's judgement is the model. The screens are the tools. The desk rules ("refunds above ₹2,000 need a manager") are your code.
One point confuses many beginners: the model never runs anything itself. It only writes text that says "please call get_order with SE1042". Your program reads that request, decides whether to allow it, runs the real function, and sends the result back. All the power, and all the safety checks, sit in your code.
The Loop in One Picture
goal ──► model decides ──► tool call ──► your code runs the tool
▲ │
└────────── tool result ◄────────────────┘
(repeat until the model gives a final answer or a limit is hit)Chatbot vs RAG vs Agent
| Chatbot | RAG bot | Agent | |
|---|---|---|---|
| Steps per question | 1 model call | retrieve + 1 call | many calls, decided by the model |
| Uses tools | no | retrieval only (fixed) | yes, picks which and when |
| Can take actions | no | no | yes (create a return, book a slot) |
| Cost / latency | low | low to medium | higher and less predictable |
Example
Example
The smallest possible agent loop. fake_model is a stand-in for the model: it returns scripted decisions so you can see the loop without an API call.
def get_order(order_id):
return {"SE1042": "shipped, arriving Friday"}.get(order_id, "not found")
TOOLS = {"get_order": get_order}
# A stand-in for the model: decides the next step from what it has seen so far
def fake_model(history):
if not any(h[0] == "tool_result" for h in history):
return ("tool", "get_order", "SE1042")
return ("final", "Your order SE1042 has shipped and should arrive on Friday.")
history = [("user", "Where is my order SE1042?")]
for step in range(1, 6):
decision = fake_model(history)
if decision[0] == "final":
print(f"step {step}: final answer -> {decision[1]}")
break
_, name, arg = decision
result = TOOLS[name](arg)
print(f"step {step}: call {name}({arg!r}) -> {result!r}")
history.append(("tool_result", result))Output
step 1: call get_order('SE1042') -> 'shipped, arriving Friday'
step 2: final answer -> Your order SE1042 has shipped and should arrive on Friday.Step 1 is a tool request: the stand-in model has no order data, so it asks for it. Your loop runs get_order and adds the result to the history. In step 2 the model sees that result and writes the final answer. A real agent works the same way; only the decisions come from an LLM instead of an if.
Limits and Misconceptions
Note: An agent is not a special kind of model. It is an ordinary LLM plus a loop in your code. "Autonomous" does not mean unsupervised: you choose which tools exist, what they are allowed to do and when the loop stops. More steps means more chances to fail: if each step is right 95% of the time, a 10-step task succeeds only about 0.9510 ≈ 60% of the time. Keep agents short and tools reliable.
- Use an agent when the steps depend on the request and cannot be listed in advance.
- Do not use one when a single call, or a fixed sequence of calls, does the job.
Summary
- An agent = model + tools + a loop in your code + memory + a stopping rule.
- Tools bring fresh data and actions; the model only requests them, your code runs them.
- Agents cost more and are less predictable than one call, and errors add up over steps.
- Start simple and add agency only when the task needs it (see Workflows vs Agents).