EXPLAINER

What are AI Agents?

An AI agent is a system in which a language model decides what to do next — calling tools, observing results and repeating — to pursue a goal with limited human direction.

Short answer: An AI agent is a model running in a loop with tools: it plans a step, acts (calls a tool), observes the result, and decides what to do next until the goal is met or it stops. More autonomy means more power and more risk.

What is it?

Definitions vary, but a useful working one is: an AI agent is a system where a language model is given a goal and a set of tools, and it chooses its own sequence of actions to achieve the goal, using the results of each action to decide the next.

A plain model call turns one input into one output. An agent wraps the model in a loop, which makes it capable of multi-step tasks such as "find the cause of this failing test, fix it and run the tests again."

Why does it matter?

Many valuable tasks are not answerable in one step: researching a topic across sources, triaging tickets, updating records in several systems, debugging code. Agents extend what a model can do, not just what it can say. They also change the risk profile: an agent can take actions with side effects, so reliability, permissions and oversight become central (AI Privacy and Security: What to Know Before You Paste Data, What is Prompt Injection?).

How does it work?

The core loop:

  1. Goal and context — the system prompt, the user's request, and relevant memory.
  2. Reason / plan — the model decides the next step.
  3. Act — it requests a tool call (Function Calling (Tool Calling) Explained); your code runs the tool (Agent Tools: How AI Agents Take Actions).
  4. Observe — the tool result is added to the context.
  5. Repeat or finish — the model either calls another tool or returns a final answer.
// Minimal agent loop (pseudo-code)
const messages = [system, { role: "user", content: goal }];
for (let step = 0; step < MAX_STEPS; step++) {
  const reply = await llm.chat(messages, { tools });
  messages.push(reply);
  if (!reply.toolCalls) return reply.text;          // done
  for (const call of reply.toolCalls) {
    const result = await runTool(call.name, call.args);   // validate + execute
    messages.push({ role: "tool", id: call.id, content: result });
  }
}
throw new Error("Step limit reached");

Notice the practical controls: a step limit, validated tool execution, and the growing message list, which consumes the context window.

Example

A coding agent is asked to fix a failing test. It lists files (tool), reads the test and source (tool), proposes an edit (tool), runs the test suite (tool), sees a new failure, adjusts, and re-runs until tests pass or it hits its step limit — then summarises what it changed. A human reviews the diff before merging. The review step is not optional decoration: it is how the system stays trustworthy.

When should I use it?

Use an agent when the path to the goal cannot be fixed in advance and the task benefits from adapting to intermediate results. If you can write the steps down in advance, a fixed workflow is usually cheaper, faster and more predictable. If you only need an answer, a single model call or a chat assistant is enough (AI Agent vs Chatbot vs Assistant: What's the Difference?).

Common mistakes

  • Using an agent for a fixed process. Added autonomy adds error and cost.
  • No step, time or cost limits. Loops can run away.
  • Overly broad tool permissions (Agent Tools: How AI Agents Take Actions).
  • Letting errors compound. One wrong early step can derail the rest; add checks between steps.
  • Evaluating only the final answer. Also inspect tool choices and arguments (How to Evaluate AI Systems and Outputs).
  • No human approval for irreversible actions.