An AI agent is a system that uses an AI model to decide which steps or tools to use in order to achieve a goal.
A normal chatbot mainly answers:
User message → LLM → response
An agent can continue working:
Goal → decide next step → use tool → observe result
→ decide again → stop when complete
Why are agents needed?
Some tasks cannot be completed with one model response.
Example goal:
Find my pending orders and cancel any order that has not shipped.
The system may need to:
- Identify the user.
- Fetch pending orders.
- Inspect each order's status.
- Ask for confirmation.
- Call the cancellation API.
- Report what happened.
The model alone does not know the live order data and cannot cancel anything. An agent combines the model with backend tools and a controlled execution loop.
Main parts of an agent
| Part | Responsibility |
| Goal | Defines what should be achieved |
| LLM | Chooses or proposes the next step |
| Tools | Read data or perform approved actions |
| Memory or state | Tracks useful information and completed steps |
| Agent loop | Repeats decisions and actions until completion |
| Guardrails | Limit what the agent may see and do |
The agent loop
flowchart LR
A["Receive goal"] --> B["Choose next action"]
B --> C["Call approved tool"]
C --> D["Observe result"]
D --> E{"Goal complete?"}
E -->|No| B
E -->|Yes| F["Return final result"]
A simplified loop:
while (!state.completed && state.steps < MAX_STEPS) {
const decision = await model.chooseNextAction({
goal,
state,
availableTools
});
const result = await executeAllowedTool(decision);
state = updateState(state, decision, result);
}
return state.finalAnswer;
Chatbot vs agent
| Chatbot | Agent |
| Mainly generates a response | Works toward a goal through multiple steps |
| Often one model call | May use several model and tool calls |
| Usually does not take actions | Can request approved actions |
| Lower cost and complexity | Higher cost and more failure points |
Does every AI feature need an agent?
No.
Use one model call for:
- summarizing text
- extracting fields
- translating
- classifying a ticket
- answering from provided context
Consider an agent when:
- the task requires multiple decisions
- the next step depends on a tool result
- the system must interact with external services
- the path cannot be fully known in advance
Important safety rules
- expose only narrow tools
- validate every tool argument
- check user permissions in backend code
- require confirmation for destructive actions
- limit steps, time, tokens, and cost
- log tool calls and outcomes
- stop safely when the goal cannot be completed
An agent is not just an LLM. It is LLM + tools + state + an execution loop + guardrails.