Python agent workflows with ruff, pytest, and typing
Python agent workflows stay healthy when the gate order is fixed: ruff, then types, then pytest.
Python agent workflows stay healthy when the gate order is fixed: ruff, then types, then pytest. Agents that skip the chain silently degrade repos with import chaos, # type: ignore sprawl, and happy-path-only evidence. The trap is letting the model invent a second environment manager or a different format subset than CI.
Pin one blessed tool chain
Pick one stack and stick to it. Prefer ruff for format and lint unless the repo already standardized elsewhere. Put the exact commands in the rules file, including monorepo package paths. Forbid new dependencies without a note on license and whether types ship in-package or need stubs.
Related: Rules files that agents obey for where these commands live.
Definition of done: ruff → types → pytest
- Run ruff first. Format and check before debating style in chat.
- Typecheck touched modules. Fix annotations. Do not delete them to go green.
- Narrow pytest, then broaden. Start with the failing or adjacent tests; run broader smoke only when the change crosses packages.
- Attach evidence. Commands run and paths touched belong in the PR, not only in the agent transcript.
Stop the session when the agent adds widespread # type: ignore, mixes poetry/pip/uv without need, or formats a different subset than CI.
Three traps that show up first

Failure modes to catch early
type: ignoresprawl. The agent silences errors instead of fixing annotations. Fix: ban new ignores without a ticket and an owner; prefer typed boundaries at public APIs.- Env manager churn. One PR invents a second installer. Fix: follow the repo’s existing approach only.
- Format thrash. Local format subset differs from CI. Fix: one entrypoint command both humans and agents run.
Also treat notebooks as separate artifacts. Do not let agents dump experimental notebooks into installable packages.
A one-week hygiene loop

Stop gates before you ship
Mon–Fri: every agent PR must show the three commands green on the diff. Once this week: ripgrep for new # type: ignore and unexplained dependency adds. If the same skip appears twice, encode it as a CI gate, not another review lecture.
Bottom line

When this fits vs when it does not
Python agents need a boring chain: ruff, types, pytest, same as CI. Pin versions, pin entrypoints, and refuse escapes. For language-specific traps outside Python, see Rust and Go agent caveats.
Share