cd /news/developer-tools/agents-md-hands-on-build-one-step-by… Β· home β€Ί topics β€Ί developer-tools β€Ί article
[ARTICLE Β· art-47585] src=dev.to β†— pub= topic=developer-tools verified=true sentiment=↑ positive

AGENTS.md, Hands-On: Build One Step by Step (and Watch an Agent Use It)

A developer built a complete AGENTS.md file for a URL shortener API in Python, demonstrating how the file guides AI coding agents by specifying setup, test, structure, conventions, and guardrails. The hands-on tutorial shows that an agent can read the file in thirty seconds and use it to work effectively on the project.

read5 min views1 publishedJul 4, 2026

In the field guide I covered what an AGENTS.md is and what belongs in it. This is the hands-on follow-up: we'll build a complete AGENTS.md for a real project, one section at a time, then point an AI coding agent at it and watch the difference it makes. By the end you'll have a working file β€” and you'll have seen it pay off.

New to AGENTS.md? It's a single Markdown file at the root of your repo that tells AI coding agents how to work in it β€” build steps, tests, conventions, guardrails. The "why" behind each section is in the field guide.

We'll write the AGENTS.md for a small but real service: a URL shortener API in Python β€” FastAPI, SQLite, pytest. A couple of endpoints, a thin data layer, a test suite. Follow along with this, or swap in your own repo β€” the steps are identical.

Its shape:

linkshort/
  app/
    main.py        # FastAPI routes
    db.py          # SQLite access
    models.py      # Pydantic models
  migrations/      # generated SQL β€” not hand-edited
  tests/
  requirements.txt

At the repo root:

touch AGENTS.md

That's the whole step. We'll fill it in one section at a time, building toward a file an agent can read in thirty seconds.

Tell the agent what it's looking at. Add:


A URL shortener API in Python β€” FastAPI, SQLite, pytest.

One sentence sets the agent's priors: it knows the language, framework, and storage before it reads a single line of code.

The agent can't help if it can't start the project. Add the real, copy-pasteable commands:

## Setup
python -m venv .venv && source .venv/bin/activate
pip install -r requirements.txt

## Run
uvicorn app.main:app --reload   # http://localhost:8000

Use the commands that actually work in your repo β€” no placeholders.

This is the most important section, because tests are how the agent checks its own work. Add:

## Test β€” all must pass before a change is done
pytest
ruff check .
mypy app

Now the agent knows how to verify a change and the bar it has to clear. An agent that knows pytest

will run it; one that doesn't hands you a broken branch.

A short map so the agent finds its way without spelunking the whole tree:

## Structure
- app/main.py    route handlers
- app/db.py      SQLite access (parameterized queries only, never string-built SQL)
- app/models.py  Pydantic request/response models
- migrations/    generated SQL β€” do not hand-edit
- tests/         pytest, mirroring app/

Notice we're already slipping a convention ("parameterized queries only") and a guardrail ("do not hand-edit") in right where they're relevant.

The patterns you want followed. Be specific β€” vague rules are noise:

## Conventions
- Validate all input with Pydantic models at the route boundary.
- Raise HTTPException for client errors; never return raw dicts on failure.
- Type everything; mypy must stay clean.
- Match the style of the surrounding file.

"Type everything; mypy must stay clean" tells the agent exactly what to do. "Write good code" wouldn't.

If your agent opens PRs, give it the house rules:

## Commits & PRs
- Conventional Commits (feat:, fix:, chore:).
- One logical change per PR; update CHANGELOG.md.

The "don'ts" that prevent expensive mistakes:

## Don't
- Don't hand-edit migrations/ β€” they're generated.
- Don't commit directly to main β€” branch and open a PR.
- Never run the seed script against a non-local database.

Put it together and you have a complete, copy-pasteable file:


A URL shortener API in Python β€” FastAPI, SQLite, pytest.

## Setup
python -m venv .venv && source .venv/bin/activate
pip install -r requirements.txt

## Run
uvicorn app.main:app --reload   # http://localhost:8000

## Test β€” all must pass before a change is done
pytest
ruff check .
mypy app

## Structure
- app/main.py    route handlers
- app/db.py      SQLite access (parameterized queries only, never string-built SQL)
- app/models.py  Pydantic request/response models
- migrations/    generated SQL β€” do not hand-edit
- tests/         pytest, mirroring app/

## Conventions
- Validate all input with Pydantic models at the route boundary.
- Raise HTTPException for client errors; never return raw dicts on failure.
- Type everything; mypy must stay clean.
- Match the style of the surrounding file.

## Commits & PRs
- Conventional Commits (feat:, fix:, chore:).
- One logical change per PR; update CHANGELOG.md.

## Don't
- Don't hand-edit migrations/ β€” they're generated.
- Don't commit directly to main β€” branch and open a PR.
- Never run the seed script against a non-local database.

Thirty seconds to read. Now let's see if it works.

This is the part that matters. Open your repo in an AI coding agent β€” Claude Code, Cursor, Codex, whatever you use β€” and give it a real task:

"Add a

DELETE /links/{code}

endpoint that removes a link, with a test."

Watch what it does with the AGENTS.md in place:

app/main.py

, validating input the way your conventions require.pytest

test in tests/

, mirroring the structure.pytest

, ruff

, and mypy

β€” because you told it that's the bar β€” and fixes what fails.migrations/

, and it Now picture the same task without the file. The agent has to guess: Which test runner? Where do routes go? Is there a lint step? So it asks you, or it guesses wrong, or it edits a generated file you'll have to revert. The AGENTS.md is the difference between an agent that interrupts you and one that just ships.

That's the whole payoff β€” and you can watch it happen in real time.

One habit before you go: treat the file like code. When the test command changes, or you add a directory, or you catch yourself telling the agent the same thing twice β€” update AGENTS.md in the same breath. A stale file is worse than none, because the agent trusts it.

You started with an empty file, added eight short sections, and watched an agent use every one of them to land a correct, tested change without hand-holding. Write it once, and every agent that walks into your repo gets the same briefing.

This was the hands-on build. For the principles behind each section β€” what belongs, the anti-patterns, why short beats complete β€” see the field guide.

── more in #developer-tools 4 stories Β· sorted by recency
── more on @fastapi 3 stories trending now
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain β€” perfect for shipping the agent you just read about.

$git push zahid main
β†’ Live at https://your-agent.zahid.host βœ“
Get free account β†’ Pricing
from €0/mo Β· no card required
LIVE [news/agents-md-hands-on-b…] indexed:0 read:5min 2026-07-04 Β· β€”