MSBA-370 · Lesson 9 of 12 · 19 min
Custom agents and instructions
▶ Video coming soon A video version of this lesson is on the way.
Lena's first cloud agent pull request in the trail-units repository was technically correct and stylistically foreign. It used a different test runner style from the rest of the repository, forgot to rebuild the bundled dist folder that the action actually runs, and wrote a commit message in a format nobody at Tidewater used. None of that was the agent's fault. Nobody had told it. The ninth session was about telling agents things once, in files, so that every session starts with the team's knowledge: custom instructions, AGENTS.md, prompt files and custom agents.
The GH-600 outline lists agent customization through "custom instructions, custom agents, tools and Copilot setup steps" as recommended experience, and its tuning skills ask candidates to revise instructions, workflows and constraints when evaluation shows a problem. MSBA-304 introduced instruction files for everyday Copilot use; this lesson treats them as part of agent design.
The instruction files
Copilot reads several kinds of instruction file, and each has a different scope. Repository custom instructions live in .github/copilot-instructions.md and apply to every Copilot request in the repository. Path-specific instructions live in files ending .instructions.md under .github/instructions, each with a front matter field naming the files it applies to, so that test files, documentation and workflow files can each have their own rules. AGENTS.md is an open convention, shared by several agent products, for a file that tells agents how to build, test and work in a project; Copilot's agents read it, and in a repository with several projects the nearest AGENTS.md to the files being changed applies. Organizations on Business and Enterprise can also set organization instructions, and individuals can set personal instructions.
| File or setting | Scope | Good for |
|---|---|---|
| .github/copilot-instructions.md | Whole repository | Project summary, build and test commands, conventions |
| .github/instructions/*.instructions.md | Files matching a pattern | Rules for tests, docs, workflows or one language |
| AGENTS.md | The folder it is in and below | Agent-oriented build, test and done criteria; shared with other agent tools |
| Organization instructions | All repositories in the organization | Company-wide rules, such as security requirements |
| Personal instructions | One user's requests | Personal preferences such as explanation style |
---
applyTo: "test/**/*.test.js"
---
# Test conventions
- Use the built-in node:test runner and node:assert/strict; do not add Jest or Mocha.
- One describe block per exported function; name tests "converts X to Y" or "rejects ...".
- Never change an existing test to make it pass. If an existing test looks wrong, stop and explain why in the pull request.
- Run npm test before finishing.Writing instructions that work
Instructions are part of every prompt, so they compete with the task for the model's attention and use context. Good instruction files are short, specific and checkable. They say how to build and test, what "done" means, which conventions are non-negotiable and which actions are forbidden. They do not repeat what the code already makes obvious, describe the history of the project or contain long style essays. GitHub's guidance is to keep repository instructions focused, and to move rules that only apply to some files into path-specific files.
# AGENTS.md for trail-units
## Build and test
- Install: npm ci
- Test: npm test
- Build the action bundle: npm run build (writes dist/index.js; commit it)
## Done means
- npm test passes and dist/ is rebuilt and committed
- action.yml inputs and README stay in sync
- No new runtime dependencies without a note in the pull request
## Do not
- Change action.yml input names (they are public)
- Edit files under dist/ by hand
- Change existing tests to make them passAfter Dmitri committed that file, the next three agent pull requests rebuilt the bundle without being asked. That is the cheapest tuning there is: one file, read by every session.
Prompt files
Prompt files are reusable prompts stored in the repository, in files ending .prompt.md under .github/prompts, which a person can run by name in supported editors. They suit tasks the team asks for repeatedly, such as "write release notes from merged pull requests" or "add a new unit to the conversion table", and they keep the wording of a good prompt from being lost in someone's chat history. A prompt file can say which tools it needs and which mode it should run in.
Custom agents
A custom agent is a named, specialized agent defined by a Markdown file with front matter. GitHub introduced custom agents for Copilot in late 2025. In a repository they live in .github/agents, with file names that GitHub's examples end in .agent.md. The front matter gives the agent a name and a description, which people see when choosing an agent, and can list the tools it may use and the MCP servers it needs; the body is the agent's instructions. When someone starts a cloud agent session, an agent mode conversation or a Copilot CLI session, they can choose a custom agent instead of the default one, and it brings its own instructions and tool limits.
---
name: test-writer
description: Writes missing unit tests for code that already exists. Does not change source files.
tools: ["read", "search", "edit", "shell"]
---
You write tests for code that already exists in this repository.
- Read the source file and its existing tests first.
- Add tests only under test/. Never edit files under src/ or dist/.
- Follow .github/instructions/tests.instructions.md.
- Cover normal cases, boundaries (zero, very large values) and invalid input.
- Run npm test. If a new test fails because the source looks wrong, keep the test,
mark it with test.todo, and explain the suspected bug in the pull request.Custom agents are a direct way to apply least privilege from lesson 7 and fewer-tools advice from lesson 4. The test-writer agent cannot push, deploy or call external services, because those tools are not on its list, and its instructions forbid changing source files. A reviewer agent might have only read tools. A documentation agent might be allowed to edit only Markdown files. Seraphine described Skerry's set: a dependency-upgrade agent, a test-writer, an accessibility checker and an internal API migration agent, each with its own tools and instructions.
Organization and enterprise agents
Custom agents can also be shared beyond one repository. GitHub supports organization and enterprise custom agents defined in a designated repository, and its February 2026 enterprise AI controls announcement describes applying enterprise-wide agent definitions from the canonical .github-private/agents path, plus a push rule that can protect agent files in .github/agents from unreviewed edits. That protection matters: an agent definition is effectively a set of permissions and instructions, so a change to it deserves the same review as a change to a workflow file.
Worked problem
Tuning with instructions
Over two weeks, three cloud agent pull requests in TrailCheck each added a new npm package for something the standard library already did. Lena wants to stop this without banning dependencies. Which file should change, and how?
Show solution
- The problem applies to the whole repository, so AGENTS.md or copilot-instructions.md is the right place.
- Add a rule: prefer the Node standard library; do not add a runtime dependency unless the task requires it, and if you do, explain why in the pull request.
- Keep dependency review and human review as the enforcement, because instructions guide but do not guarantee.
- Check the next few agent pull requests to see whether the rule worked, which is the evaluation loop MSBA-371 develops.
Instructions are guidance, not enforcement
The most important limit of everything in this lesson is that instructions are text in a prompt. A model usually follows them and sometimes does not. Rules that must always hold belong in deterministic controls: rulesets that block pushes to protected paths, required checks, dependency review, tool lists, firewall rules and human review. Instructions make good behavior likely; controls make bad behavior impossible or visible. Tidewater's AGENTS.md said not to edit dist by hand, and a required check also rebuilt the bundle and failed if dist did not match.
How instructions combine
In a single request several instruction sources may apply at once: personal instructions, repository instructions, any path-specific files matching the files involved, the nearest AGENTS.md, a custom agent's instructions and the task itself. Copilot combines them rather than choosing one. That is convenient and occasionally confusing, because two sources can disagree. GitHub's documentation describes the sources and their scope but advises against relying on precedence between conflicting instructions, so the practical rule is to avoid conflicts: say each thing once, in the narrowest file that covers it.
| Rule | Best place for it |
|---|---|
| How to build and test the project | AGENTS.md or repository instructions |
| Test style and test runner | Path-specific file for test files |
| Never edit generated files | AGENTS.md, backed by a required check |
| Company security requirements | Organization instructions, backed by rulesets |
| Only edit tests | The test-writer custom agent |
| Explain answers briefly | Personal instructions |
Testing instructions
Instructions are a kind of code, and they can be tested in a simple way. After changing an instruction file, run a few representative tasks and check whether the behavior changed as intended. Dmitri kept three small tasks for trail-units for this purpose: add a unit, fix a deliberately broken conversion, and write tests for a helper. After each change to AGENTS.md or the test instructions he ran them with the cloud agent and read the results. When a change made results worse, he reverted it. That small habit is the beginning of the evaluation discipline that MSBA-371 develops.
Instructions in pull request review
Instruction files sit in the repository, so changes to them arrive as pull requests and get reviewed like code. Tidewater added the .github/agents folder, the instructions folder, copilot-instructions.md and AGENTS.md to its CODEOWNERS file, with Priya and Dmitri as owners, so that any change to how agents behaved needed one of them to approve it. This mattered most in TrailCheck, where outside contributors could propose changes: a pull request from a fork that quietly edited AGENTS.md to tell agents to skip tests would need an owner's approval before it could take effect.
Keeping instructions current
Instructions rot like any documentation. A build command changes, a folder is renamed, a test runner is replaced, and the instructions still describe the old way. Agents then follow stale instructions with complete confidence. Tidewater made updating the instruction files part of the definition of done for any change to the build or test setup, and checked them in the same term review as the agent settings. Dmitri also asked the cloud agent itself, once a term, to compare AGENTS.md with the repository and list anything that looked out of date, then reviewed its list by hand.
Custom agents for review and documentation
The test-writer agent was the first of three custom agents Tidewater wrote. The second was a reviewer agent with read and search tools only, which wrote review comments on pull requests against a short checklist: tests added, dist rebuilt, README in step with action.yml. It did not replace human review; it caught the routine omissions before a person looked. The third was a documentation agent that could edit only Markdown files, used to keep READMEs in step with code changes. Each agent's file was under fifty lines, and each had a named owner.
A worked comparison
Dmitri compared three runs of the same task, adding a nautical miles unit to trail-units, with three levels of customization. With no instruction files, the agent added the unit, used a different test style and forgot to rebuild dist. With AGENTS.md alone, it rebuilt dist and kept action.yml in step, but its tests still used a different style. With AGENTS.md and the path-specific test instructions, the pull request matched the team's conventions and needed no review comments. Each run cost about the same; the difference was entirely in what the agent had been told.
| Customization | Rebuilt dist | Test style matched | Review comments |
|---|---|---|---|
| None | No | No | 4 |
| AGENTS.md only | Yes | No | 2 |
| AGENTS.md and test instructions | Yes | Yes | 0 |
The comparison was small and informal, but it persuaded the rest of the team to write instruction files for their own repositories. Malik wrote an AGENTS.md for open-trail-report that afternoon, and Lena started one for TrailCheck, which needed more care because outside contributors could read it and propose changes to it.
Prompt files the team kept
Tidewater ended the term with four prompt files in TrailCheck: write release notes from merged pull requests, add a new trail condition type, reproduce a volunteer bug report as a failing test, and summarize a week of issue activity for the Thursday meeting. Each was a few lines long, and each replaced a prompt someone had been retyping from memory.
Common mistakes
MistakeWriting long instruction files that describe the whole project history.
InsteadKeep instructions short, specific and checkable; move file-specific rules to path-specific files.
MistakeRelying on instructions alone for rules that must always hold.
InsteadBack critical rules with rulesets, checks, tool lists and review.
MistakeGiving every custom agent every tool.
InsteadList only the tools each agent needs.
MistakeLetting anyone change agent definitions without review.
InsteadTreat agent files like workflow files: protect and review them.
Summary and key terms
- Repository instructions, path-specific instructions, AGENTS.md, organization and personal instructions all shape agent prompts.
- Good instructions state how to build and test, what done means and what is forbidden, briefly.
- Prompt files store reusable prompts; custom agents in .github/agents define named agents with their own instructions, tools and MCP servers.
- Organization and enterprise agents can be shared centrally, and agent files can be protected by push rules.
- Instructions guide behavior; deterministic controls enforce it.
- Repository custom instructions
- Instructions in .github/copilot-instructions.md that apply to every Copilot request in a repository.
- Path-specific instructions
- Instruction files that apply to files matching a pattern.
- AGENTS.md
- An open convention for a file that tells agents how to build, test and work in a project.
- Prompt file
- A reusable prompt stored in the repository and run by name.
- Custom agent
- A named agent defined in a Markdown file with its own instructions and allowed tools.
Practice problems
Work each problem on paper first, then reveal the answer to check.
Where do repository custom instructions live?
Show answer
In .github/copilot-instructions.md.
Which AGENTS.md applies in a repository with several projects?
Show answer
The nearest one to the files being changed.
Why should agent definition files be protected?
Show answer
They set an agent's instructions and tools, so changes are effectively permission changes.
Lesson quiz · 5 questions
Score 60% or more to complete this lesson.
Create a free account to save your progress, take quizzes and earn a certificate.