Skip to content
AI & Machine LearningAll explainers

What is an AI agent? How agents work

An AI agent wraps an LLM in a loop that can plan, call tools, read the result, and decide the next step. Here's how the loop works, which architectures teams use, and the guardrails production agents need.

Published: Updated: Reading time: 8 min
On this page

An AI agent is a system that wraps a large language model in a loop so it can do more than answer once. The agent plans a step, calls a tool, reads the result, and decides what to do next, repeating until the task is done. So what is an AI agent in practice? It's software that pursues a goal over many steps instead of producing one response, and that's the difference between a chatbot and a program that gets work done.

What is an AI agent and how the loop works

Under the hood an agent runs a tight cycle, usually some variant of the ReAct pattern, which pairs reasoning with action.

  1. Reason: the model looks at the goal and the current state and decides the next step.
  2. Act: it calls a tool: a web search, an API request, a database query, a code execution.
  3. Observe: the tool's output is fed back into the model's context.
  4. Repeat: the loop continues until the goal is met or a stop condition fires.

Decision logic lives inside the model, which keeps the system flexible. Execution logic lives in your code, which keeps it inspectable and controllable. That means you can log every thought and every tool call, validate arguments before they run, and cut the loop off when it stalls. If you want a mental model, think of a while-loop with a language model deciding when to exit.

AI agents vs generative AI

People use the two terms loosely. generative-ai is the broad capability: give a model a prompt, get back new content. An agent runs that capability inside a control loop that has a goal, memory, and the ability to take real actions.

A useful test: if the system returns one output and stops, it's generative AI. If it can call a tool, look at what came back, and choose a different action as a result, it's an agent. Every agent is built on generative models, but plenty of generative AI use never involves an agent. In practice, "we need an agent" and "we need a good prompt" lead to very different amounts of engineering in AI agent development and broader AI development. The finer point of agentic AI vs AI agents gets its own treatment in this explainer.

AI agent architecture and patterns

Most production agents are assembled from a small set of patterns rather than one grand design. The common ones, roughly in order of how often you meet them:

PatternHow it worksWhen it fitsExtra cost
ReActReason, act, observe, step by stepConstrained tool tasksLow
Plan-and-executeA planner writes a task list, an executor works itLong jobs that lose the threadPlanning pass
ReflectionA second pass critiques output before commitCode, high-stakes decisionsLatency and tokens
RouterA dispatcher picks the agent, model, or toolMixed incoming requestsUsually one classification call

ReAct is the baseline behind most tool-using agents and is enough for a lot of work. Reflection does improve reliability, though it's usually optional because of what it adds to latency. A router is often just a classification prompt with sensible fallbacks.

Real systems mix these. A typical stack is ReAct for the inner loop, a planner on top for structure, and a router at the front to send work to the right place.

Tool calling and memory

An agent differs from a model in a text box in two ways: it can do things, and it can remember them.

Tools and function calling

Tools are typed functions exposed to the model through a schema, which is what vendors call tool calling or function calling. The model picks a tool and emits structured arguments. Your runtime executes the call and returns the result. Most of the safety work happens here: tools enforce validation, access control, rate limits, and logging, so a well-designed tool layer does most of the job of keeping an agent in bounds.

In late 2024 Anthropic open-sourced the Model Context Protocol (MCP), a standard for connecting models to tools and data. Through 2025 it became a common way to share one tool layer across agents instead of re-wiring every integration, and in December 2025 Anthropic donated MCP to the Linux Foundation's Agentic AI Foundation, with OpenAI, Google, and Microsoft among the backers.

Short-term and long-term memory

Short-term memory is the working state of the current task: the conversation, the plan so far, recent tool outputs, all bounded by the model's context window. Long-term memory persists across sessions, usually as embeddings in a vector store that the agent queries when it needs something relevant.

Many agents lean on retrieval-augmented-generation to pull grounded facts into context at the moment they act, rather than trusting whatever is baked into the weights.

Single-agent vs multi-agent systems

A single agent is one model in one loop with its tools and memory. It's cheaper, easier to reason about, and enough for most bounded workflows like triaging a support ticket or running a scripted research task. Start here.

A multi-agent system splits the work across specialists, a planner plus workers such as a researcher, a coder, and a tester, coordinated by an orchestrator that assigns tasks and merges results. Splitting roles lets each agent hold fewer permissions. The price is coordination overhead, more ways to fail, and harder debugging. A fair rule of thumb is to add agents when one can't hold the whole job, and to treat the extra orchestration as a cost you have to justify.

