---
title: "How we prepare code for AI agents: context, rules, and test environments"
description: "Get the repository ready for AI agents: clear instructions, AGENTS.md, architectural context, test data, and reproducible checks."
canonical: https://i8.ro/en/blog/preparing-code-for-ai-agents-context-rules-and-test-environments
---

# How we prepare code for AI agents: context, rules, and test environments

> Get the repository ready for AI agents: clear instructions, AGENTS.md, architectural context, test data, and reproducible checks.

Source: https://i8.ro/en/blog/preparing-code-for-ai-agents-context-rules-and-test-environments

**Series II: From infrastructure to agentic commerce projects in production. Episode 07 of 20.**

In the previous episode, we turned a feature's objective into verifiable tasks. The next issue arises immediately: even a well-defined task fails if the agent doesn’t know how to start the project, what rules apply, and what command proves the change works.

The main decision is to treat the repository as the project’s executable context package. Instructions, commands, decisions, and test data must be kept close to the code, versioned, and checked. A long document sent separately doesn't make up for a project that only starts on one person's laptop.

## The repository is more than code

A **repository** is the versioned space where the team keeps the code and its change history. For development with AI agents, it must quickly answer several questions: what does the system do, how is it installed, how do you run it, what can't we change, and how do we verify the results.

In our hypothetical scenario, the B2B portal repository contains the web interface, the request API, the document service, and the tests. The development agent is tasked with validating PDF file uploads. The agent later integrated into the portal, which might classify documents, is a separate function. It does not read development instructions and has no access to the repository.

A minimal package might have this structure:

\`\`\`text
README.md
AGENTS.md
docs/architecture/
docs/adr/
scripts/bootstrap
scripts/check
tests/fixtures/
.env.example
\`\`\`

The exact names may vary. What matters is that the team has an official starting and checking route, not five contradictory versions hidden in messages.

## README for orientation, AGENTS.md for execution

The README remains the introduction for humans: the project's purpose, main components, requirements, and starting directions. **AGENTS.md** is a Markdown file dedicated to programming agent instructions. Its open format describes it as a README for agents and recommends including installation and testing commands, conventions, and security considerations.

For the portal, AGENTS.md should concisely specify:

- which directories correspond to the interface, API, and document service;
- the official commands for installation, starting, formatting, analysis, and tests;
- important versions for runtimes and package managers;
- code conventions and where to add tests;
- sensitive areas, such as migrations, authorization, and document storage;
- mandatory checks before submitting a change;
- when the agent should stop and request a decision.

In a monorepo, there may be AGENTS.md files closer to certain subprojects. The format’s documentation and GitHub specify that the instruction closest to the changed file takes priority. This rule must be tested in your chosen tool, as support differs between products and features.

Instructions aren’t an authorization mechanism. The phrase “do not access production” can guide the agent, but true isolation comes from missing credentials, minimal permissions, separate networks, and technical approvals. A Markdown file won’t stop a command permitted by the runtime environment.

## A single validated way to start

GitHub recommends documenting the sequences for bootstrap, build, test, run, and lint, including versions and preconditions, and commands must be actually tried. For a small team, the practical solution is to provide two stable entry points:

- `scripts/bootstrap`, which installs or checks dependencies and sets up the local environment;
- `scripts/check`, which runs mandatory checks in the order the team accepts.

These scripts can call existing tools. They shouldn’t hide errors or continue after a critical step has failed. The agent and new teammate use the same route, and continuous integration can call the same check.

A development container can specify in a file `devcontainer.json` the tools and settings of the containerized environment. The Dev Container specification aims to ensure consistency between local development and automated build and test systems. It's optional, not mandatory. For a simple project, pinned versions and reproducible scripts may be enough. For multiple services, containers can reduce differences between laptops, but they can't, by themselves, guarantee reproduction of all external services.

## Safe test data and example configurations

The file `.env.example` lists the required keys with dummy values or explanations, never with actual secrets. Tokens and passwords are injected by the authorized environment. Tests use synthetic accounts and documents, not uncontrolled copies from production.

For PDF functionality, we keep small fixtures: a valid file, one that's too large, one with an incorrect declared type, and metadata for fictitious users. A **fixture** is a stable set of prepared test data. We document who updates it and what it verifies. If a sample contains personal data, we replace it—not just superficially “anonymize” it and publish it in the repository.

The agent must be able to create the local database from scratch and run tests without access to client accounts. Any dependency on an external service has a controlled alternative: official sandbox, emulator, mock, or an explicit step that halts execution. That way, inability to contact production becomes an environment property, not just a prompt warning.

## ADR: why a decision exists

A **ADR**, from Architecture Decision Record, is a brief entry recording an architectural decision. Michael Nygard's proposed model includes context, decision, status, and consequences. If a choice changes, the old ADR stays in history and is marked as replaced.

For the portal, an ADR might explain why documents are stored in object storage, why the database keeps only references, and what tradeoffs result from these choices. This way, the agent sees the reasons behind choices, not just the current form of the code. AGENTS.md describes how we work right now; the ADR explains why a significant decision exists. Neither should be turned into a duplicate of the other.

## Verification in a clean environment

Before considering the repository ready, we test it as if onboarding a new colleague:

1. clone it in an environment with no caches or hidden local files;
2. run the bootstrap instructions exactly as written;
3. launch services with example configurations and synthetic data;
4. perform a full verification and an end-to-end scenario;
5. fix documentation or automation, not the memory of whoever intervened.

The SWE-agent paper published at NeurIPS 2024 shows that the interface an agent uses to navigate the repository and run tests affects its behavior and performance. The results from a research system do not guarantee the same performance in a commercial project. They do, however, support a cautious conclusion: the environment and tools given to the agent are part of the system we are evaluating.

The piece added to the project is the minimal context package: README for orientation, AGENTS.md for execution, ADRs for the reasoning, scripts for bootstrap and verification, plus synthetic fixtures. We review it in the same pull request as the code change that makes it outdated. In the next episode, we will compare the places an agent can work: IDE, terminal, and cloud environment.

## Sources

- [AGENTS.md, open format for agent instructions](https://agents.md/), for structure, domain, and instruction priority, consulted on October 9, 2026.
- [GitHub Docs, *Adding repository custom instructions for GitHub Copilot*](https://docs.github.com/en/enterprise-cloud@latest/copilot/how-tos/copilot-on-github/customize-copilot/add-custom-instructions/add-repository-instructions), for repository context and build, test, and validation commands.
- [Development Containers, *Overview*](https://containers.dev/overview), for a description of development environments and their reuse in build and test.
- [Nygard, *Documenting Architecture Decisions*](https://cognitect.com/blog/2011/11/15/documenting-architecture-decisions) and [Yang et al., *SWE-agent*, NeurIPS 2024](https://proceedings.neurips.cc/paper_files/paper/2024/hash/5a7c947568c1b1328ccc5230172e1e7c-Abstract-Conference.html), for ADRs and the agent interface’s role.
