Sub topic 2
Writing Instructions an Agent Can Act On
This chapter assumes you know basic Git, Markdown, command-line workflows, and how to use an AI coding assistant. The goal is to write instructions that an agent can follow and a reviewer can verify.
Write Concrete, Verifiable Instructions
An agent needs commands, paths, and conditions. Avoid advice such as “write clean code” or “test properly.” State the action and its success condition instead.
## Build and test
- Run `npm run lint && npm test` before finishing.
- Fix failures caused by your changes.
- Add a unit test in the matching `*.test.ts` file for every new public function in `src/services/`.Each rule answers at least one practical question:
- What command should the agent run?
- Which files or directories does the rule concern?
- What change requires a test?
- What result indicates success?
Keep rules short. Explain unusual commands, but do not document general programming knowledge. Prefer repository-specific facts, such as required environment setup, directory conventions, test commands, and pull request requirements.
Place the File at the Correct Scope
A root AGENTS.md normally contains rules shared by the whole repository. An agent working on a file should also look for applicable instruction files in that file’s parent directories.
repo/
├── AGENTS.md
└── packages/
├── api/
│ ├── AGENTS.md
│ └── src/routes/orders.ts
└── web/
├── AGENTS.md
└── src/App.tsxThe API file receives the root rules and the rules in packages/api/AGENTS.md. The web file receives the root rules and the rules in packages/web/AGENTS.md. Keep shared guidance at the root. Put package-specific commands and styles in the nearest nested file.
Understand Which Instructions Win
When rules overlap, the usual precedence is:
- An explicit user request.
- The most specific applicable
AGENTS.md. - A broader
AGENTS.mdhigher in the directory tree.
A nested file can add detail or override a general rule when the project’s agent supports that behavior. Do not repeat every root rule in nested files. If two rules conflict and the agent’s precedence is unclear, state the exception explicitly and test it with a small task.
Exercise
An agent edits packages/api/src/service.ts. Which instruction files should guide it?
Show answer
The root AGENTS.md and the closest applicable packages/api/AGENTS.md; an explicit user request takes precedence over both.