Sub topic 12
Checking that the agent follows your instructions
This chapter assumes you have a working AGENTS.md with build, test and lint commands, and that you know how nested files and precedence work. Writing instructions is only half the job. You also need evidence that the agent reads them and acts on them.
Why a file can fail silently
An instruction file can fail in several ways, and none of them produce an error message:
- The tool never loaded the file, for example because it looks for a different filename or the file sits outside the directory scope.
- The file loaded, but a closer AGENTS.md or an explicit user prompt overrode a rule.
- The rule was loaded, but it is too vague for the agent to act on.
- The rule is concrete but wrong, such as a command that no longer exists.
Testing separates these cases. Change one thing at a time so you know which cause you are looking at.
Step 1: Confirm the file is loaded
Start a fresh session in the directory you care about. Ask a question that only the file can answer:
What command should you run to execute a single test file in this repository?With the example file from earlier chapters, a correct answer is npm test -- path/to/file.test.ts. If the agent guesses npx jest or asks you, the file was not loaded. Check the filename, its location, and whether your tool reads AGENTS.md directly or needs a symlink or import.
For nested files, run the same check from inside packages/web/ and ask for the package-specific test command. The answer should come from the nested file.
Step 2: Give the agent a task with a checkable outcome
Loading is not the same as following. Pick a small task where each rule leaves a visible trace:
Add a function formatInvoiceNumber to src/services/ and cover it with a test.Then review the result against the rules:
| Rule in AGENTS.md | What to check |
|---|---|
| Use named exports | The new function has no `export default` |
| Business logic in `src/services/` | The file is under `src/services/`, not `src/routes/` |
| Unit test in the matching `*.test.ts` file | A test file exists next to or for the service |
| Run lint and typecheck before finishing | The session log shows `npm run lint && npm run typecheck` |
| Never edit an existing migration | `git diff` shows no changes under `migrations/` |
Rules phrased as commands and locations, as in the writing chapter, are the easiest to verify. If you cannot tell from the diff or the log whether a rule was followed, rewrite the rule.
Step 3: Test precedence on purpose
Precedence is easy to assume and easy to get wrong. Test two cases:
- Nearest file wins. Add a harmless conflicting rule to a nested file, then work in that directory. The agent should follow the nested rule. Remove the test rule afterward.
- User prompt wins. Ask for something the file forbids, such as a default export, and say so explicitly. The agent should follow your prompt. If it refuses or silently follows the file, note the tool's behavior.
Step 4: Repeat after changes
Agent behavior depends on the model and the tool version as well as on your file. Rerun your checks when you edit AGENTS.md, rename commands, upgrade the tool, or switch tools. Keep the check prompts in the repository, for example in docs/agent-checks.md, so anyone can repeat them.
Run each check more than once. A single success can be luck. If a rule is followed in most runs but not all, move it higher in the file, shorten the text around it, or make the wording more specific.
Common mistakes
- Testing in a session that already has context from earlier work, so the agent answers from memory instead of the file.
- Checking only that the agent says it understood. Look at the diff and the commands it ran.
- Changing several rules at once, which hides which change helped.
Exercise
An agent working in packages/web/ uses the root test command instead of the one in packages/web/AGENTS.md. Name two checks you would run to find the cause.
Show answer
First, start a fresh session in packages/web/ and ask which command runs the tests there. If it answers with the root command, the nested file was not loaded or the tool does not support nested files. Second, check whether the task prompt or a closer file gave a conflicting instruction, and whether the nested rule is concrete, for example npm test --workspace packages/web. Fix the loading, the conflict or the wording depending on what you find.