Skip to content
mentoor

Topic 2 of 5 · 5 min read

Defining a subagent's role, tools and model

Goal: Write or fix a subagent definition so its role is narrow, its tools are the minimum it needs and its output format is something the caller can check.

A good subagent definition is a job description: one narrow role, only the tools that role needs, a model matched to the difficulty, and a fixed shape for the answer.

Check yourself · 1 of 3

Which tool list fits a subagent whose only job is to review a diff?

Choose one answer

Why it matters

In tools such as Claude Code and VS Code custom agents, a subagent is a file, usually Markdown with a short header. The parent reads its description to decide when to hand work over, and the body becomes the subagent's instructions. A vague file gives vague delegation: the parent calls it at the wrong time, or the subagent wanders.

The parts

  1. Name and description. The description is a trigger, not a slogan. Say when to use it: "Use after any change to files under src/ to review the diff for bugs. Read-only."
  2. A narrow role. One job. A "helper that reviews, fixes and deploys" cannot be trusted at any of them.
  3. A tool allow-list. Give the minimum. A reviewer needs read, grep and git diff, not edit or shell. Fewer tools means fewer ways to do damage and fewer distractions.
  4. A model. Search and summarising often run well on a small, fast model. Review of subtle logic may need a stronger one. Choose per role and check the result, not by habit.
  5. An output contract. Tell it exactly what to return, so the parent can check it: a verdict, a list of findings with path:line, and what was not checked.

Before and after

Weak:

---
name: helper
description: Helps with code
tools: all
---
Look at the code and do whatever is needed to make it better.

Fixed:

---
name: diff-reviewer
description: Use after code changes to review the current git diff for bugs and missing tests. Read-only.
tools: Read, Grep, Glob, Bash(git diff:*)
model: sonnet
---
You review the diff against the task you were given. Do not edit files.
Return a list of findings. Each finding: file:line, what is wrong, why it matters.
End with "Not checked:" and list anything you could not verify.

The exact header fields differ by tool, so read your tool's docs. The idea carries over.

What goes wrong

  • All tools by default. A "researcher" with edit and shell access will sooner or later change something.
  • Description too broad. The parent calls it for everything, or never.
  • No output contract. The report comes back as a friendly paragraph the parent cannot check.
  • Costly model everywhere. Paying for the strongest model on a file-listing job wastes budget; the cheap model on a security review can miss real issues.

Examples

A read-only explorer

---
name: code-explorer
description: Use to find where something is implemented. Returns paths and a one-line note. Read-only.
tools: Read, Grep, Glob
model: haiku
---
Search the repository for the thing named in the brief.
Return at most 10 results as `path:line - note`. Do not paste file contents.

The small model is enough for search, and the 10-result cap keeps the report short.

Fixing a bad description

Before: description: Reviews things. After: description: Use after finishing a feature, before opening a PR, to review the diff for bugs, missing tests and unrelated changes. The parent now knows the moment to call it.

Key points

  • The description decides when the parent delegates, so it should say when to use the subagent.
  • Give a subagent the fewest tools its role needs; read-only roles should have no edit tools.
  • Pick the model per role and verify the output quality instead of using one model for everything.
  • An output contract such as findings with path and line makes the report checkable.
  • One narrow job per subagent works better than one agent that does everything.

Common mistakes

  • Granting every tool because it is the default.
  • Writing a description that names the topic but not when to use the subagent.
  • Leaving the return format open, so reports cannot be compared or checked.
  • Combining review and fixing in one subagent, so it grades its own work.

Check yourself · 2 of 3

A subagent file says: description: Helps with code. The parent almost never calls it. What is the best fix?

Choose one answer

Check yourself · 3 of 3

Why add an output contract such as "findings as path:line plus a Not checked list"?

Choose one answer

Practice items, not counted towards your mastery.

Start here