NashTech Blog

Tips for using Github Copilot instruction files or AGENTS.MD effectively

Table of Contents

AI assistant tools like Github Copilot, Cursor, Claude have become popular. However, the results are not always as our expectations. For saving time in prompting, we can leverage the instructions files to support the AI tools in generating the response for us quickly and exactly. In this article, we’ll understand more about copilot-instruction.md and AGENTS.MD file as well as the tips for using them effectively.

1.Github Copilot instruction files

The clearer the context is, the more exactly AI responses are. To provide the context for AI tools, Github Copilot will read the information in the instructions files. The copilot-instruction.md file is usually stored in .github folder. We can write the content for it in nature language in Markdown format. Here is an example of instructions file for generating Playwright script.

---
applyTo: "**/tests/*.spec.ts"
---

## Playwright test requirements

When writing Playwright tests, please follow these guidelines to ensure consistency and maintainability:

1. **Use stable locators** - Prefer `getByRole()`, `getByText()`, and `getByTestId()` over CSS selectors or XPath
1. **Write isolated tests** - Each test should be independent and not rely on other tests' state
1. **Follow naming conventions** - Use descriptive test names and `*.spec.ts` file naming
1. **Implement proper assertions** - Use Playwright's `expect()` with specific matchers like `toHaveText()`, `toBeVisible()`
1. **Leverage auto-wait** - Avoid manual `setTimeout()` and rely on Playwright's built-in waiting mechanisms
1. **Configure cross-browser testing** - Test across Chromium, Firefox, and WebKit browsers
1. **Use Page Object Model** - Organize selectors and actions into reusable page classes for maintainability
1. **Handle dynamic content** - Properly wait for elements to load and handle loading states
1. **Set up proper test data** - Use beforeEach/afterEach hooks for test setup and cleanup
1. **Configure CI/CD integration** - Set up headless mode, screenshots on failure, and parallel execution

Instead of using the long prompts or separate prompts for a generating automation script task, we can add all the information into the instruction file. Thanks to it, we can have the result as our expectation quickly.

The instruction file will support us in different kinds of tasks like code implementation, defining coding standards, and development workflow.

.github/copilot-instructions.md will be applied for all chat request. However, we can use separates instructions file for specific tasks with .instruction.md files. In those files, please use the keyword “applyTo” so that Github Copilot can apply the right rules for each task.

2.AGENTS.MD

Different AI tools provide different ways to give the instruction to the AI agents like instructions file for GithubCopilot or adding rules in Curson. AGENTS.MD has been developed as the standard for most of the AI tools.

The AGENTS.MD file will be stored in the root folder of the project, and it contains the guidance for the coding agent. It’s very useful if you work with multiple agents in your project. Whenever you chat with the AI tool, it will refer to this file automatically. Here is an example of AGENTS.MD file.

# Sample AGENTS.md file

## Dev environment tips
- Use `pnpm dlx turbo run where <project_name>` to jump to a package instead of scanning with `ls`.
- Run `pnpm install --filter <project_name>` to add the package to your workspace so Vite, ESLint, and TypeScript can see it.
- Use `pnpm create vite@latest <project_name> -- --template react-ts` to spin up a new React + Vite package with TypeScript checks ready.
- Check the name field inside each package's package.json to confirm the right name—skip the top-level one.

## Testing instructions
- Find the CI plan in the .github/workflows folder.
- Run `pnpm turbo run test --filter <project_name>` to run every check defined for that package.
- From the package root you can just call `pnpm test`. The commit should pass all tests before you merge.
- To focus on one step, add the Vitest pattern: `pnpm vitest run -t "<test name>"`.
- Fix any test or type errors until the whole suite is green.
- After moving files or changing imports, run `pnpm lint --filter <project_name>` to be sure ESLint and TypeScript rules still pass.
- Add or update tests for the code you change, even if nobody asked.

## PR instructions
- Title format: [<project_name>] <Title>
- Always run `pnpm lint` and `pnpm test` before committing.

It’s also written in Markdown format, and you can add sections that help an agent work effectively with your project. Popular choices will be

  • Project overview
  • Build and test commands
  • Code style guidelines
  • Testing instructions
  • Security considerations

Of course, you will also be able to add separate AGENTS.MD files in each folder if you want to provide different instructions for each part of your project.

3.Key differences between Github Copilot instructions & AGENTS.MD

AGENTS.MDGitHub Copilot Instructions
ScopeDefines an AI agent (identity, capabilities)Guides Github Copilot
Used byAI AgentsGitHub Copilot / Workspace
File TypeManifest (Markdown or YAML)Markdown
FocusDefine an agent, what it is and it can doHow Copilot should behave when coding inside a repo
Runtime effectCan define tools, APIs, executionContextual behavioral guidance

We can compile both AGENTS.MD and Github Copilot Instructions in a workflow for your project. For example, in automation tests, we can use AGENTS.MD to define an agent first. This agent will be responsible for automating the steps in test cases by Playwright MCP or running the test case successfully before committing code to repository. For the Github Copilot instructions, it will be responsible for how the script is implemented. We can define the rules related to coding convention, apply POM or data-driven in Github Copilot instruction files.

4.Tips for using Copilot instructions or AGENTS.MD effectively

  • Keep the instructions short and clear
  • Create separate instructions for different modules/folders
  • Reuse and reference instructions files the instruction in the chatmode/prompt file to make it clear and avoid duplication
  • Refer to the instruction on the Github repos or get the suggestions from Github Copilot itself
  • Give your project overview, explain your project structure, add coding convention in instructions files.

Conclusion

For now, effective prompting is a necessary skill for the engineers including BA, Developer or Tester. Using the instructions files like AGENTS.MD or Github Copilot or Cursor rules is very important. It help us save time for prompting, and the AI can provide good response with low consumption of token.

Referral:

Picture of Tien Nguyen Anh

Tien Nguyen Anh

I'm an Automation Test Manager with more than 10 years in software testing and development. Currently, I'm responsible for managing automation testing team, building their skills and supporting them to overcome issues. I also research the new automation testing technologies to share with team or conduct the training in NashTech.

Leave a Comment

Your email address will not be published. Required fields are marked *

Suggested Article

Scroll to Top