By Abhijith N M · Reviewed 24 October 2026 · Editorial standards
An engineer asks the internal assistant where payment retries happen. The agent globs a monorepo, reads eleven whole files, and answers after three and a half minutes for 8.90 USD. Two of its three citations point at files deleted last quarter.
The assistant trusted a code-search MCP server whose index ran three hours behind the repository. It never confirmed a hit against the live tree, and it paid for whole files when a 40-line window would have answered the question.
This is scenario 4 of the six published scenarios. Production goal: an Agent SDK tool that helps engineers explore a large codebase with the built-in tools and with MCP servers for data that lives outside the repository. Hard constraint: exploration is read-only, every answer cites a path and a line range that exists now, and one question has a fixed budget.
The built-in tools are the six the Agent SDK ships with: Glob for paths, Grep for content, Read for a line range, Edit and Write for changes, and Bash for everything else. They read the working tree, so they cannot be stale.
Narrow first, confirm second, answer third. The order is the whole design: a cheap content search removes most of the candidate files before any file is read.
Note the budget in that design. A read budget of six windows keeps a vague question from turning into a nine-dollar tour, and it forces the agent to narrow before it reads.
Most wasted cost in this scenario comes from using the wrong tool for the shape of the question. The pairing is mechanical.
| The question | The tool | Why that one |
|---|---|---|
| Which file implements retries? | Grep | You know the symbol, not the path |
| Where does the billing module live? | Glob | You know the name shape, not the path |
| What does this function return? | Read with offset and limit | You need a window, not a file |
| Which ticket mentions this error? | An MCP server | The data lives outside the repository |
| Run the retry unit test | Bash, from an allow-list | It changes the machine, so scope it |
One request, end to end: the agent greps for retry_payment, gets two paths, reads 40 lines around the match in each, and confirms that one of the two no longer exists. It drops that hit, answers from the file it read, and cites one path with a line range. Total cost is one search and two short reads.
"""Read-only exploration with a read budget and a citation check."""
from __future__ import annotations
BUDGET = {"max_reads": 4, "max_lines": 80}
LIVE_TREE = {
"billing/retry.py": [
"MAX_ATTEMPTS = 3",
"",
"def retry_payment(order):",
" while order.attempts < MAX_ATTEMPTS:",
" ...",
],
}
# A code-search index that ran three hours behind the repository.
INDEX_HITS = ["billing/retry.py", "billing/old_retry.py"]
def read_window(path, start, end):
"""Read a line range, not a whole file."""
lines = LIVE_TREE.get(path)
if lines is None:
return {"error": {"code": "file_not_found", "path": path}}
return {"path": path, "lines": lines[start - 1 : end]}
def confirm(path, budget):
"""A citation exists only if the live tree still has the lines."""
window = read_window(path, 1, budget["max_lines"])
if "error" in window:
return {"path": path, "status": "stale", "code": window["error"]["code"]}
return {"path": path, "status": "confirmed", "lines": len(window["lines"])}
reads = 0
for hit in INDEX_HITS:
if reads >= BUDGET["max_reads"]:
print({"status": "budget_exhausted"})
break
reads += 1
print(confirm(hit, BUDGET))| The decision | The best answer | What it costs you |
|---|---|---|
| The source of truth for a citation | The live tree, confirmed by Read or Grep | One extra turn to confirm what an index claimed to know |
| The permission mode for exploration | Read-only, with a separate narrow write path | The tool cannot finish a fix, so it hands off |
The wrong answer is usually a shortcut in the first row: trust the index because it is faster. An index that lags by three hours is fine for a hint and wrong for a citation. The second row is where incidents come from: an exploration agent with write access inherits every permission the parent had.
Asked to find a flaky test, the agent notices the cause and edits a config file. Exploration turns into a change, the transcript records fixed, and a reviewer merges it because the diff is small and plausible.
The control is the permission mode plus a hard tool list: permissionMode set to read-only and allowedTools limited to Glob, Grep and Read. A fix is a handoff to a session with Edit and an approval step, not a side effect of a search.
Grep, Glob, Read, Bash or an MCP server should answer it, and write the one-line reason.Key takeaways
Narrow before you read: a content search removes most candidate files for free.
The live tree is the source of truth for a citation; an MCP index is only a lead.
Read a line range with offset and limit instead of whole files.
Keep exploration read-only with an explicit tool list, and hand off any fix.
A read budget turns a vague question into a bounded one.
Written and edited by the nexGenCoders team. Spotted a mistake? Tell us and we will fix it.
Don't lose this lesson
Create a free account to save your progress, keep your streak, and work toward a shareable certificate.