Sub topic 5
Custom agents: a specialist with its own setup
This chapter assumes you have used an AI coding assistant, can read Markdown with YAML frontmatter, and know that a context window is the limited amount of text the model can consider at once. Field names below are illustrative. Check your tool's documentation for its exact schema.
What a custom agent is
A custom agent is a saved configuration for a specialist. It bundles a role prompt, a set of allowed tools, and often a description of when to use it. When you start it, the assistant runs with that setup instead of its general-purpose defaults.
A prompt file is a single saved request. A custom agent is a standing setup. Prompt files answer "do this task". Agents answer "act as this specialist, with these limits".
Why a separate setup helps
Three problems push people toward custom agents:
- Focus. A general agent carries every instruction you gave it. A reviewer needs review rules, not deployment steps.
- Safety. A reviewer should not edit files. A tool list can enforce that, while a sentence in a prompt only asks for it.
- Context. In many tools, an agent runs in its own context window. Its long searches and file reads stay out of your main conversation, and you get back a summary.
Anatomy of an agent file
Many tools define an agent as a Markdown file with frontmatter. The frontmatter holds metadata and the body holds the role prompt.
---
name: code-reviewer
description: Reviews code changes for correctness, readability, and test coverage. Use after code has been modified.
tools: Read, Grep, Glob
---
You are a careful code reviewer.
When invoked:
1. Inspect the recent changes.
2. Check correctness first, then readability, then test coverage.
3. Report findings grouped by severity, each with a concrete suggestion.
You only read code. Never modify files.Each part has a job:
| Part | Purpose |
|---|---|
| `name` | The identifier you or the tool uses to select the agent |
| `description` | Tells the tool, and sometimes the main agent, when to use it |
| `tools` | The allowlist of what the agent can do |
| Body | The role and procedure the agent follows |
Some tools use JSON instead. The idea is the same:
{
"name": "docs-writer",
"description": "Writes and updates project documentation",
"prompt": "You write concise technical documentation. Match the existing style in the docs folder.",
"tools": ["fs_read", "fs_write"]
}Here the prompt field holds the role text, and tools lists tool names that are specific to that product.
How an agent runs
Tools differ in how agents start. Some let you pick one explicitly. Some delegate automatically when the task matches the description. Some support both.
Common mistakes
- Vague descriptions. If the description says "helps with code", the tool cannot tell when to use the agent. Name the task and the trigger.
- A role that tries to do everything. An agent that reviews, refactors, and deploys has no focus left. Split it.
- Prose-only restrictions. "Never modify files" is a request. Leaving out write tools is a control. Use both, and rely on the second.
- Copying fields between tools. Names such as
toolsand the tool identifiers differ by product. Wrong names may be ignored silently, which can leave the agent with more access than you intended.
Exercise
A teammate wants an agent that audits dependencies and must never change the repository. They write "Do not edit files" in the prompt and give the agent every tool. What is wrong, and what would you change?
Show answer
The restriction exists only as text, so the model could still edit files if it ignored or misread the instruction. Remove the write and execute tools from the allowlist, keeping only read-style tools, and keep the sentence as a reminder. Also give the agent a specific description, such as "Audits dependency manifests for outdated or vulnerable packages", so the tool knows when to select it.