What is an AI agent?
An AI agent is a system that pursues a goal by repeatedly deciding what to do next, taking an action in the world, and using the result of that action to inform its next decision.
Three parts make it an agent rather than a text generator:
- A goal rather than a single question.
- Tools — functions it can call that do something outside the model: search, read a file, hit an API, run code.
- A loop with a stop condition — it keeps going until the goal is met, an error stops it, or a limit is reached.
Remove the loop and you have a model that calls a function once. Remove the tools and you have a model that thinks out loud. Both are useful; neither is an agent.
What is a chatbot, precisely?
A chatbot is a conversational interface that maps an input to a response, one turn at a time, without taking actions in external systems.
The lineage runs back to ELIZA in the 1960s, which matched patterns in typed input and reflected them back as questions. Modern chatbots are enormously better at the language part — an LLM-powered support bot understands phrasing that would have defeated a rule-based system entirely — but the shape is unchanged. Input arrives, a response is produced, the turn ends.
That is not an insult to chatbots. For a large share of real problems, the turn-based shape is the correct design: it is predictable, cheap, easy to test, and cannot take a destructive action because it cannot take any action at all. A support bot that answers refund-policy questions should not be an agent.
AI agents vs chatbots: the comparison
The differences follow from one architectural choice: whether the system can act and observe.
| Chatbot | AI agent | |
|---|---|---|
| Control flow | One turn, input to output | Loop until goal or limit |
| External actions | None | Calls tools and APIs |
| Uses its own results | No | Yes, each observation feeds the next step |
| Failure mode | Wrong answer | Wrong action, or an endless loop |
| Cost per request | Predictable | Variable, depends on steps taken |
| Testing | Compare output to expected | Must test the whole trajectory |
The last two rows are the ones vendor comparisons skip, and they are the ones that matter in production. A chatbot's worst case is an unhelpful reply. An agent's worst case is thirty tool calls, a large bill, and a change to a system you did not want changed.
One honest note about definitions on this topic: every company selling an agent platform draws the line where its own product sits, so "agent" gets applied to anything from a scripted flow to an autonomous coding tool. One 2026 industry analysis observed that most tools marketed as agents are still retrieval systems with an LLM in front. When you meet the word, ask a mechanical question rather than accepting the label: does it loop, and can it act?
How does an agent actually work? The ReAct loop
Most production agents use a pattern called ReAct, short for Reasoning and Acting, introduced in a 2022 paper by Yao et al. The idea is to interleave thinking and doing rather than planning everything upfront.
Each pass through the loop produces three things:
- Thought — what the model believes it should do next, and why.
- Action — a specific tool call with specific arguments.
- Observation — whatever the tool returned, including an error.
The observation is appended to the context and the loop runs again. The model now knows something it did not know before, so its next thought is better informed. This continues until the model produces a final answer instead of an action, or the step limit is hit.
Why interleave instead of planning first? Because a model planning all steps upfront has to guess what each step will return, and guesses compound into confidently wrong answers. Acting first and observing replaces a guess with a fact at every step.
A worked example. Ask: "I bet a friend 100 EUR that it would rain in Athens today. If I won, how much is that in INR?" A chatbot cannot answer this — it does not know today's weather. An agent runs:
- Thought: I need the Athens weather before I can tell whether the bet was won. Action:
get_weather("Athens"). Observation:rain. - Thought: It rained, so the bet was won. Convert. Action:
convert_currency(100, "EUR", "INR"). Observation:9500.0. - Thought: I have everything. Answer: It rained, so you won ₹9,500.
Step 2 could not be planned in advance, because whether to convert at all depended on what step 1 returned. That dependency is the whole reason the loop exists.
What is tool calling?
Tool calling is the mechanism that lets a language model trigger code. Instead of returning prose, the model returns a structured decision: which function to call, and with which arguments.
The critical detail, and the one most explanations skip: the model does not execute anything. It emits a request. Your code decides whether to honour it, runs the function, and passes the result back. That boundary is where every safety control lives — permission checks, confirmation prompts, rate limits, logging.
So the sequence is: model proposes, your code disposes, result returns to the model. An agent is that exchange, repeated.
Build a working agent in under 100 lines
Here is the loop with nothing hidden. This code has been run and its output verified, including the error path and the step limit. There is no framework and no API key required — the "model" is a scripted stub, so you can read every branch and see exactly where a real LLM would go.
The tools. Ordinary functions. Nothing special makes them tools except that the agent is allowed to call them.
python
def get_weather(city: str) -> str:
fake_data = {"athens": "rain", "delhi": "clear", "mumbai": "rain"}
return fake_data.get(city.lower(), "unknown")
def convert_currency(amount: float, source: str, target: str) -> float:
rates = {("EUR", "INR"): 95.0, ("USD", "INR"): 88.0, ("EUR", "USD"): 1.08}
rate = rates.get((source.upper(), target.upper()))
if rate is None:
raise ValueError(f"no rate for {source}->{target}")
return round(amount * rate, 2)
TOOLS = {"get_weather": get_weather, "convert_currency": convert_currency}
The loop. This is the entire idea, in about twenty-five lines.
python
def run_agent(task: str, model, tools: dict, max_steps: int = 5) -> str:
"""Reason -> Act -> Observe, repeated until the model returns an answer."""
observations = []
for step in range(1, max_steps + 1):
decision = model.decide(task, observations)
print(f"[step {step}] thought: {decision['thought']}")
# Stop condition: the model chose to answer instead of act.
if "answer" in decision:
return decision["answer"]
call = decision["action"]
print(f"[step {step}] action: {call['tool']}({call['args']})")
# Errors become observations, not crashes - this is what lets
# the agent recover instead of dying.
try:
result = tools[call["tool"]](**call["args"])
except Exception as exc:
result = f"ERROR: {exc}"
print(f"[step {step}] observation: {result}\n")
observations.append({"call": call, "result": result})
# Guardrail: never loop forever.
return "Stopped: hit the step limit without reaching an answer."
Read the three commented lines again, because they are the three decisions that define an agent. The stop condition determines when it ends. The try/except turns a failure into information the model can react to rather than a crash. The step limit is what stands between you and an infinite loop with a metered API behind it.
Running the full file produces this trace:
[step 1] thought: I need to know if it rained in Athens before I can
decide whether the bet was won.
[step 1] action: get_weather({'city': 'Athens'})
[step 1] observation: rain
[step 2] thought: It rained, so the bet was won. Convert 100 EUR to INR.
[step 2] action: convert_currency({'amount': 100, 'source': 'EUR', 'target': 'INR'})
[step 2] observation: 9500.0
[step 3] thought: I have everything I need.
final: It rained in Athens, so you won Rs 9500.0.
To make it real, replace the scripted decide() with an LLM API call that receives the task plus all prior observations and returns the same structure — a thought and either an action or an answer. Most model APIs support this natively through function or tool calling, which returns structured arguments rather than prose you would otherwise have to parse. The loop does not change at all. That is the point of building it this way: swapping the model is a one-class change, because the architecture was never in the model to begin with.
Is ChatGPT an agent or a chatbot?
It depends entirely on what it is doing in that moment, which is why the question causes so much confusion.
Asked to explain recursion, an LLM assistant behaves as a chatbot: one turn, no external action. Asked to research a topic across the web, or to edit files and run tests in a repository, the same product runs a loop with tools — searching, reading results, deciding what to search next. That is agent behaviour by any mechanical definition.
So "agent" describes an operating mode, not a product category. The useful question is never "is this an agent?" but "in this task, is it looping and acting?"
Where agents fail
Agents fail in ways chatbots structurally cannot, and these failure modes are absent from most introductions to the topic.
- Infinite loops. The agent retries the same failing action, observes the same error, and retries again, burning tokens and time. A step limit is the minimum defence.
- Goal drift. Over many steps, the agent's working objective quietly diverges from the one you gave it, especially when early observations are misleading.
- Cost explosion. Cost scales with steps, and steps are decided at runtime. A chatbot's per-request cost is predictable; an agent's is not.
- Hallucinated tool calls. The model requests a tool that does not exist or passes malformed arguments. Validate before executing — never dispatch straight from model output.
- Context overflow. Every observation is appended, so long trajectories eventually exceed the context window and older steps get truncated.
- A wider security surface. To act, an agent needs credentials — API keys, service accounts, tokens. Security analysts have flagged that this broad, continuous access is a materially different risk profile from a read-only chatbot.
One more limitation worth stating plainly: the reasoning trace is not proof of reasoning. The thought text explains what the model is doing in a way that is useful for debugging, but it is generated text and can be a plausible-sounding rationalisation of a wrong action. Debug with the observations and the actual tool calls, not with the prose.
What this means for your career
The skill that is becoming valuable is not prompting. It is designing and constraining loops.
Concretely, that means being able to define a tool interface cleanly, decide a stop condition, handle a failed call, cap cost, and evaluate whether the whole trajectory achieved the goal — not just whether the final message reads well. Testing an agent means testing a trajectory, which is a genuinely harder problem than testing a function, and one very few people are good at yet.
A practical suggestion: extend the code above rather than starting with a framework. Add a third tool. Make one of them fail deliberately and watch what the loop does. Then swap the scripted model for a real API call. You will understand more about agents from those three exercises than from any framework tutorial, because frameworks hide precisely the loop you need to see.
Common Mistakes
| Mistake | Why it happens | Fix |
|---|---|---|
| Calling a RAG pipeline an agent | Both feel "AI-powered" | Ask whether it loops and acts; retrieval alone is neither |
| Building without a step limit | The happy path works in testing | Cap steps before the first live API call |
| Executing tool calls straight from model output | It works in demos | Validate the tool name and arguments first |
| Trusting the reasoning trace | It reads convincingly | Debug from observations and actual calls |
| Starting with a framework | Tutorials all start there | Write the loop once by hand, then adopt a framework |
| Testing only the final answer | It is what the user sees | Evaluate the whole trajectory |
| Using an agent where a chatbot fits | Agents sound more advanced | If the task is one turn with no action, do not add a loop |
Frequently Asked Questions
What is the main difference between an AI agent and a chatbot?
Control flow. A chatbot handles one turn: input in, response out, no external action. An AI agent runs a loop, calling tools, observing results, and deciding what to do next until the goal is met or a limit is reached. The same language model can power both, so the difference is architecture rather than model capability.
What is the ReAct loop?
ReAct, from Reasoning and Acting, is a pattern introduced by Yao et al. in 2022 where an agent alternates between reasoning and taking action. Each pass produces a thought about what to do next, an action such as a tool call, and an observation of the result, which then informs the next thought. It continues until the model answers instead of acting.
Is ChatGPT an AI agent?
It depends on the task. Answering a question in one turn is chatbot behaviour. Researching across the web or editing and running code in a repository involves looping with tools, which is agent behaviour. "Agent" describes an operating mode rather than a product category, so the useful test is whether the system is looping and acting in that particular task.
How do AI agents call tools?
The model does not execute anything itself. It returns a structured decision naming a function and its arguments, your code validates and runs that function, and the result is passed back to the model as an observation. That handoff boundary is where permission checks, confirmation prompts and logging belong.
Can I build an AI agent without a framework?
Yes, and it is the better way to learn. A working agent loop is roughly twenty-five lines: call the model for a decision, stop if it returns an answer, otherwise execute the requested tool, catch errors as observations, append the result, and cap the total steps. Frameworks add convenience later, but they hide the loop you most need to understand.
What is agentic AI?
Agentic AI is an umbrella term for systems that pursue goals through autonomous multi-step action rather than single-turn responses. The term is used loosely across the industry, often for products that mainly retrieve information, so treat it as marketing vocabulary and check the mechanism underneath before accepting the label.
Are AI agents better than chatbots?
Neither is better; they suit different problems. If the task is a single turn with no external action, a chatbot is cheaper, more predictable and easier to test. If the task requires steps whose order depends on intermediate results, an agent is the correct design. Agents also carry failure modes chatbots do not, including runaway loops and variable cost.
What skills do I need to build AI agents?
Solid programming fundamentals, comfort with APIs and structured data, error handling, and system design thinking around stop conditions and cost limits. Evaluation matters most and is least taught: an agent is judged on its whole trajectory, not just its final message, which is a harder testing problem than checking a single output.
Conclusion
Strip away the marketing and the distinction is small and precise. A chatbot answers. An agent loops: reason, act, observe, repeat, until a stop condition fires. Everything else — autonomy, memory, planning, tool use — follows from that one architectural choice.
Which means you can understand agents completely by writing about twenty-five lines of Python. Run the code above, add a tool, break one deliberately, and watch what the loop does with the error. That exercise will teach you more than any vendor comparison page, including the parts vendors have a reason not to mention.
Join Hello Engineers Free