When an AI agent is worth building

Agents earn their keep on tasks that need several steps, depend on live data, and change course based on what they find: working a support ticket across three internal systems, say, or researching a question and writing up the answer. If a task fits in one prompt and one response, a plain model call is cheaper and easier to test. For worked deployments, see these AI agent examples.

Where agents struggle is just as useful to know. They can wander, repeat tool calls, or confidently act on a bad intermediate result, and every extra step adds cost and latency. That's why the rest of this entry is about evaluation and controls.

How teams evaluate agents

Agents are hard to test precisely because they are stochastic and act over many steps. The same task can succeed down one path and fail down another, and a small mistake early can surface much later. Two kinds of evaluation cover it.

Outcome evaluation asks whether the goal was met: did the patch fix the bug, did the ticket get resolved. Public benchmarks like SWE-bench, which scores fixes to real GitHub issues, and tau-bench, Sierra's benchmark for tool-using agents in customer-service tasks, measure exactly this. Sierra has since released tau2-bench, and scores across the two versions aren't directly comparable. Trajectory evaluation goes deeper and inspects the whole sequence of decisions and tool calls for wasted steps, wrong turns, or policy violations. You need both: an agent can reach the right answer by a route you wouldn't want repeated.

What production AI agents need

The freedom to choose actions is what makes an agent useful, and it's also where the risk comes from. A demo can be built quickly. A reliable agent takes real engineering, usually aligned with governance guidance like the NIST AI Risk Management Framework and its Generative AI Profile (NIST AI 600-1). It needs:

  • Tool guardrails: scoped permissions per agent and validation on every action, so an agent can only touch what its job requires.
  • Human-in-the-loop: approval gates on anything irreversible, like a payment, a deployment, or a data deletion.
  • Observability, meaning traces of every reasoning step and tool call. Without them you can't debug or run trajectory evaluation.
  • Cost and loop control: hard caps on steps, tokens, and tool calls, plus cheaper models for routine work, so a stuck agent can't run up the bill.
  • Prompt-injection defense: untrusted text in a web page or document can smuggle in instructions that hijack the agent. Prompt injection is LLM01 in the OWASP Top 10 for LLM Applications, so anything that reads outside content and can act on it needs input filtering and output checks.

Most of this is ordinary discipline for software that takes actions on your behalf. The difference is that here the software also decides which action comes next, so teams usually widen an agent's autonomy only after its traces show it behaving well at the current level.

Frequently asked questions

  • An AI agent is a system that wraps a large language model in a loop so it can act, not just answer. It plans a step, calls a tool such as a search or an API, reads the result, then decides what to do next, repeating until the goal is met. The model makes the decisions and the surrounding code runs the actions and holds the state. That loop is what separates an agent from a chatbot that only replies.

  • Generative AI takes a prompt and returns one output, like a paragraph or an image. An AI agent runs generative models inside a control loop, so it can pursue a goal over many steps, use tools, and react to results. Every agent uses generative AI under the hood, but not every generative model is an agent.

  • They can, but most production agents run with tight limits. Teams cap the steps, scope which tools an agent may call, and send risky actions like payments to a human for approval. An unbounded loop is expensive and hard to trust, so full autonomy is rarely the goal.

  • A multi-agent system splits a job across several specialized agents coordinated by an orchestrator. A planner breaks the goal into tasks, workers such as a researcher, a coder, and a tester handle their parts, and the orchestrator routes work and merges results. You get narrower roles and tighter permissions per agent, but there are more parts to coordinate and debug, so most teams add agents only after a single one has clearly hit its limit.

  • You measure two things, the outcome and the path. Outcome evaluation asks whether the task got done correctly, using benchmarks like SWE-bench for coding fixes or tau-bench for tool-driven support tasks. Trajectory evaluation inspects the full sequence of reasoning and tool calls for wasted steps, wrong turns, or policy breaches. Both need logged traces, which is why observability has to be in place before you start testing.

  • A plain chat session isn't an agent. You send a prompt and get one reply. It starts to behave like an agent when it's allowed to call tools, for example to search the web, run code, or read files, and then uses those results to decide its next step. What makes something an agent is that loop, whichever product runs it.

Still unanswered
Ask us directly

A senior engineer replies under 4 hours.

Related expertise