---
title: "What are AI agents? How agents work and when to use one"
description: "AI agents are LLM systems that call tools in a loop until a task is done. Learn how the loop works, agents vs agentic AI, examples, failure modes, and limits."
summary: "An AI agent is a system in which language model output selects the next action, a tool call executes it, and the result feeds back until the task ends or a limit is hit. This explainer covers the agent loop, workflows versus agents, examples, failure modes, and when a simpler design wins."
type: "explainer"
canonical_url: "https://theaiengineering.com/articles/what-are-ai-agents"
markdown_url: "https://theaiengineering.com/articles/what-are-ai-agents.md"
topic: "AI agents"
author: "The AI Engineering Editors"
publisher: "The AI Engineering"
published: "2026-07-16"
updated: "2026-07-16"
keywords: ["ai agents","what is an ai agent","agentic ai","ai agents vs agentic ai","ai agents examples","how does an ai agent work","ai agent vs chatbot"]
citation: "The AI Engineering Editors. \"What are AI agents? How agents work and when to use one.\" The AI Engineering, updated Jul 16, 2026. https://theaiengineering.com/articles/what-are-ai-agents"
---

# What are AI agents? How agents work and when to use one

## TL;DR

- An AI agent runs a language model in a loop: model output selects a tool call, the application executes the call, and the result returns to the model until the task ends.
- Every agent has five parts: a model, tools, memory, a planning approach, and stopping conditions such as step limits and cost budgets.
- An agentic workflow follows code paths fixed in advance, while an autonomous agent lets model output pick each step; workflows are more predictable and easier to test.
- The common agent failure modes are compounding errors across steps, poor tool design, context overload, non-terminating loops, and prompt injection through tool results.
- If a fixed sequence of steps or a single model call can do the job, that design is cheaper, faster, and more reliable than an agent.

