AI glossary · Agents and tools
What is an AI agent?
Also called: LLM agent, agentic loop, agent loop
Definition
An AI agent is a program in which a language model works towards a goal by repeatedly choosing a tool to call, reading the result and deciding the next step, until the task is done or a stop condition is reached.
Explained
How does an AI agent work?
Anthropic draws a useful line between workflows, where your code fixes the sequence of model and tool calls in advance, and agents, where the model decides its own steps and which tools to use. Underneath, an agent is a loop: send the goal and the available tools, let the model ask for a tool call, run it, send back the result, and repeat.
The model never runs anything itself. Your code, often called the harness, executes each call and returns real results from the environment, such as test output or a file’s contents. That feedback is what lets an agent notice a mistake and fix it. The loop ends when the model replies without asking for a tool, or when a limit you set, such as a maximum number of turns, stops it.
Coding agents such as Claude Code are this loop with file, search, shell and web tools, plus context management: project instructions in CLAUDE.md, subagents for side tasks, and compaction when the context window fills up.
Example
Token growth in a 7-request coding loop
Claude Code’s docs walk through “fix the failing tests” as six tool calls: run the tests, read the error, search for the source, read it, edit it, and run the tests again. Each call is a new request, and each request sends the original messages, every earlier reply and every tool result again.
Assume a 15,000-token start (system prompt, tool definitions, project instructions and your message) and about 2,000 tokens added per tool round trip. These sizes are illustrative; the shape is not. The last request carries 27,000 tokens, but the seven together send 147,000, which is 5.4 times as much. At Claude Sonnet 5.5’s input price of $2 per million tokens that is $0.29 of input for one small fix, before output and before any prompt caching discount.
| Request | What the agent does | Input tokens sent |
|---|---|---|
| 1 | Run the test suite | 15,000 |
| 2 | Read the failure output | 17,000 |
| 3 | Search for the relevant source files | 19,000 |
| 4 | Read those files | 21,000 |
| 5 | Edit the code | 23,000 |
| 6 | Run the tests again | 25,000 |
| 7 | Reply with the fix (no tool call) | 27,000 |
| Total | 147,000 |
Price from our daily data, 2026-11-28. Output tokens are not included.
Cost and quality
Why does an agent’s token cost grow every turn?
Because every turn re-sends the conversation, an agent’s input bill grows roughly with the square of its number of turns when each turn adds a similar amount. Long tasks, large tool results and many tool definitions all multiply it. Prompt caching, shorter tool outputs and fewer turns are the main levers.
Quality depends on the feedback the agent can get. Anthropic stresses that agents need ground truth from the environment at each step, such as tests that pass or fail, and recommends starting with the simplest solution and adding an agent only when a fixed workflow falls short.
Don’t mix up
AI agent vs chatbot: what’s the difference?
- AI agent vs chatbot
- A chatbot answers from what it was given in one reply. An agent takes actions through tools and loops on the results, so it can run code, edit files or query systems before it answers.
- Agent vs workflow
- In a workflow, your code decides the order of steps and the model fills in each one. In an agent, the model decides the steps. Workflows are more predictable and cheaper; agents handle tasks whose steps you can’t list in advance.
FAQ
Questions people ask
Is ChatGPT an AI agent?
A normal ChatGPT reply is an assistant answering a message, sometimes after a built-in tool such as web search, not an open-ended agent loop. OpenAI has offered agent features in ChatGPT that plan and carry out multi-step tasks with a browser and other tools, and its help centre now points longer multi-step tasks to ChatGPT Work. Product names and plans change often, so check OpenAI’s help centre for what is current.
What are the main parts of an AI agent?
A language model that decides the next step, a set of tools it can ask for (search, code execution, file edits, APIs), a harness that runs those calls and sends back the results, and a stop condition such as a turn limit. Coding agents add project instructions, such as CLAUDE.md for Claude Code, and ways to manage the context window as it fills.
Go deeper
Try it and read more
- Free toolLLM API Cost CalculatorEstimate per-request, daily and monthly API costs.
- Free toolPrompt Caching CalculatorEstimate savings from prompt caching.
- Free toolContext Window CheckerSee whether your text fits each model’s context window.
- Guide · 13 min readThe best model for coding agents, and how to choose oneThe best model for coding agents, judged on tool-use reliability, context, speed and cost per task, with current prices for tool-capable models from our data.
- Guide · 13 min readHow to reduce Claude Code token usage, and what each fix costs youReduce Claude Code token usage with /clear, /compact, plan mode, exact file references, the right model and effort, a lean CLAUDE.md and fewer MCP servers.
Related