All 5 AI packs for $39 →
← ToolTier Library
AGENTS.md · Free

AGENTS.md for a Python monorepo (uv workspace)

A free AGENTS.md for Python monorepos managed as a uv workspace: one lockfile, uv run --package for each member, where dependencies go, workspace sources between packages, import boundaries and a lockfile check before done.

Install
AGENTS.md (repository root)
Last tested
Codex / Copilot / uv 0.13.9 docs · 2026-11-19

In a uv workspace, agents keep making the same few mistakes: running pip install into the wrong environment, adding a dependency to the root instead of the package that imports it, wiring one package to another with a path hack, or editing uv.lock by hand. This AGENTS.md gives them the uv way to do each of those, plus import boundaries between apps and shared packages.

The commands follow uv's workspace docs and CLI reference, checked on November 19, 2026, when uv 0.13.9 was the latest release on PyPI: a workspace shares one lockfile, uv run and uv sync act on the root unless you pass --package, members depend on each other through tool.uv.sources with workspace = true, the whole workspace has a single requires-python, and --all-packages installs every member. uv's docs also note that it can't stop one member from importing a dependency declared by another, which is why the file tells agents to check the member's own pyproject.toml first.

Nested AGENTS.md files work in both Codex and Copilot: Codex joins the files from the repo root down to the folder it's working in, and GitHub's docs say the nearest AGENTS.md in the directory tree takes precedence. Put service-specific commands in apps/api/AGENTS.md and keep this one for the workspace. Fill in the [bracketed] paths and tools. Using FastAPI in one of the apps? Add our free Cursor rules for FastAPI too.

AGENTS.md
# AGENTS.md

Instructions for AI coding agents working in this repository. This is a Python monorepo managed as a single uv workspace: one `uv.lock` and one `.venv` at the root, shared by every package.

## Layout
- `pyproject.toml` (root): workspace root. `[tool.uv.workspace]` lists the members (`[packages/*, apps/*]`).
- `[apps/]`: deployable applications, e.g. `[apps/api]` (FastAPI) and `[apps/worker]`.
- `[packages/]`: internal libraries shared by the apps, e.g. `[packages/core]` and `[packages/db]`.
- Each member has its own `pyproject.toml` and uses the `src/<package_name>/` layout. Tests live in that member's `tests/` folder.
- A member folder may contain its own `AGENTS.md` with extra rules. When you work inside it, follow the nearest one as well as this file.

## Setup and commands
Run everything through uv from the repository root. Don't call `pip`, `python -m venv` or `poetry`, and don't activate the virtualenv by hand.
- Install everything: `uv sync --all-packages`
- Run a command in one member: `uv run --package <member> <command>` (example: `uv run --package api pytest`)
- All tests: `[uv run pytest]`
- Lint and format: `[uv run ruff check --fix .]` and `[uv run ruff format .]`
- Type check: `[uv run mypy apps packages]`
- CI runs with `--locked`, so a stale `uv.lock` fails the build.

## Dependencies
- Add a third-party dependency to the member that imports it: `uv add --package <member> <dependency>`. Add dev tools to the root dev group: `uv add --dev <tool>`.
- One member depending on another goes in that member's `pyproject.toml` as a normal dependency plus a source entry: `[tool.uv.sources]` `core = { workspace = true }`. Never use a relative `sys.path` hack or a hard-coded path import.
- Import only what your member declares. uv can't stop a package from importing a dependency that another member declared, so check the member's own `pyproject.toml` before adding an import.
- The whole workspace shares one `requires-python` (`[>=3.12]`). Don't use syntax or stdlib features newer than that.
- Never edit `uv.lock` by hand. If you changed dependencies, run `uv lock` and commit the lockfile with the `pyproject.toml` change. Don't upgrade unrelated packages; ask before running `uv lock --upgrade`.

## Boundaries
- `[packages/*]` must not import from `[apps/*]`. Apps may import packages.
- Shared models and settings belong in `[packages/core]`. Don't copy them into an app.
- A change to a package's public API must update every member that uses it in the same change. Search the workspace for usages first.

## Working rules
- Run the tests for the member you changed and for every member that depends on it before you say you're done.
- Keep diffs focused on the task. Don't reformat or move files you didn't need to touch.
- Never commit secrets or `.env` files. Read settings from environment variables through `[pydantic-settings in packages/core]`.
- Ask before deleting files, changing CI, or adding a new workspace member.

## Definition of done
- `uv sync --locked --all-packages` succeeds, so the lockfile is current.
- Lint, format check, type check and the affected tests all pass, and you report the exact commands you ran.
AGENTS.mdPythonuvMonorepo

← More free rules, templates and prompts

+ Your logo here