Skip to content
Languages

Python AGENTS.md

Python agents often install into the wrong environment. This file tells the agent to use the project's lockfile and runner, to keep type hints consistent with the files around the edit, and to run the existing test command.

Paste, then editPython MCP servers

uv, pip, and Poetry are not interchangeable. Name the one this repository uses.

In this stack

What to tell the agent

Do

  • Name the test command exactly, including any default path such as tests/.
  • Say whether the package is a library or an application, so the agent does not add a CLI the library does not want.
  • Point at pyproject.toml as the source of tool config.
  • Ask the agent to update a test when behavior changes.

Leave alone

  • Running sudo pip install.
  • Mixing uv add with a hand-edited requirements.txt that the project no longer uses.
  • Broadening an exception handler to except Exception: pass.
Starter file

AGENTS.md to copy

Save this as AGENTS.md at the root of the repository, or next to the package it covers. Replace the commands with the ones in this repo. See which agents read the file.

AGENTS.md
# Python

## Environment
- Use the runner the repository documents (uv, poetry, or pip with a virtualenv). Do not pip install into the system Python.
- Add a dependency only through that runner, so the lockfile updates with the manifest.
- Stay on the Python version in .python-version or requires-python.

## Code
- Match the typing style of the file you edit. Do not strip annotations from a typed module.
- Keep I/O at the edges. A function that computes a value should take its inputs as arguments.

## Checks
- Run the test command the repo uses, for example uv run pytest or python -m unittest.
- If the repo formats with ruff, run ruff check on the files you changed.
- Quote the traceback's last project frame when something fails.

## Leave alone
- Do not commit a virtualenv, __pycache__, or a regenerated lockfile you did not mean to change.
- Do not pin a new package to a URL or a git commit unless the task says to.
Commands to confirm

Checks named in the file

Confirm each command exists here before you rely on it. Delete the ones this repository does not use.

  • Sync the lockfile environment. uv sync
  • Tests. uv run pytest
  • Lint the files you touched. uv run ruff check path/you/changed
FAQ

Questions

What is the Python AGENTS.md for?

It points a Python agent at the project's environment and test command so it does not install into the system interpreter.

Which Python installer should the instruction file name?

The one the repository already uses. If pyproject.toml and uv.lock are present, say uv. If poetry.lock is present, say Poetry. Naming a second installer produces two lockfiles.

Where should a new Python dependency be declared?

Through the project's runner so the manifest and the lockfile change together. A package installed only into a local virtualenv disappears on the next machine.

Keep going

Related on MCPpedia