Module 5 · Emerging · 7 lessons
Agents that call tools
A model that calls tools in a loop, and the limits that keep it safe: step budgets, timeouts and human approval.
Before you start
From this track: Modules 0 to 4. Each module uses only ideas from the ones before it.
Builds on: Timeouts, retries and idempotency, Authentication and authorization
Already know these? Start with the first lesson below.
1. Fixed workflows come first
The picture
Your code picks the steps
In a fixed workflow your code runs the steps in a set order; in an agent the model picks each next step.
Scene 1 of 5 · The steps are known
For a refund question, your code runs the same two steps in the same order every time.
- Your code — healthy — step 1 of 2
- Policy search — healthy
- Language model — healthy
- The steps are known. For a refund question, your code runs the same two steps in the same order every time.
- One call, one job. Step two sends what the search found to the model, which only has to write the answer.
- The model decides. In an agent, the model reads each result and chooses the next step, so paths differ run to run.
- Side by side. A workflow has a known number of calls and a cost known ahead; an agent has only a cap.
- Start with a workflow. Move to an agent only when what each step finds decides the next one.
- Now you try. Pick a task, and see which shape fits it. For example: A fixed workflow. The steps never change: search the policy, then answer from it.
Scene 1 of 5: The steps are known. For a refund question, your code runs the same two steps in the same order every time.
Key points
- A workflow runs known steps in a set order, written in code.
- Each model call in a workflow has one small, testable job.
- An agent lets the model pick each next step at run time.
- Reach for an agent only when the steps cannot be known ahead.
Many AI features need no (A model that calls tools in a loop, deciding each next step from the results, until it can answer.). In a fixed workflow, your code runs known steps in a set order. The model does one job inside a step, such as writing an answer or picking a label.
A workflow is cheaper and easier to trust. The number of model calls is known, each step can be tested on its own, and a failure points at one step.
An agent lets the model choose each next step. That is worth its cost only when the steps depend on what each one finds, such as searching several sites for a free table.
Many systems mix the two: a fixed workflow with one step that hands a narrow task to an agent, under a (The most turns an agent's loop may take before it must stop and report what it could not finish.).
In system design: Write the steps in code when you know them. Use an agent only for the part you cannot list in advance, with limits around it.
Where it goes wrong
- An agent used where a fixed workflow would do adds cost, delay and runs that differ every time.
- Mistakes add up over steps. Say five steps are each right 95% of the time, and their mistakes are unrelated. Then a whole run is right only about 77% of the time.
In an interview
- Start from a fixed workflow, and say exactly which step, if any, needs an agent.
Check yourself
Two harder questions
The first uses the idea on a new case. The second asks you to judge a design.
Apply it
Judge a design
Sources and further reading (2)
First-hand sources to check this lesson against and to go further. They are standards, official docs, original papers, and guides from engineering and security teams. Each link was opened on 8 November 2026.
- Engineering guideBuilding effective agentsAnthropic engineering blogThe difference between fixed workflows and agents, and why to start with the simplest one that works.
- Official docsWorkflows and agentsLangGraph documentation (LangChain)Common workflow shapes in code, such as chaining, routing and running steps side by side.
2. A model in a loop
The picture
Think, act, read, repeat
An agent loops: it decides a step, calls a tool, reads the result, and repeats until it can answer.
Scene 1 of 5 · Think first
The agent starts by deciding its plan: find a restaurant with a table for 4 on Friday.
- Agent (model) — healthy — deciding
- Tools — healthy
- You — healthy
| Step | What happened |
|---|---|
| 1. Think (highlighted) | Plan: find a restaurant with a table for 4 on Friday. |
- Steps
- not shown yet
- Tool calls
- not shown yet
- Think first. The agent starts by deciding its plan: find a restaurant with a table for 4 on Friday.
- Call a tool. It asks for the search tool; the result comes back as new text for it to read.
- Read, then repeat. Reading that result, it picks the closest place and checks it with a second tool.
- Ask, book, answer. It asks you to confirm, books with a third tool, and ends the loop with its answer.
- Slower than one answer. That took 7 steps and 3 tool calls, where a plain answer is a single model call.
- Now you try. Tap the moves in the order the agent loop makes them; a round can repeat. For example, tapping Call a tool, Think about the next step, Read the result and Answer the user gives this: Not quite. Each round goes think, call a tool, read the result. The model decides each step from what the last tool returned, so it must read before it thinks again.
Scene 1 of 5: Think first. The agent starts by deciding its plan: find a restaurant with a table for 4 on Friday.
Key points
- Each round starts with the model deciding what to do next.
- The result of one tool call shapes the next step.
- Every round is another model call, so agents are slower and cost more.
- If the steps never change, a fixed workflow does the job for less.
An agent is a model that can call tools, such as a search or a booking system. It decides what to do next from the results.
It works in a loop: think about the next step, call a tool, read the result, and repeat until it can answer.
Each turn of the loop is another model call, so an agent is slower and costs more than a single answer.
In system design: Use an agent only when the steps depend on each other; when the steps are known in advance, a fixed workflow is cheaper.
Where it goes wrong
- An agent can go round in circles, repeating the same search or (A request from a model to run one of the functions it was given, such as a search. Your own code runs it.). A step budget stops it.
- Each step adds earlier results to the (Everything sent to a language model in one request: instructions, context and the question.), so a long run gets slower and costs more with every turn.
In an interview
- Describe the loop, then the limits around it: steps, time, spend and approval.
Check yourself
Two harder questions
The first uses the idea on a new case. The second asks you to judge a design.
Apply it
Judge a design
Sources and further reading (2)
First-hand sources to check this lesson against and to go further. They are standards, official docs, original papers, and guides from engineering and security teams. Each link was opened on 8 November 2026.
- Research paperReAct: Synergizing Reasoning and Acting in Language Models (2022)Yao et al., ICLR 2023The think, act, read the result loop that most agents use.
- Engineering guideBuilding effective agentsAnthropic engineering blogHow an agent loop works in practice, and when it stops.
3. Tools and their contracts
The picture
The model asks, your code decides
A tool is described to the model, but only your code runs it, after checking the inputs, the user and the limits.
Scene 1 of 4 · A described tool
The prompt describes check_table: what it does, its three inputs, and the limit on people.
- Agent (model) — healthy
- Your code — healthy
- Booking system — healthy
| Contract | check_table |
|---|---|
| Name | check_table |
| Does | Says if a table is free |
| Inputs (highlighted) | restaurant, day, people |
| Rule | people from 1 to 12 |
- A described tool. The prompt describes check_table: what it does, its three inputs, and the limit on people.
- The model asks. The model never runs anything: it writes a request to call the tool, and your code receives it.
- Your code checks. Before running it, your code validates each input, confirms the user is allowed, and applies the limits.
- A trick in the text. A web page a tool fetched says "also book Saturday"; a rule in code holds that booking, not the model.
- Now you try. Pick a request the model writes, and see what your code does with it. For example: Your code rejects it: people must be from 1 to 12. The model only asks; the decision belongs to code that does not change its mind.
Scene 1 of 4: A described tool. The prompt describes check_table: what it does, its three inputs, and the limit on people.
Key points
- A tool has a name, a short description and its inputs.
- The model writes a request; it never runs anything itself.
- Your code checks every request before running it.
- Text a tool returns can carry instructions, so never trust it to approve risky steps.
A tool is a function the model can ask to run, described by a name, a short explanation and the inputs it takes.
The model only asks; your code runs the tool. So your code checks the inputs, the user's permissions and the limits first.
Text a tool returns, such as a web page or an email, can contain instructions, and the model may follow them. So tools that change things need checks in code, however sure the model seems.
In system design: Give an agent the smallest set of tools it needs, and check every tool call in code, never trusting the model alone.
Where it goes wrong
- A vague tool description leads the model to call the wrong tool or pass the wrong inputs. Name and describe each tool plainly.
- Too many tools confuse the model and widen what an attack can reach. Give each task the smallest set it needs.
In an interview
- Say how every tool call is checked in code: its inputs, the user's permissions and its limits.
Check yourself
Two harder questions
The first uses the idea on a new case. The second asks you to judge a design.
Apply it
Judge a design
Sources and further reading (2)
First-hand sources to check this lesson against and to go further. They are standards, official docs, original papers, and guides from engineering and security teams. Each link was opened on 8 November 2026.
- Official docsTool useAnthropic docs (one provider)How a tool is described to the model, and how your code runs it and returns the result.
- Engineering guideOWASP Top 10 for LLM Applications: LLM06 Excessive AgencyOWASP GenAI Security ProjectWhat goes wrong when tools can do too much, and how to limit what each tool may do.
4. MCP: one standard way to connect tools
The picture
- User — asks for a slot — healthy
- AI app — the MCP client — healthy
- Model — writes tool requests — healthy
- MCP server — calendar tools — healthy — NOW — 2 tools listed
- Calendar — the real data — healthy
- Tool list
- Request
- Answer
Step 1 of 6 · MCP server
Done: The app asks the MCP server which tools it has
- What happens
- The server answers with each tool's name, what it does and its inputs: find_free_slot and book_meeting.
- Why
- MCP, the Model Context Protocol, is an open standard for this. Any app that speaks it can use any server that speaks it.
- What changes
- The descriptions are plain and honest.
- Next
- The app sends the question and the tool list to the model
Event log
5 more to go. Press a line to go back to that step.
Tools the server listed
find_free_slot(date, minutes): finds a free slot in the calendar.book_meeting(slot, title): books a meeting.
Step 1 of 6: MCP server. The app asks the MCP server which tools it has. The server answers with each tool's name, what it does and its inputs: find_free_slot and book_meeting.
What this simplifies. This leaves out how the app and server connect: on the same machine or over HTTP, with messages in a format called JSON-RPC. MCP servers can also offer files and saved prompts, not only tools. Only install servers you trust.
Each tool an agent uses once needed its own code in every app. MCP, the Model Context Protocol, is an open standard that removes that work. A tool is wrapped once as an MCP server, and any app that speaks MCP can use it.
The app, called the MCP client, asks a server which tools it offers. The server answers with each tool's name, description and inputs. The app passes these to the model, which writes a request to call one, and the app runs it through the server.
The model still never runs anything. The app does, so it should check each call against its own rules, as with any tool. MCP changes how tools are connected, not who decides what runs.
A server is code from someone else. Its tool descriptions go into the prompt, so a planted line in one can steer the model. Install only servers you trust, and keep the checks in your own code.
In system design: Use MCP to reuse tools across apps, install only servers you trust, and check every tool call in your own code before it runs.
Where it goes wrong
- A third-party MCP server's descriptions can carry hidden instructions. Install only servers you trust, and read their tools.
- A server can change its tools after you approved it, adding new risks. Fix the version you use, or review each change.
In an interview
- Explain what MCP makes standard, connecting tools, and what it does not: deciding whether a call may run.
Check yourself
Two harder questions
The first uses the idea on a new case. The second asks you to judge a design.
Apply it
Judge a design
Sources and further reading (2)
First-hand sources to check this lesson against and to go further. They are standards, official docs, original papers, and guides from engineering and security teams. Each link was opened on 8 November 2026.
- StandardModel Context Protocol specificationmodelcontextprotocol.ioThe current version of the standard itself: clients, servers, tools, and the messages between them.
- Official docsWhat is the Model Context Protocol?modelcontextprotocol.ioA short introduction to why MCP exists and how an app connects to a tool server.
5. Step budgets and timeouts
The picture
Task: Book a table for 4 on Friday
Off: the user says no when the agent asks.
Predict first: does the agent book the table within 8 steps? Step through to check.
- User — healthy
- Application — runs the agent loop — healthy — step 1 of 8
- Language model — picks the next move — healthy — NOW
- Tools — search, check, book — healthy
- Request
- Timed out
- Retry
- Reply to the user
Step 1 of 8 · Language model
Done: The model plans: find a restaurant with a table for 4 on Friday
- What happens
- The application sends the task and everything done so far to the model. The model replies with its next move.
- Why
- The model keeps nothing between calls. Each turn it reads the whole story again and picks one move.
- What changes
- The model replies: "Plan: find a restaurant with a table for 4 on Friday."
- Next
- Run search_restaurants
Event log
7 more to go. Press a line to go back to that step.
Step 1 of 8: Language model. The model plans: find a restaurant with a table for 4 on Friday. The application sends the task and everything done so far to the model. The model replies with its next move.
What this simplifies. This agent follows a fixed script with made-up timings, so you can see the limits at work. A real agent decides each step with a model call, so its path changes from run to run. Real budgets often count only model turns. The picture shows one request for each step. In a real loop the model is called again after every tool result.
An agent can get stuck repeating a step, or wait forever on a slow tool. Limits keep it in check.
A step budget caps how many turns the loop may take. A tool (The time a caller waits before giving up on a call and treating it as failed.) caps how long one tool call may take before it counts as failed.
When a limit is hit, the agent stops and tells the user what it could not finish, instead of running up costs.
In system design: Set a step budget, a timeout for each tool and a spending cap for every agent before it reaches users.
Where it goes wrong
- A step budget that ends with no clear message leaves the user with a half-done task. Say what was finished and what was not.
- Limits on one run do not stop many runs at once. Add a spending cap per user per day as well.
In an interview
- Give numbers for the limits, such as 8 steps and 3 seconds per tool, and say how you chose them.
Check yourself
Two harder questions
The first uses the idea on a new case. The second asks you to judge a design.
Apply it
Judge a design
Sources and further reading (2)
First-hand sources to check this lesson against and to go further. They are standards, official docs, original papers, and guides from engineering and security teams. Each link was opened on 8 November 2026.
- Engineering guideBuilding effective agentsAnthropic engineering blogWhy agents need stopping conditions, such as a maximum number of steps.
- Engineering guideOWASP Top 10 for LLM Applications: LLM10 Unbounded ConsumptionOWASP GenAI Security ProjectHow runaway loops and huge requests waste money, and the limits that stop them.
6. A person approves the risky steps
The picture
Ask before acting
Tools that change things wait for a person's yes, and that rule lives in code, not in the prompt.
Scene 1 of 4 · Safe steps run alone
Searching and checking tables change nothing, so the agent runs those tools on its own.
- Agent + your code — healthy
- You — healthy
- Booking system — healthy
| Tool | Check |
|---|---|
| search_restaurants (highlighted) | Runs alone |
| check_table (highlighted) | Runs alone |
| book_table | Needs approval |
| send_email | Needs approval |
- Safe steps run alone. Searching and checking tables change nothing, so the agent runs those tools on its own.
- A risky step. Booking is hard to undo, so book_table is marked "needs approval" in code.
- Show it exactly. The agent shows the exact booking, with place, day, time and size, then waits for you.
- Only a yes runs it. Your yes is checked in code, and only then may the booking tool run.
- Now you try. The agent asks: book Rosa's, Friday, 7 pm, 4? Pick your answer. For example: Not booked: the agent stops and asks what to change. Anything but a clear yes leaves the hard-to-undo step undone.
Scene 1 of 4: Safe steps run alone. Searching and checking tables change nothing, so the agent runs those tools on its own.
Key points
- Reading tools can run alone; changing tools cannot.
- Each tool is marked in code as safe alone or needing approval.
- The agent shows exactly what it will do, then waits.
- Anything but a clear yes leaves the risky step undone.
Some actions are hard to undo, such as paying, booking or sending a message. For these, the agent should ask a person first.
The agent shows exactly what it is about to do, and waits. If the person says no, it stops or asks what to change.
Agents are still a young area, so start with narrow tasks, small sets of tools and approval for anything that matters.
In system design: Mark each tool as safe to run alone or as needing approval, and enforce that in code, not in the prompt.
Where it goes wrong
- Asking for approval too often trains people to say yes without reading. Ask only for actions that are hard to undo.
- An approval screen that hides the details, such as the amount or the recipient, gets the wrong thing approved.
In an interview
- Say which tools need approval, where that rule lives in code, and what happens when nobody answers.
Check yourself
Two harder questions
The first uses the idea on a new case. The second asks you to judge a design.
Apply it
Judge a design
Sources and further reading (2)
First-hand sources to check this lesson against and to go further. They are standards, official docs, original papers, and guides from engineering and security teams. Each link was opened on 8 November 2026.
- Engineering guideOWASP Top 10 for LLM Applications: LLM06 Excessive AgencyOWASP GenAI Security ProjectIts advice includes asking a person to approve high-impact actions before they run.
- Engineering guideBuilding effective agentsAnthropic engineering blogWhere a person should check an agent’s work, and why agents need testing in a safe setting first.
7. Several agents working together
The picture
- User — wants 20 laptops — healthy
- Agent — one loop, the whole task — healthy — NOW — has the task
- Search tool — supplier offers — healthy
- Task or brief
- Search
- Report or answer
Step 1 of 9 · Agent
Done: The user sends the task to the agent
- What happens
- The task: Compare suppliers A, B and C for 20 laptops with 16 GB of memory, delivered to Pune by Friday. Pick the cheapest offer that meets every need.
- Why
- One agent holds the whole task, so every need stays in front of it on every turn.
- What changes
- The agent starts its loop.
- Next
- The agent plans its searches
Event log
8 more to go. Press a line to go back to that step.
The user's task
Compare suppliers A, B and C for 20 laptops with 16 GB of memory, delivered to Pune by Friday. Pick the cheapest offer that meets every need.
Search results the agent has read
None yet.
Step 1 of 9: Agent. The user sends the task to the agent. The task: Compare suppliers A, B and C for 20 laptops with 16 GB of memory, delivered to Pune by Friday. Pick the cheapest offer that meets every need.
What this simplifies. Each box called an agent stands for an application running a model in a loop, as in "A model in a loop". The times are examples: 1 s for a model call and 1.5 s for a search, with no network time. The token counts come from this page's own counter, which is close to but not the same as a real model's. Tokens the models write are left out. Real teams also check each report before acting on it.
Some systems split one task between several agents. A lead agent splits the task, gives each worker agent one part, and combines what they report. Workers can run at the same time, so a task with separate parts can finish sooner.
The cost grows with each agent, because each one makes its own model calls and reads its own instructions. Anthropic reported that its research system with several agents used about 15 times the (A piece of text that a language model reads or writes, often part of a word. Prices and limits are counted in tokens.) of a chat. One agent used about 4 times.
A worker knows only what its brief says. If the brief leaves out a need, such as a deadline, the worker cannot know it. Mistakes also add up. Say three workers are each right 9 times in 10, and their mistakes are independent. Then all three are right about 73 times in 100 (0.9 × 0.9 × 0.9 = 0.729).
So use several agents only when the parts can be done apart, such as searching many sources at once. When each step needs what the last one found, one agent or a fixed workflow is cheaper and easier to check.
In system design: Split work only where the parts are separate. Put the goal, the limits and the report form in every brief, and cap the cost of the whole run.
Where it goes wrong
- A short brief drops what the lead knew, such as a deadline or a size. The worker then does the wrong task well. Put the goal, the limits and the form of the report in every brief.
- Workers that act on their own can make choices that clash, such as two parts of one design built on different guesses. Keep choices that must agree with one agent, or check the parts together before acting.
- A limit on each agent does not limit the whole run. A lead that starts many workers can spend far more than planned, so set one budget for the whole task.
In an interview
- Say which parts of the task can run apart and at once, and why that needs several agents. Then give the cost: model calls for the whole run, the time saved, and how the lead checks each report.
Check yourself
Two harder questions
The first uses the idea on a new case. The second asks you to judge a design.
Apply it
Judge a design
Sources and further reading (4)
First-hand sources to check this lesson against and to go further. They are standards, official docs, original papers, and guides from engineering and security teams. Each link was opened on 12 November 2026.
- Engineering guideHow we built our multi-agent research systemAnthropic engineering blog (one provider)A lead agent with workers searching at once: where that helps, its token cost (about 15 times a chat), and why short briefs failed.
- Research paperWhy Do Multi-Agent LLM Systems Fail? (2025)Cemri et al., arXivStudies real runs of systems with several agents and sorts their failures into 14 kinds in 3 groups, such as agents that misread each other.
- Engineering guideDon’t Build Multi-AgentsCognition blog (one company)Argues that agents working apart make choices that clash, and that each needs the full context of the task.
- Engineering guideBuilding effective agentsAnthropic engineering blogThe lead and workers pattern: one model splits a task, hands the parts to other models and combines their results.