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:

  1. Identify the user.
  2. Fetch pending orders.
  3. Inspect each order's status.
  4. Ask for confirmation.
  5. Call the cancellation API.
  6. 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:

Consider an agent when:

Important safety rules

An agent is not just an LLM. It is LLM + tools + state + an execution loop + guardrails.