Skip to main content

Read-only Tools and Tools That Change Things

Why This Matters

Reading a log is harmless. Filing a bug, commenting on a pull request or quarantining a test is not. The difference between those two kinds of tool decides how much you can let the loop run on its own, and it is a favourite exam theme.

Sort the toolbox

ToolKindWorst case if called wrongly
get_test_historyreadSome wasted tokens
read_logreadSome wasted tokens
get_commit_diffreadSome wasted tokens
search_issuesreadSome wasted tokens
create_issuewriteNoise for developers, duplicates, lost trust

Read-only tools can run freely inside the loop. Write tools need controls.

Least privilege lives in the credentials

A description that says “only file bugs in project QA” is a request. What actually limits the damage is the token behind the tool:

  • the issue tracker token can only create issues in the QA project, nothing else
  • the log tool’s credentials can read CI logs, not change pipelines
  • no tool has access to secrets, production data or other repositories

If the model is ever tricked into calling a tool with bad input (module 7), the credentials decide how bad it gets.

A confirmation step in code

TestPilot never calls create_issue directly from the loop. Instead, the tool returns a proposal, and your code decides:

async function createIssue(input: IssueInput, ctx: Context) {
  if (!ctx.approved.has(proposalKey(input))) {
    ctx.proposals.push(input);
    return { status: "proposed", note: "A human will review this proposal. Do not retry." };
  }
  return tracker.create(input);
}

In the nightly job, proposals end up in the report for a tester to approve with one click. In an interactive session, the person approves on the spot.

Idempotency

The loop may call create_issue twice for the same failure, for example after a retry. Make the tool safe to repeat:

  • compute a key from the test id and the error signature
  • search for an existing issue with that key before creating one
  • if it exists, add a comment instead of a new ticket

Log every write

Every write records who (which run, which agent), what (the full input) and why (the evidence that led to it). When a developer asks “why did TestPilot file this?”, the answer is one lookup away (lesson 60).

Exercise

Implement create_issue as a proposal-only tool with an idempotency key. Write a test where the model calls it twice for the same failure and check that only one proposal exists.

Compare with solution/lesson-31-mcp-server, which covers lessons 24–31 (see docs/exercises.md, module 4).