AI agents are software systems that run a language model in a loop: model output selects an action, such as a tool call, the application executes the action and returns the result, and the cycle repeats until the task is complete or a limit is reached. The loop lets one request turn into many model calls and real actions in other systems, which is what separates an [AI agent](https://theaiengineering.com/glossary/ai-agent) from a chatbot. This explainer covers how the loop works, how agents differ from agentic workflows and from "agentic AI," real examples, the ways agents fail, and when not to build one. The explainer is part of our [AI agents topic hub](https://theaiengineering.com/topics/ai-agents).

## What is an AI agent?

An AI agent is a system that runs a language model in a loop: model output selects tool calls, and tool results feed back until the task ends.

The defining property is where control flow lives. In ordinary software, code determines every step. In an agent, the model's output determines the next step at runtime: which tool to call, with which arguments, and whether the task is finished. Anthropic's engineering post [Building effective agents](https://www.anthropic.com/engineering/building-effective-agents) (December 2024) uses this as the dividing line, describing agents as systems in which the LLM, rather than predefined code, controls the process and tool usage.

The idea predates large language models. Classic AI textbooks define an agent as anything that perceives an environment and acts on it. In an LLM agent, the context window is the perception and [tool calling](https://theaiengineering.com/glossary/tool-calling) is the action. Research such as the [ReAct](https://theaiengineering.com/glossary/react-agent) paper (Yao et al., 2022) showed that interleaving written reasoning steps with actions improves results on multi-step tasks, and that interleaved pattern remains a common agent design.

## How does an AI agent work?

An AI agent works by repeating one cycle. The application sends the task, the history so far, and the available tool definitions to a model. The model returns either a final answer or a tool call. The application checks the call against its policies, executes it, appends the result to the context, checks its budgets, and calls the model again.

**Figure 1: The agent loop. The application, not the model, executes tools and enforces limits.**

Loop: the task and tools feed a model call; a tool call is checked and run, its result appended, and the model called again until it returns a final answer.

Components:

- **Task and tools**: Instructions, tool definitions
- **Model call**: Over the current context
- **Check policy, run tool**: The application executes it
- **Append result**: Add to context, check budgets
- **Return result**: To the caller

Connections:

- Task and tools → Model call
- Model call → Check policy, run tool: tool call
- Check policy, run tool → Append result
- Append result → Model call
- Model call → Return result: final answer

The loop fits in a few lines of code. In the sketch below, `call_model` stands in for a provider SDK call, and message formats vary by provider:

```python
def run_agent(task, tools, call_model, max_steps=10):
    """tools maps a name to an object with .schema and .run(**args)."""
    messages = [{"role": "user", "content": task}]
    schemas = [tool.schema for tool in tools.values()]
    for _ in range(max_steps):
        reply = call_model(messages, tools=schemas)
        messages.append(reply.message)
        if not reply.tool_calls:  # no tool requested: final answer
            return reply.text
        for call in reply.tool_calls:
            result = tools[call.name].run(**call.arguments)
            messages.append({"role": "tool", "tool_call_id": call.id,
                             "content": str(result)})
    raise RuntimeError("step budget exhausted before the task finished")
```

Production agents add error handling, permission checks, tracing, and context management around this loop, but the structure stays the same. The loop has five parts.

### The model

The model generates each next step from the current context. Models trained for tool use produce well-formed calls more consistently, and reasoning models can plan across more steps before acting, at the cost of extra latency and tokens. Model choice sets the ceiling on how complex a task the agent can complete.

### Tools

Tools are functions the application exposes with a name, a description, and a JSON schema for arguments. The tool description works as a prompt: vague or overlapping descriptions produce wrong calls. The [Model Context Protocol](https://theaiengineering.com/glossary/model-context-protocol) standardizes how tools and data sources are exposed, so one tool server can serve many agents. Our explainer on [tool calling](https://theaiengineering.com/articles/tool-calling) covers schema design.

### Memory

Short-term memory is the conversation and tool history inside the context window. Long-term [agent memory](https://theaiengineering.com/glossary/agent-memory) is anything stored outside the model, such as notes, user preferences, or past results in a database, and retrieved into context in later steps or sessions. Long tasks need compaction, such as summarizing old steps, because a full history eventually exceeds the window or buries key details.

### Planning

Planning is how an agent breaks a task into steps. Some agents plan implicitly, writing a short reasoning step before each action in the ReAct style. Others write an explicit plan or to-do list first and update it as they go. Complex systems delegate subtasks to [subagents](https://theaiengineering.com/glossary/subagent), each with its own context, and combine the results.

### Stopping conditions

Stopping conditions end the loop. The normal stop is a final answer, but every production agent also needs hard limits: a maximum number of steps, a token or cost budget, a wall-clock timeout, and [approval gates](https://theaiengineering.com/glossary/human-in-the-loop) before risky actions. Anthropic's guidance notes that agents commonly include stopping conditions such as a maximum iteration count, and recommends extensive testing in sandboxed environments.

## Agentic workflows vs autonomous agents

An agentic workflow runs model calls along code paths the developer defined in advance; an autonomous agent lets model output choose the next step at runtime. Both use the same models and tools. The difference decides how predictable, testable, and expensive the system is, so it is the first design decision for any agent project.

| Aspect | Agentic workflow | Autonomous agent |
|---|---|---|
| Control flow | Fixed in code | Chosen by model output at runtime |
| Predictability | Same path on every run | Path varies between runs |
| Testing | Test each step in isolation | Test outcomes and full trajectories |
| Cost and latency | Bounded by design | Variable, so budgets are required |
| Best fit | Known, repeatable processes | Open-ended tasks with unknown steps |
| Example | Classify a ticket, route it, draft a reply, check tone | Find and fix the cause of a failing test suite |

Anthropic's post names five common workflow patterns: prompt chaining (a fixed sequence of calls), routing (classify, then dispatch), parallelization (split work or vote across calls), [orchestrator-workers](https://theaiengineering.com/glossary/agent-orchestration) (one model delegates subtasks to others), and evaluator-optimizer (one call drafts, another critiques). Many production systems combine both styles: a fixed workflow with one agentic step where the task is genuinely open-ended. Agent frameworks such as LangGraph and Microsoft Agent Framework model this mix directly; our [AI agent frameworks comparison](https://theaiengineering.com/articles/ai-agent-frameworks) covers how each one handles it.

## AI agents vs agentic AI

In everyday use, an AI agent is one specific system, while agentic AI is the broader category of systems that act with some autonomy, including several agents coordinating together. The terms overlap heavily in marketing. A useful working rule: "agent" names a thing you can deploy, and "agentic" describes how much control over its own steps a system has.

The 2025 paper [AI Agents vs. Agentic AI: A Conceptual Taxonomy](https://arxiv.org/abs/2505.10468) by Sapkota, Roumeliotis, and Karkee formalizes the split. The paper treats AI agents as modular, LLM-driven systems for task-specific automation, and treats [agentic AI](https://theaiengineering.com/glossary/agentic-ai) as a different design approach marked by multi-agent collaboration, dynamic task decomposition, persistent memory, and coordinated autonomy. In engineering terms, the paper's definition of agentic AI corresponds to a [multi-agent system](https://theaiengineering.com/glossary/multi-agent-system).

Gartner warned in 2025 about "agent washing," the practice of rebranding chatbots, assistants, and robotic process automation tools as agentic without real agentic capabilities. When evaluating a product labeled agentic, ask whether model output actually controls multi-step behavior or whether the product is a single model call behind a new name.

## AI agent vs chatbot vs LLM

An LLM is the model: text in, text out. A chatbot wraps an LLM in a conversation interface and answers one turn at a time. An AI agent wraps an LLM in a loop with tools, so one request can trigger many model calls and actions. The key differences are control of the next step and reach into external systems.

| | LLM call | Chatbot | AI agent |
|---|---|---|---|
| Unit of work | One prompt, one completion | One conversational turn | One task, many steps |
| Actions in other systems | None | Usually none, or one lookup | Many, through tools |
| Model calls per request | One | One or a few | Many, variable |
| Main risk | A wrong answer | A wrong answer in conversation | A wrong action with real side effects |

## AI agents examples

Common AI agent examples include coding agents that edit and test code, research agents that search and synthesize sources, customer-support agents that look up accounts and take bounded actions, data agents that write and run queries, and [computer-use agents](https://theaiengineering.com/glossary/computer-use-agent) that operate a browser or desktop. Each example pairs open-ended steps with tools that reach real systems.

- **Coding agents.** Tools such as Claude Code, OpenAI Codex, and GitHub Copilot's coding agent read a repository, edit files, run tests, and iterate on failures. Our [AI coding agents comparison](https://theaiengineering.com/articles/ai-coding-agents) covers them in depth.
- **Research agents.** Deep research features in assistant products run many searches, read the results, and write a cited report.
- **Customer-support agents.** These agents look up orders and accounts, answer from a help center, and escalate to a human, with write actions such as refunds limited or gated behind approval.
- **Data analysis agents.** These agents write SQL or Python, run the code against a database or notebook, inspect the output, and revise the query.
- **Computer-use agents.** These agents operate graphical interfaces from screenshots, clicking and typing in a browser or desktop app where no API exists.
- **Operations agents.** These agents investigate alerts by querying logs and metrics, then propose or apply a fix within a scoped set of permissions.

## Why do AI agents fail?

The common AI agent failure modes are compounding errors across steps, poorly designed tools, context overload, loops that never converge, and untrusted content steering tool use. Gartner predicted in June 2025 that [over 40% of agentic AI projects will be canceled by the end of 2027](https://www.gartner.com/en/newsroom/press-releases/2025-06-25-gartner-predicts-over-40-percent-of-agentic-ai-projects-will-be-canceled-by-end-of-2027), citing rising costs, unclear business value, and inadequate risk controls.

- **Compounding errors.** Small per-step error rates multiply. A step that succeeds 95% of the time, repeated independently 10 times, completes all 10 steps about 60% of the time.
- **Tool misuse.** Vague descriptions, overlapping tools, and loose argument schemas lead to wrong calls or malformed arguments.
- **Context overload.** Long histories and verbose tool outputs crowd the context window, and later outputs stop reflecting the original goal or earlier findings.
- **Non-termination.** An agent can repeat a failing call or oscillate between two approaches; only hard step and cost limits end such loops.
- **Prompt injection.** Tool results such as web pages, emails, or documents can contain instructions that redirect the agent. Prompt injection is entry LLM01 in the [OWASP Top 10 for LLM Applications](https://genai.owasp.org/llm-top-10/), and our [glossary entry on prompt injection](https://theaiengineering.com/glossary/prompt-injection) explains the mechanics.
- **Excessive agency.** Agents given broad permissions can do broad damage. OWASP lists excessive agency as LLM06 and unbounded consumption, such as runaway token spend, as LLM10.
- **Weak evaluation.** A correct final answer can hide a wasteful or unsafe trajectory, so agent evals must check the steps as well as the outcome. Our [LLM evaluation guide](https://theaiengineering.com/articles/llm-evaluation) covers trajectory scoring.

The defenses map to the failures: fewer, sharper tools; least-privilege permissions; human approval for irreversible actions; guardrails on inputs and outputs; context compaction; hard budgets; and traces of every step.

## When not to use an AI agent

Do not use an AI agent when the steps are known in advance, when a single model call with good retrieval answers the question, when mistakes are costly and hard to reverse, or when latency and cost must be predictable. In those cases a fixed workflow or a plain function is cheaper, faster, and easier to test.

A model provider and a framework vendor give the same advice. Anthropic's guidance recommends finding the simplest solution and adding complexity only when needed, and notes that for many applications a single optimized model call with retrieval and in-context examples is usually enough. Microsoft's Agent Framework documentation advises writing a regular function instead of an agent whenever a function can handle the task.

| Use an AI agent when | Use something simpler when |
|---|---|
| The number and order of steps depend on what the system finds | The steps are the same every time |
| Tools must be combined in ways you cannot enumerate | One or two known tool calls cover the task |
| A human reviews the result or the actions are reversible | Actions are irreversible and unreviewed |
| Variable cost and latency are acceptable | Strict latency or cost limits apply |
| You have an eval set to measure task success | You cannot yet measure whether the output is right |

A practical test: write the task as a flowchart. If the flowchart is complete, build the workflow. If the flowchart keeps needing a box labeled "figure out what to do next," that box is where an agent belongs.

## Where to go next

To pick tooling for the loop described here, read our [AI agent frameworks comparison](https://theaiengineering.com/articles/ai-agent-frameworks), which covers LangGraph, CrewAI, the OpenAI, Claude, and Google SDKs, and more, or browse the [agent frameworks directory](https://theaiengineering.com/platforms/agent-frameworks). For the protocol that connects agents to tools and data, continue with [what the Model Context Protocol is](https://theaiengineering.com/articles/what-is-model-context-protocol).

## Frequently asked questions

### What are AI agents used for?

AI agents are used for tasks where the steps cannot be fully scripted in advance. Common uses include coding agents that edit code and run tests, research agents that search and summarize sources, support agents that look up accounts and take limited actions, data agents that write and run queries, and computer-use agents that operate web or desktop interfaces on a user's behalf.

### How do AI agents communicate with each other?

AI agents communicate through messages passed by an orchestrating program, or through open protocols. The Agent2Agent (A2A) protocol, which Google announced in April 2025 and the Linux Foundation took on as a project in June 2025, defines how agents from different systems exchange tasks and results. The Model Context Protocol covers a different link: connecting an agent to tools and data sources.

### What are the types of AI agents?

The classic taxonomy from Russell and Norvig's textbook Artificial Intelligence: A Modern Approach lists simple reflex, model-based reflex, goal-based, utility-based, and learning agents. In LLM engineering, teams more often classify agents by architecture: single agents with tools, orchestrator-worker systems that delegate to subagents, and multi-agent systems in which several agents coordinate through messages or a shared state.

### How do AI agents learn?

Most deployed AI agents do not learn in the training sense while they run, because the model weights stay fixed. An agent can store facts in long-term memory, such as a database it reads in later sessions, which changes its behavior without retraining. Engineering teams improve agents by editing prompts and tools, adding eval cases from failures, and sometimes fine-tuning the underlying model.

### How do you build an AI agent?

Start with a narrow task and a model that supports tool calling. Define a few well-described tools, write a loop that calls the model, executes requested tools, and appends results, and add a step limit and cost budget. Build an eval set of real tasks before adding complexity. Move to an agent framework once you need durable state, tracing, or multi-agent orchestration.

## Terms in this guide

- [AI agent](https://theaiengineering.com/glossary/ai-agent): An AI agent is a software system in which a large language model runs in a loop, calling tools, reading their results, and repeating until the task is complete or a stop condition is reached.
- [Agentic AI](https://theaiengineering.com/glossary/agentic-ai): Agentic AI is the class of AI systems that pursue a goal through multiple steps, using a language model to plan, call tools, and act on the results with limited human input.
- [Multi-agent system](https://theaiengineering.com/glossary/multi-agent-system): A multi-agent system is an AI architecture in which several language-model agents, each with its own prompt, tools, and context, work on parts of a task and pass results to one another.
- [Agent memory](https://theaiengineering.com/glossary/agent-memory): Agent memory is the set of mechanisms that let an AI agent keep and retrieve information beyond a single model call, from the current context window to external stores that persist across sessions.
- [Tool calling](https://theaiengineering.com/glossary/tool-calling): Tool calling is an LLM capability in which the model, given a list of tool definitions, outputs a structured request naming a tool and its arguments, which the application executes and returns.
- [Model Context Protocol (MCP)](https://theaiengineering.com/glossary/model-context-protocol): Model Context Protocol (MCP) is an open protocol, introduced by Anthropic in November 2024, that standardizes how AI applications connect to external tools, data sources, and prompts through MCP servers.
- [Context window](https://theaiengineering.com/glossary/context-window): A context window is the maximum number of tokens a language model can take into account in a single request, including the system prompt, conversation history, tool results, and the generated output.
- [Prompt injection](https://theaiengineering.com/glossary/prompt-injection): Prompt injection is an attack in which text supplied to a large language model, typed by a user or hidden in content the model reads, alters the application's intended behavior or output.
- [Guardrails](https://theaiengineering.com/glossary/guardrails): Guardrails are programmatic checks placed around a large language model that validate, filter, or block inputs, outputs, and tool calls so an AI application stays within its safety, security, and policy limits.
- [A2A protocol](https://theaiengineering.com/glossary/a2a-protocol): The A2A (Agent2Agent) protocol is an open standard, introduced by Google in April 2025, that lets AI agents built on different frameworks discover each other, exchange messages, and delegate tasks.
- [ReAct agent](https://theaiengineering.com/glossary/react-agent): A ReAct agent is an AI agent that alternates a written reasoning step, an action such as a tool call, and an observation of the result, repeating the cycle until it can answer.
- [JSON Schema](https://theaiengineering.com/glossary/json-schema): JSON Schema is a declarative vocabulary, itself written in JSON, for describing the structure of JSON data; LLM APIs and MCP use it to define tool arguments and constrain model output.
- [Context compaction](https://theaiengineering.com/glossary/context-compaction): Context compaction is a context management technique that replaces older conversation turns with a model-written summary as the context window nears its limit, so an agent can keep working.
- [Subagent](https://theaiengineering.com/glossary/subagent): A subagent is an AI agent that another agent starts for one subtask, running in a separate context window with its own instructions and tools, and returning only a condensed result.
- [Human-in-the-loop](https://theaiengineering.com/glossary/human-in-the-loop): Human-in-the-loop (HITL) is an agent design in which the run pauses at defined checkpoints, such as before a sensitive tool call, so a person can approve, edit, or reject the action.
- [Agent sandbox](https://theaiengineering.com/glossary/agent-sandbox): An agent sandbox is an isolated execution environment in which an AI agent runs code, shell commands, or a browser, with enforced limits on the files, network hosts, and credentials it can reach.
- [Agent orchestration](https://theaiengineering.com/glossary/agent-orchestration): Agent orchestration is the control logic that decides which agent, model call, or tool runs next in an AI system and what each receives, whether written in code or chosen by a model.
- [Computer-use agent](https://theaiengineering.com/glossary/computer-use-agent): A computer-use agent is an AI agent that operates a graphical interface, such as a desktop or web browser, by reading screenshots and issuing mouse and keyboard actions instead of calling APIs.
- [Few-shot prompting](https://theaiengineering.com/glossary/few-shot-prompting): Few-shot prompting is a technique that puts a few example inputs paired with desired outputs in a prompt, so a language model infers the task, format, and labels without changing its weights.
- [Golden dataset](https://theaiengineering.com/glossary/golden-dataset): A golden dataset is a curated, versioned set of representative inputs, each paired with an expected output or grading criteria, that a team treats as ground truth when evaluating an LLM application.

## Related guides

- [AI agent frameworks compared: LangGraph, CrewAI, ADK, and more](https://theaiengineering.com/articles/ai-agent-frameworks): An AI agent frameworks comparison of LangGraph, LangChain, CrewAI, the OpenAI, Claude, and Google SDKs, Pydantic AI, Mastra, and more, by language and license.
- [How to build an AI agent: a step-by-step guide in Python](https://theaiengineering.com/articles/how-to-build-an-ai-agent): Learn how to build an AI agent from scratch in Python: when you need one, tool schemas, the agent loop, stop conditions, guardrails, evals, and tracing.
- [What is tool calling? How LLM function calling works](https://theaiengineering.com/articles/tool-calling): Tool calling lets an LLM request actions from your code through structured calls. Learn the request loop, parallel calls, structured outputs, security, and MCP.
- [What is the Model Context Protocol (MCP)? How it works](https://theaiengineering.com/articles/what-is-model-context-protocol): The Model Context Protocol (MCP) is an open standard for connecting AI apps to tools and data. Learn its architecture, transports, tool calls, and security.

Part of the [AI agents](https://theaiengineering.com/topics/ai-agents) topic hub.

## Cite this guide

The AI Engineering Editors. "What are AI agents? How agents work and when to use one." The AI Engineering, updated Jul 16, 2026. https://theaiengineering.com/articles/what-are-ai-agents

- Title: What are AI agents? How agents work and when to use one
- Author: The AI Engineering Editors
- Publisher: The AI Engineering
- Published: 2026-07-16
- Updated: 2026-07-16
- URL: https://theaiengineering.com/articles/what-are-ai-agents
- Markdown: https://theaiengineering.com/articles/what-are-ai-agents.md

To cite one section, link to its anchor:

- [What is an AI agent?](https://theaiengineering.com/articles/what-are-ai-agents#what-is-an-ai-agent)
- [How does an AI agent work?](https://theaiengineering.com/articles/what-are-ai-agents#how-does-an-ai-agent-work)
- [Agentic workflows vs autonomous agents](https://theaiengineering.com/articles/what-are-ai-agents#agentic-workflows-vs-autonomous-agents)
- [AI agents vs agentic AI](https://theaiengineering.com/articles/what-are-ai-agents#ai-agents-vs-agentic-ai)
- [AI agent vs chatbot vs LLM](https://theaiengineering.com/articles/what-are-ai-agents#ai-agent-vs-chatbot-vs-llm)
- [AI agents examples](https://theaiengineering.com/articles/what-are-ai-agents#ai-agents-examples)
- [Why do AI agents fail?](https://theaiengineering.com/articles/what-are-ai-agents#why-do-ai-agents-fail)
- [When not to use an AI agent](https://theaiengineering.com/articles/what-are-ai-agents#when-not-to-use-an-ai-agent)
- [Where to go next](https://theaiengineering.com/articles/what-are-ai-agents#where-to-go-next)
- [Frequently asked questions](https://theaiengineering.com/articles/what-are-ai-agents#faq)
