Sub topic 2
Writing Focused Agent Roles and Instructions
Assume you already understand prompts, Markdown, YAML frontmatter, basic Git, and how to use an AI coding agent. This chapter focuses on defining a specialist agent and loading extra capabilities only when needed.
Focus the role and instructions
A custom agent is an agent configuration with a specific role, instructions, and usually a restricted tool set. Give it one clear job. State what it should inspect, what order to follow, and what its response must contain.
---
name: code-reviewer
description: Reviews code changes for correctness and test coverage.
tools: Read, Grep, Glob
---
You are a careful code reviewer.
When invoked:
1. Inspect the recent changes.
2. Check correctness, then readability, then test coverage.
3. Report findings grouped by severity.
4. Include a file reference and a concrete suggestion for each finding.
Never modify files.The exact field names differ between products. Check your agent framework before copying the frontmatter.
Limit tools and permissions
Tool scoping limits what an agent can do. A read-only reviewer needs file-reading and search tools, but not file-writing, shell, deployment, or database tools. Narrow permissions reduce accidental changes and limit the impact of unsafe instructions in repository content.
Load skills on demand
An agent skill is a reusable capability that an agent can load when a task matches its description. Unlike a permanently large system prompt, a skill can keep detailed instructions and resources outside the initial context.
Structure a skill
A skill folder commonly contains SKILL.md, reference material, and scripts:
changelog-entry/
├── SKILL.md
├── reference/
│ └── format.md
└── scripts/
└── check_format.pySKILL.md is the entry point. Its frontmatter should identify the skill and describe when to use it. Keep the main instructions short. Put detailed rules in reference files and repeatable checks in scripts.
---
name: changelog-entry
description: Writes changelog entries when a user asks to add or update release notes.
---
# Changelog entry
1. Read the latest entries to match their format.
2. Group changes under Added, Changed, Fixed, or Removed.
3. Use the project's tense and include issue numbers when known.
For full formatting rules, read reference/format.md.Write descriptions that get selected
A description is a routing signal. Name the task, the expected output, and useful trigger phrases. Avoid vague descriptions such as “helps with documentation.” Test the description with real requests, then revise it when the skill is selected too often or not often enough.
Exercise
Which change best improves a code-review agent's safety?
Show answer
Remove file-writing and shell tools from its allowed tool set, then keep its role instructions read-only.