Skip to content

Commit 72d2eec

Browse files
docs: add AGENTS.md with contribution rules for AI agents (#15121)
* docs: add AGENTS.md with contribution rules for AI agents Adds a model-neutral AGENTS.md at the repo root summarizing the conventions that most often trip up automated contributors, most importantly that algorithms-keeper closes any PR without a checked box in the 'Describe your change' section. Complements CONTRIBUTING.md. * docs: use uvx/uv commands in AGENTS.md (this repo uses uv, not requirements.txt)
1 parent 63103f4 commit 72d2eec

1 file changed

Lines changed: 62 additions & 0 deletions

File tree

AGENTS.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# AGENTS.md
2+
3+
Guidance for AI coding agents (and their humans) contributing to
4+
**TheAlgorithms/Python**. This complements — and never overrides —
5+
[`CONTRIBUTING.md`](CONTRIBUTING.md). Read that first.
6+
7+
This repository is educational: implementations should be clear and correct
8+
rather than maximally optimized. Every change goes through CI and the
9+
`algorithms-keeper` bot, both of which reject non-conforming PRs automatically.
10+
11+
## Before opening a pull request
12+
13+
- **Check at least one box in the PR description.** The `algorithms-keeper`
14+
bot **closes any PR whose "Describe your change" section has no checked
15+
box** (`* [x]`). Fill in the template that ships in
16+
`.github/pull_request_template.md` and tick every item that applies before
17+
you submit — this is the single most common reason automated PRs get closed.
18+
- **One algorithm file per PR.** Split unrelated changes into separate PRs to
19+
keep review focused.
20+
- **Don't change code and its doctests in the same PR.** If you're only
21+
updating tests, say so and touch nothing else.
22+
23+
## Code conventions (enforced by CI)
24+
25+
- **Formatting & linting:** `ruff` (`uvx ruff check .` and `uvx ruff format .`).
26+
Run `uvx pre-commit run --all-files` locally to catch everything CI will.
27+
- **Type hints:** annotate every function parameter and return value with
28+
[type hints](https://docs.python.org/3/library/typing.html).
29+
- **Doctests:** every function needs at least one
30+
[doctest](https://docs.python.org/3/library/doctest.html) that passes under
31+
`python -m doctest -v your_file.py` (and `pytest`).
32+
- **Naming:** filenames are all-lowercase with underscores (no spaces or
33+
dashes); functions and variables follow standard Python naming.
34+
- **Placement:** new files go inside an existing directory.
35+
- **References:** new algorithms include a URL to Wikipedia or a comparable
36+
explanation.
37+
38+
## Running the suite locally
39+
40+
This project is managed with [`uv`](https://docs.astral.sh/uv/) — there is no
41+
`requirements.txt`. Dependencies live in `pyproject.toml`/`uv.lock`, and `uvx`
42+
runs a tool in a throwaway environment without polluting yours:
43+
44+
```bash
45+
uvx pre-commit run --all-files # ruff, formatting, hooks
46+
uvx pytest your_module/your_file.py --doctest-modules
47+
```
48+
49+
(`uv run pytest ...` works too if you'd rather use the project's locked
50+
environment.)
51+
52+
Some directories are intentionally skipped in CI (`--ignore` entries in
53+
`.github/workflows/build.yml`), usually because a heavy dependency lacks a
54+
wheel for the CPython version the repo currently targets. Check that list
55+
before assuming a file is untested.
56+
57+
## Good agent behavior
58+
59+
- Keep diffs minimal and scoped to the stated change.
60+
- Preserve existing style and structure; prefer clarity over cleverness.
61+
- Never fabricate doctest output — run it and paste the real result.
62+
- If CI is red, read the log and fix the cause rather than re-running blindly.

0 commit comments

Comments
 (0)