What are AI agents? A beginner's guide to the agent loop, tools, memory, the harness and multi-agent systems
An AI agent is a language model that works toward a goal by choosing its own next step: it calls a tool, reads the result, and repeats until the task is done. A chatbot only answers, and a workflow follows steps your code fixed in advance. Everything around the model (the loop, the tools, permissions, memory and limits) is called the agent harness. Agents are flexible but cost more and are less predictable, so start with the simplest design that works.
What are AI agents?
An AI agent is a language model that works toward a goal by deciding its own next step. It can call tools (search, a database, a code runner, a booking API), read what comes back, and choose what to do next, again and again, until the job is done. Anthropic's working definition is short: agents are "LLMs autonomously using tools in a loop."
That sounds simple, and the core is. The confusion comes from everything people call an agent: chatbots, scripted pipelines with a model inside, coding assistants, "agentic" products. This guide sorts them out, then walks through the parts every agent has: the loop, tools, memory, planning, the harness around the model, guardrails, multi-agent setups, evaluation and the ways agents fail.
We use one running example throughout: Tripwell, a small online travel company whose assistant grows from a chatbot into a workflow and then into an agent. Its customer, Maya, needs a trip to a conference in Lisbon, flight and hotel included, for under 600 euros.
Chatbot vs workflow vs AI agent
Version 1, the chatbot. Maya asks for a flight; the model answers from what it learned in training plus the conversation. It cannot see live prices and cannot book anything. Good for questions, useless for actions.
Version 2, the workflow. Tripwell's engineers write the steps in code: the model extracts the city, date and budget; code calls the flight API and filters by price; the model writes a friendly summary. Anthropic's guide Building effective agents calls these "systems where LLMs and tools are orchestrated through predefined code paths." The engineers chose every step before Maya typed anything.
Version 3, the agent. Now Maya asks for a trip close to the venue, hotel included, under budget. The steps depend on what the searches return. If the cheap flight lands at midnight, the hotel needs a late check in; if the hotels near the venue are full, another date may work better. The same guide defines agents as systems where "LLMs dynamically direct their own processes and tool usage." In a workflow your code picks the next step; in an agent, the model does.
| Chatbot | Workflow | AI agent | |
|---|---|---|---|
| Who picks the steps | nobody, one reply | your code | the model |
| Can it take actions? | no | yes, fixed ones | yes, its own choice |
| Cost and speed | lowest | low and known | higher, varies by task |
| Predictability | mostly predictable | very predictable | less predictable |
| Best for | questions | known, repeatable tasks | open-ended tasks |
Workflows are not a lesser option. The guide lists five common patterns (prompt chaining, routing, parallelization, orchestrator workers and evaluator optimizer), and many products need nothing more. Our deeper comparison, workflow vs agent, gives a three-question rule for choosing.
AI agents examples
Where do you meet agents today?
- Coding agents such as Claude Code or Codex read a repository, run the tests and edit files until the tests pass.
- Research agents search many sources and write a report with citations.
- Support agents look up an order and issue a refund within the company's rules.
- Computer use agents click and type through websites and desktop apps, as a person would.
Different jobs, one shape: a model, a set of tools and a loop.
How AI agents work: the agent loop
Every agent runs the same cycle:
- The model reads the goal and everything that has happened so far.
- It decides what to do next. Usually that is a tool call.
- The code around the model runs the tool and adds the result to the conversation.
- The model reads the result and decides again.
The loop ends when the model answers without asking for a tool; that is its signal that it thinks the task is done. One pass is often called a turn. The Claude Agent SDK documentation describes exactly this: Claude evaluates the prompt, calls tools, receives the results, and repeats until it produces a response with no tool calls.
Here is Tripwell's agent on Maya's request. Turn one: it searches flights for the day before the conference and finds six; the cheapest is 140 euros but lands just before midnight. Turn two: it searches hotels near the venue and finds two rooms at 210 euros a night. Then it adds it up (140 plus two nights at 210 is 560 euros, under budget), stops calling tools and replies with a plan and a question: shall I book it? Nobody scripted those steps.
You never rely on the model alone to stop. The code sets hard limits: a maximum number of turns, a spending budget, a timeout. Building effective agents recommends stopping conditions such as a maximum number of iterations, and the Agent SDK exposes max_turns and max_budget_usd for this. Our article on the agentic loop and stop reasons shows how the loop should end, and three wrong ways to end it.
Tools and function calling
A tool is a function your code offers to the model. It has a name, a plain description and an input schema that lists its parameters, for example search_flights with from, to, date and an optional max_price.
This is often called function calling, and the key point surprises many beginners: the model never runs the function. It writes a structured request (the tool name and its arguments) and stops. Your code checks the request, runs the real function and sends the result back. In Claude's API that is a tool_use block out and a tool_result block back, as the tool use docs describe. The full round trip is in Claude tool use, explained.
Tool design matters more than most people expect, because the model chooses tools by reading their names and descriptions:
- Describe each tool as you would for a new teammate.
- Keep the set small, with no two tools that overlap.
- Make mistakes hard: ask for a date in a fixed format, not a free text "when".
- When a tool fails, return a clear error the model can act on.
If you would rather not wire every tool by hand, the Model Context Protocol (MCP) is an open standard for plugging tools and data into AI applications.
AI agent memory: context, notes and retrieval
An agent's working memory is its context window: everything the model sees in one request. In an agent it keeps growing, turn after turn, with the system prompt, tool definitions, the conversation and every tool result. The window has a limit, and long before you reach it, recall gets less reliable. Anthropic's guide to context engineering calls this context rot and treats attention as a finite budget.
So agents combine several kinds of memory:
- In context. Fast and always visible, but limited and gone when the session ends. See the LLM context window.
- Notes and files. The agent writes progress, decisions and preferences outside the window and reads them back later, such as Maya's aisle seat.
- Retrieval. The agent searches for what it needs when it needs it. That is RAG, used as a tool.
- Compaction. When the window gets full, the harness summarizes older turns and continues in a fresh, shorter context.
Planning
Before acting, an agent usually breaks the goal into steps, often as a simple to do list: flights on the 11th, hotels near the venue, check the total, ask Maya to approve, book and confirm. A written plan keeps the model on track over many turns and lets you see what it intends to do; Building effective agents lists that transparency as one of three core principles.
A good plan also changes: if the hotel search comes back empty, the agent updates it and tries the next day. Some tools go further and let you approve the plan first, which Claude Code calls plan mode.
What is an agent harness?
Most of what we have described so far is not the model. It is the code around it, and that code has a name: the agent harness. The harness runs the loop, holds the tools, checks permissions, manages the context, saves memory, enforces limits and logs what happened. A common shorthand is agent = model + harness: the model thinks, the harness lets it act safely.
Tripwell's harness, piece by piece:
| Piece | Tripwell's choice |
|---|---|
| Loop | up to 25 turns per request |
| Tools | search_flights, search_hotels, book, pay |
| Permissions | searches run freely, booking waits for Maya |
| Context | long chats are compacted |
| Memory | traveller notes, such as the aisle seat |
| Limits | a spending cap per request |
| Logs | every tool call recorded |
You already use harnesses. A coding tool like Claude Code is a harness around a model. Anthropic's Agent SDK offers "the same tools, agent loop, and context management that power Claude Code" as a library, and describes its Managed Agents service as "a hosted agent harness." Swap the model and most of the harness stays; swap the harness and the same model can behave very differently. For a component-by-component view, read AI agent architecture.
One caution about the word: in testing and evaluation, a harness also means the code that runs your tests. Anthropic's guide to agent evals defines both an agent harness and an evaluation harness, so check which one people mean.
What is harness engineering?
Harness engineering means designing that harness on purpose, instead of only tweaking the prompt. The phrase spread in early 2026; OpenAI's February 2026 post Harness engineering describes engineers whose job shifted from writing code to designing environments, specifying intent and building feedback loops for coding agents. In practice that is three jobs:
- Environment. The agent can see, run and check its own work (start the app, read logs, run tests).
- Constraints. Rules, permissions and checks enforced in code, not only requested in a prompt.
- Feedback loops. Tests, linters and reviews that catch mistakes so the agent can fix them.
One lesson repeats across these write-ups: give the agent a short map of where things are, not a thousand page manual. OpenAI's team replaced one large instruction file with a short index pointing to deeper docs. Where exactly harness engineering ends and context engineering begins is still debated, so treat it as a practical label, not a formal discipline.
Guardrails and human approval
An agent can take actions, so it can take wrong ones. Guardrails stop that, and the ones that matter live in the harness, not in the prompt. A common setup has three tiers:
- Allow: search flights, search hotels, read the traveller's notes.
- Ask a human: book, pay, change a booking.
- Deny: refund to another card, delete an account.
Add checks in code too: Tripwell refuses any booking above the customer's budget, whatever the model says. When the model asks to book the 560 euro trip, the harness pauses the loop, shows Maya exactly what will happen, and runs the booking only after she approves. The more costly or irreversible the action, the more it deserves that checkpoint. Our guides to human in the loop AI agents and guardrails in code go further.
Multi-agent systems: when are they worth it?
In a multi-agent system, an orchestrator agent splits a job and hands pieces to subagents. For a big trip, Tripwell's orchestrator could send one subagent to flights, one to hotels and one to things to do, in parallel. Each works in its own clean context window and returns only a short summary, so the orchestrator's context stays small.
It is expensive. In Anthropic's multi-agent research system, agents used about 4 times the tokens of a chat and multi-agent systems about 15 times.
It pays off when work splits into independent parts that run in parallel and the result is worth the cost; research is a good fit. It fits poorly when every step depends on the last or all agents need the same context, and the same write-up notes that most coding tasks split less cleanly than research. Early versions even spawned 50 subagents for simple questions. More in multi-agent systems with Claude.
How to evaluate an AI agent
An eval is a test: give the agent a task, let it run (a trial), keep the full record (the transcript) and score it with a grader. Grade the outcome, not the words: did a booking really appear in Tripwell's database, not did the agent say it booked one.
| Grader | Good at | Watch out |
|---|---|---|
| Code | fast, cheap, objective | brittle for nuance |
| Model | nuance, such as tone | must be checked against people |
| Human | the gold standard | slow and expensive |
Anthropic suggests starting with 20 to 50 simple tasks drawn from real failures. Run each task several times, because agents vary: an agent that succeeds 75% of the time succeeds three times in a row only about 42% of the time. For a booking assistant, consistency is what counts.
Why AI agents fail
Four failures show up again and again:
| Failure | What it looks like | The fix |
|---|---|---|
| Loops | the same search, again and again | a turn limit, a check for repeated calls |
| Wrong tool | or the right tool with wrong arguments | clear descriptions, fewer tools, validation in code |
| Runaway cost | long loops, many subagents | a budget for every run |
| Prompt injection | text the agent reads hides instructions | least privilege, a human on risky actions |
Prompt injection deserves one more sentence: when an agent reads a web page, a file or a hotel review, any instructions hidden in that text can try to take over the agent, which OWASP calls indirect prompt injection.
Do you need an AI agent? A checklist
Building effective agents gives the simplest advice: find the simplest solution that works and add complexity only when needed, which "might mean not building agentic systems at all." Walk down this list and stop at the first line that fits:
- [ ] The answer comes from general knowledge alone: one model call.
- [ ] It needs your own documents: add retrieval.
- [ ] You can write the steps down in advance: a workflow.
- [ ] The steps depend on what it finds along the way: an agent.
- [ ] A big job that splits into independent, parallel parts: multi-agent.
- [ ] Any costly or irreversible action: a human approves, whatever you built.
Climb one step at a time, and let your evals tell you when the step below is not enough.
Recap
- A chatbot answers; a workflow follows steps written in code; an agent lets the model choose its next step, in a loop, with tools.
- Memory is the context window plus notes, retrieval and compaction.
- The harness is everything around the model: loop, tools, permissions, context and limits. Harness engineering is designing it on purpose.
- Guard risky actions with code and human approval, go multi-agent only when the work splits cleanly, measure with evals, and start simple.
Sources: Anthropic, Building effective agents; Anthropic, Effective context engineering for AI agents; Anthropic, How we built our multi-agent research system; Anthropic, Demystifying evals for AI agents; Anthropic, Effective harnesses for long-running agents; OpenAI, Harness engineering; Claude docs, Tool use; Claude Code docs, How the agent loop works; Model Context Protocol; OWASP, LLM01 Prompt Injection.
FAQ
What are AI agents in simple terms?
An AI agent is a language model that can take actions to reach a goal. It decides what to do next, calls a tool such as a flight search or a code runner, reads the result, and repeats that loop until it is done. Anthropic describes agents as LLMs autonomously using tools in a loop.
What is the difference between a chatbot, a workflow and an AI agent?
A chatbot answers in text and takes no actions. A workflow calls a model and tools along steps written in code in advance. An agent lets the model choose its own steps, one at a time, based on what each tool returns. Moving from chatbot to agent gains flexibility and costs predictability and money.
What is an agent harness?
The agent harness is all the code around the model that turns it into an agent: the loop that calls it again and again, the tools it may use, the permission checks, context management, memory and hard limits such as a maximum number of turns or a budget. A common shorthand is agent equals model plus harness.
What is harness engineering?
Harness engineering is the practice of designing that surrounding system on purpose: an environment where the agent can run and check its work, constraints enforced in code, and feedback loops such as tests and reviews. The term spread in early 2026 through engineering posts from teams building coding agents.
What are some examples of AI agents?
Coding agents that read a repository, run the tests and edit files until they pass; research agents that search many sources and write a cited report; support agents that look up an order and issue a refund within rules; and computer use agents that click and type through websites and apps.
Do I need an AI agent or is a workflow enough?
If you can write the steps down in advance, a workflow is cheaper, faster and easier to test. Use an agent only when the next step depends on what the last one found, and add multi-agent setups only for valuable jobs that split into independent parts.
Read next
- Workflow vs Agent: How to Choose, and What Agents Cost
- AI Agent Architecture: The Building Blocks, Explained
- What Is RAG? Retrieval-Augmented Generation Explained
- Claude Code Tutorial for Beginners: Install to First Commit
- Context Engineering vs Prompt Engineering: Fix Context Rot
- Software Engineering Unpacked: home
- The CCAR-F video playlist on YouTube