Module 3 · Chapter 3: The first agent
A first agent that only reads
In short
A first agent should only search and read, work on copies with no secret files, and carry turn, budget and adequate output limits from its very first run.
After this lesson you can
- Build a first agent that may only read
- Set turn and budget limits from the very first run
Terms in this lesson
Understand
Your first agent should only be able to read. Not because writing is hard, but because a read-only agent teaches every important lesson at the lowest risk: you learn to write a goal, watch how the model picks tools, read its trace and count its cost, with nothing that can break.
Good tasks for a first read-only agent: building a list of decisions from a pile of minutes, finding every place a term is used in project documents, or explaining how a code folder is organised. Each needs several turns, because the agent must search, open and then read files based on what it finds. That is why the task suits an agent rather than a single prompt.
For a read-only agent, three kinds of tool are enough: find files by name, search text inside files, and read a file's content. No tool to write, run commands, open the internet or start a subagent (a second agent the main agent calls). Each extra tool is an extra capability you must watch, so do not grant one without a reason.
Place the agent in the sandbox from chapter two: a folder of document copies, on a machine or container that holds no secret files. Remember, a read-only agent can still leak: whatever it reads enters the context, is recorded in the trace and is sent to the model provider. If that folder holds a file with keys or passwords, reading alone is enough to spread it.
Limits go in from the very first run, not after something goes wrong. There are three different limits, and all three are needed:
- Turn limit: the maximum number of cycles of the model picking a tool and reading the result. For summarising one small folder, ten to fifteen turns is usually enough. If the limit is reached, that signals an unclear goal or an oversized task, not a reason to raise the limit.
- Budget limit: the maximum cost of one task in money. This protects you from a loop that keeps reading large files.
- Output limit: the maximum number of tokens the model may write in one answer. Do not set it too low: reasoning models spend part of this budget thinking, and a limit that is too tight can produce empty answers.
Besides limits, set a checkable goal and a result shape before running: for example "a list of decisions, one line per decision, with its source file name". A shape that names sources lets you check each line against its file. Without it, you can only trust.
A step specific to Anthropic: check the latest version.
As a worked example, here is a read-only agent with the Claude Agent SDK for Python (package claude-agent-sdk). tools makes only three read tools available, allowed_tools lets them run without asking, and permission_mode="dontAsk" refuses any other call that would ask. Without tools, dontAsk alone still lets through calls that need no approval, such as read-only shell commands and starting a subagent. The max_turns and max_budget_usd options set the turn and budget limits, and cwd sets the working folder:
import asyncio
from claude_agent_sdk import query, ClaudeAgentOptions, ResultMessage
async def main():
options = ClaudeAgentOptions(
tools=["Read", "Glob", "Grep"],
allowed_tools=["Read", "Glob", "Grep"],
permission_mode="dontAsk",
max_turns=12,
max_budget_usd=0.50,
cwd="minutes-copy",
)
tugas = "I need a list of decisions from the minutes in this folder, with the source file name for each decision."
async for message in query(prompt=tugas, options=options):
if isinstance(message, ResultMessage):
print(message.result)
print("cost", message.total_cost_usd, "turns", message.num_turns)
asyncio.run(main())The last message from query() is a ResultMessage holding the final result, the cost estimate and the number of turns. The working folder is not a wall: run this example on a machine or container that holds only the document copies. A step specific to Anthropic; check the latest version in its documentation, because option names can change.
Before
The prompt
Read every document in the team drive and tell me what is important.
What came back
Bad example output: the model invented these figures and references, do not use them: I read 312 documents. Important points: the budget rose 18 percent, the warehouse project slipped two months, and there are three main risks. Further detail is available if needed.
After
The prompt
Goal: I need a list of this month's project meeting decisions. Material: only the folder of minutes copies I prepared; the agent may only search and read. Limits: at most 12 turns; do not infer decisions that are not written in the minutes. Shape: one line per decision: decision, meeting date, source file name. Check: flag decisions that contradict each other across minutes.
What came back
A list of decisions, one line per decision with its meeting date and minutes file name. One line is flagged: two sets of minutes record different deadlines for the same task. The agent stopped at turn nine.
What changed
- The first request gives access to the whole drive and asks for no sources, so the figures in its result cannot be checked.
- The second limits the material to one folder of copies, sets a turn limit and asks for a file name on every line.
- The contradiction flag is the most useful thing for a person to check.
Common mistake
- Mistake
- Running a first agent without turn and budget limits "to see how far it can go".
- Why it hurts
- An agent with a vague goal keeps opening files, and every turn resends a growing context. Cost rises faster than you expect, and the result is no better.
- Do this instead
- Set small turn and budget limits from the first run. If a limit is reached, sharpen the goal or split the task, then run again.
Try
Your first agent's task is to list decisions from minutes. Which set of tools fits?
Sorting card
Match each problem with the limit that prevents it.
A reasoning model returns an empty answer
One task rereads very large files and its cost spikes
The agent keeps opening new files without ever concluding
The agent repeats the same search ten times
The agent runs every night and its bill is unpredictable
5 cards left
Take home
Your first read-only agent
- Its tools only search and read
- It works on copies, in a place without secret files
- Turn and budget limits are set from the start
- The output limit is loose enough for a reasoning model
- The result shape asks for a source on every line
What went wrong for us
Infrastructure plan files are not committed
- Context
- When infrastructure is managed as code, the tool writes plan files before changes are applied. They feel like temporary output.
- What tends to go wrong
- Plan files can hold the secrets fed to the tool, such as passwords and tokens, in plain text. If they are committed, those secrets enter the git history.
- What it costs if ignored
- Anyone who can read the repository, now or later, can read those secrets. Deleting the file in a later commit does not remove it from history.
- Root cause
- Git ignore patterns are written for files people already know about, and tool output is rarely inspected.
- How we do it
- Plan files are in the git ignore list and never committed. If a secret ever enters the history, we revoke and rotate it at once, then clean the history.
- The rule we keep
- Secrets are never written to files git tracks, and the ignore list covers all infrastructure tool output.
The lessonTool output can hold the secrets you fed in; check it before you store it.
What it means for your workOutput files and notes can hold passwords or personal data you once entered. Check what is in them before saving or sharing.
Sources
- Agent SDK docs: Python reference (accessed 26 October 2026)
