A product manager asks for "an AI agent that handles support." The team builds a chat window on top of an LLM and ships it. A week later someone asks why it cannot actually issue a refund. The answer is that they built a chatbot and the request needed an agent.
The words are used interchangeably in marketing, but the engineering is different. This article explains AI agents vs chatbots in practical terms: what each one does, how the control flow differs, where each fits, and what changes when software is allowed to take actions. It is written for developers and SaaS founders deciding what to build.
Direct answer
- A chatbot responds to messages. Its job ends when it produces text. It may use retrieval or a fixed script, but a human performs any resulting action.
- An AI agent pursues a goal. An LLM decides which tools to call, observes the results and repeats until the task is done or it stops.
- The technical difference is the loop: a chatbot is one model call per turn; an agent is a model inside a loop with tools and state.
- Agents can do more and fail in more ways. They cost more, are slower, and need permissions, limits and logging that a chatbot does not.
Table of contents
- Definitions that hold up in code
- How the control flow differs
- AI agents vs chatbots: comparison table
- The same task, built both ways
- When should you use a chatbot, and when an agent?
- Production considerations for agents
- Common mistakes
- Best practices
- Frequently asked questions
- Conclusion
- References
Definitions that hold up in code
The industry has not settled on a single definition, so here are working ones that are useful when you read code.
A chatbot is a conversational interface. Rule-based chatbots match intents and return scripted replies. LLM chatbots generate replies from a model, often with retrieved documents (RAG). In both cases the output is a message.
An AI agent is a system where a model chooses actions. Anthropic's engineering article Building effective agents draws a useful line: workflows are systems where LLMs and tools are orchestrated through predefined code paths, while agents are systems where the LLM dynamically directs its own process and tool usage. That distinction is also a good design filter, because many products that are called agents are really workflows, and that is often the better choice.
Notice that these are not two separate technologies. An agent usually has a chat interface. What makes it an agent is what sits behind that interface.
How the control flow differs
A chatbot turn is linear. An agent turn is a loop.
flowchart TD
subgraph Chatbot
U1[User message] --> M1[LLM call]
M1 --> R1[Text reply]
end
subgraph Agent
U2[User goal] --> M2[LLM decides next step]
M2 -->|tool call| T[Run tool]
T --> O[Observation]
O --> M2
M2 -->|done| R2[Final answer]
endIn the agent loop, the model sees the goal and the tool descriptions, picks a tool, your code executes it, the result goes back to the model, and the cycle continues. The loop ends when the model produces a final answer or when your code stops it (a step limit, a budget or a human approval gate). Control of the next step has moved from your code to the model, and that is the source of both the power and the risk.
AI agents vs chatbots: comparison table
| Criterion | Chatbot | AI agent |
|---|---|---|
| Primary output | A message | A completed task (plus a message) |
| Control flow | One model call per turn, fixed by your code | Model chooses steps inside a loop |
| Tools and actions | None, or read-only retrieval | Calls APIs, databases, code, other services |
| Memory and state | Conversation history | History plus task state, scratchpad, long-term memory |
| Latency | Typically one call | Several sequential calls; seconds to minutes |
| Cost per request | Low and predictable | Higher and variable with the number of steps |
| Failure modes | Wrong or vague answer | Wrong answer, wrong action, loops, runaway cost |
| Security surface | Prompt injection leaks text | Prompt injection can trigger actions |
| Testing | Check answers | Check answers, tool choices and side effects |
| Best fit | FAQs, guidance, drafting | Multi-step tasks with tools and clear success criteria |
These are general tendencies, not measurements. A well-built chatbot can be excellent and a careless agent can be both slower and worse.
The same task, built both ways
Take the request: "Where is order 1042, and can I get a refund?"
Chatbot version. Retrieve the refund policy, answer with the policy text, and tell the user to contact support. It cannot look up the order or act.
Agent version. The model calls get_order(1042), reads that it shipped 3 days ago, calls check_refund_eligibility(1042), and then either calls create_refund_request(1042) or explains why not.
Here is the shape of the difference in code. The first is a chatbot turn; the second is an agent loop. Both use the OpenAI Node SDK and the Responses API. The agent version is a simplified sketch (no error handling, no step budget on tool results), which the next article turns into something sturdier.
// chatbot.mjs: one call, text in, text out
import OpenAI from "openai";
const openai = new OpenAI();
const reply = await openai.responses.create({
model: process.env.OPENAI_MODEL,
instructions: "You are a support assistant. Explain our refund policy clearly.",
input: "Where is order 1042, and can I get a refund?",
});
console.log(reply.output_text); // cannot look up the order, only talks about it
// agent-sketch.mjs: model-in-a-loop with tools (simplified sketch, not production-ready)
import OpenAI from "openai";
const openai = new OpenAI();
const tools = [
{ type: "function", name: "get_order", description: "Fetch an order by id",
parameters: { type: "object", properties: { id: { type: "number" } }, required: ["id"], additionalProperties: false }, strict: true },
];
const impl = { get_order: async ({ id }) => ({ id, status: "shipped", shippedDaysAgo: 3 }) };
let input = [{ role: "user", content: "Where is order 1042, and can I get a refund?" }];
for (let step = 0; step < 5; step++) { // hard step limit
const res = await openai.responses.create({ model: process.env.OPENAI_MODEL, input, tools });
input = [...input, ...res.output];
const calls = res.output.filter((o) => o.type === "function_call");
if (calls.length === 0) { console.log(res.output_text); break; }
for (const c of calls) {
const result = await impl[c.name](JSON.parse(c.arguments));
input.push({ type: "function_call_output", call_id: c.call_id, output: JSON.stringify(result) });
}
}
Two details to note. The tool definition shape (type: "function", parameters as JSON Schema, strict: true) and the function_call / function_call_output items follow the OpenAI function calling guide. And the for loop with a fixed limit is the simplest guardrail you can add; without it, a confused model can loop until your budget does.
When should you use a chatbot, and when an agent?
Use a chatbot when the user needs information or guidance, the answer can be produced from a knowledge base, and an action, if any, is performed by a person. Support FAQs, documentation assistants and onboarding helpers fit here.
Use a workflow (fixed steps with LLM calls inside) when the process is known in advance: classify a ticket, extract fields, draft a reply, route it. It is cheaper, faster and easier to test than an agent.
Use an agent when the steps cannot be known in advance, the task needs several tools, and success can be checked. Researching a topic across sources, triaging a bug by reading logs and code, or reconciling records across systems are agent-shaped.
A good rule: start with the least autonomous design that solves the problem, and add autonomy only where the fixed version demonstrably fails. If you can draw the flowchart ahead of time, you probably want a workflow.
Production considerations for agents
- Permissions. Give each tool the narrowest scope. A tool that can refund up to a limit is safer than one that can run arbitrary SQL.
- Human approval. Require confirmation for irreversible or high-value actions such as payments, deletions and external emails.
- Prompt injection. Anything an agent reads (web pages, emails, tickets) can carry instructions. Treat tool output as untrusted data, and never let it expand the agent's permissions.
- Limits. Cap steps, tokens, tool calls and wall-clock time. Return a clear failure instead of looping.
- Observability. Log every model call, tool call, arguments and result with a trace id. Our observability chapter covers the tooling.
- Idempotency. Agents retry. Make write tools idempotent so a repeated call does not double-refund. See idempotency in API design.
- Evaluation. Test with scenarios that check the final outcome and the tool trajectory, not only the final text.
Common mistakes
- Calling a chat window an agent. Without tools and a loop it is a chatbot, and that may be perfectly fine.
- Using an agent where a workflow would do. Extra autonomy adds latency, cost and variance for no benefit.
- Unbounded loops. No step limit means a single bad run can burn money.
- Over-broad tools. One "execute anything" tool turns every prompt injection into an incident.
- No human gate on irreversible actions. Approval for destructive steps is cheap insurance.
- Vague tool descriptions. The model chooses tools by reading their descriptions; unclear names and parameters produce wrong calls.
- Testing only the happy path. Test tool errors, empty results, rate limits and contradictory data.
Best practices
- Pick the simplest architecture that works: single call, then workflow, then agent.
- Write tool descriptions like API documentation: purpose, inputs, units, failure cases.
- Return structured, concise tool results; long raw dumps waste tokens and confuse the model.
- Keep a deterministic fallback, such as escalation to a human, when the agent is unsure.
- Track cost and latency per task from day one.
- Build the tool layer as ordinary, well-tested backend code. The model is replaceable; your APIs are not.
Conclusion
The difference in AI agents vs chatbots is control. A chatbot answers; an agent decides, acts and checks. That extra control is valuable for multi-step tasks and expensive everywhere else, so choose the least autonomous design that meets the goal and add limits before you add power.
A good next step is to implement the tool layer first: three or four small, well-documented, permission-scoped functions. Then read How to Build an AI Agent Using Node.js to wire them into a loop, or look at my AI integration services if you want help scoping one.
References
- Anthropic: Building effective agents
- OpenAI: Function calling guide
- OpenAI: Agents guide
- OWASP Top 10 for LLM Applications
Written by Shivam Thakur, a Software Engineer focused on web applications, SaaS platforms and modern software products. More at shivamthakur.me.

