typeagent-py
AGENTS.md889 starsChanged 14 months agoMITView on GitHub
DO NOT BE OBSEQUIOUS **NEVER use TEST_MODEL_NAME or "test" embedding model outside of test files** Never run git commands that make any changes. (git status and git diff are fine) Exceptions: git push, git worktree, git branch (for tracking setup), as instructed below. Exceptions: git push, git worktree, git branch (for tracking setup), as instructed below. NEVER COMMIT CODE. Do not run git commit or any other git commands that make changes to the repository. Exception: Worktrees/Branches below. git add…
- Commits and pushes
Where files are headingNew AGENTS.md files have more rules about keeping secrets out of the code, and fewer about checking a change actually works.
Of the AGENTS.md files we read, the 11,773 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.
In this repositoryOne other file it gives its agents.
- .github/copilot-instructions.mdCopilot instructions
The file
Show its rules and text
We split this AGENTS.md into the rules it gives an agent
46 rules. About 0 are common, 18 are distinctive, and 28 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈18
Distinctive · estimate
This author's own choices. Worth a look.
28
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 5
Never run git commands that make any changes.
- Distinctive: line 9
NEVER COMMIT CODE: Do not run git commit or any other git commands that make changes to the repository.
- Distinctive: line 13
When moving, copying or deleting files, use the git commands: git mv, git cp, git rm
- Distinctive: line 15
When I ask to update AGENTS.md (even if maybe) extract a general rule from what I said before and update AGENTS.md (unless it's already in …
- Distinctive: line 20
Don't use '!' on the command line, it's some bash magic (even inside single quotes)
- Distinctive: line 21
When running 'make' commands, do not use the venv (the Makefile uses 'uv run')
- Distinctive: line 22
If a term can refer to OS behavior or repository code behavior (for example, 'force quit'), prefer the in-repo meaning first and verify by …
- Very specific: line 24
Use pytest test to run tests in test/
- Very specific: line 25
Use pyright to check type annotations in src/, tools/, tests/, examples/
- Very specific: line 28
Use make check to type-check all files
- Very specific: line 29
Use make test to run all tests
- Very specific: line 30
Use make check test to run make check and if it passes also run make test
- Very specific: line 31
Use make format to format all files using black.
- Very specific: line 32
When validating changes, first run pytest only on new/modified test files, then run make format check test once at the end.
- Very specific: line 34
Keep ad-hoc and performance benchmarks under tools/, not tests/, so make test does not run them.
- Very specific: line 40
When adding precomputed-embedding write paths, expose explicit *_with_embeddings methods and have existing methods compute embeddings then …
- Distinctive: line 43
Keep internal helper type naming consistent within a module.
- Very specific: line 44
Prefer variable names that reflect role rather than lifecycle.
- Distinctive: line 45
Avoid potential import cycles between conversation orchestration and pipeline modules by using neutral payload protocols/arguments instead …
- Very specific: line 46
Prefer ordinal type aliases (e.g., MessageOrdinal, ChunkOrdinal) over raw int in pipeline code for readability.
- Distinctive: line 47
When the user asks to "fix the test only", update tests/mocks first and avoid adding production compatibility fallbacks unless explicitly …
- Very specific: line 52
Use uv add <package> to add new dependencies
- Very specific: line 53
Use uv add <package> --upgrade to upgrade existing packages
- Distinctive: line 72
When generating Python code (e.g.
- Distinctive: line 75
When creating a new file, add a copyright header to the top:
- Distinctive: line 85
Always strip trailing spaces
- Distinctive: line 87
Keep docstrings in sync with code when changing implementation.
- Very specific: line 89
Keep class and type names in PascalCase
- Very specific: line 90
Use python_case for variable/field and function/method names
- Very specific: line 92
Use Literal for unions of string literals
- Very specific: line 93
Keep union notation (X | Y) for other unions
- Very specific: line 94
Use Protocol for interfaces whose name starts with I followed by a capital letter
- Very specific: line 95
Use dataclass for other classes and structured types
- Very specific: line 96
Use type for type aliases (PascalCase again)
- Very specific: line 97
Use list, tuple, dict, set etc., not List etc.
- Distinctive: line 102
don't mock; use the regular implementation (maybe introduce a fixture to create it)
- Distinctive: line 105
read the code of the tested functions to understand their behavior
- Very specific: line 110
Don't put imports inside functions.
- Very specific: line 111
Put them at the top of the file with the other imports.
- Very specific: line 125
Default to Module-Qualified Imports: Prefer importing whole modules and using qualified calls (e.g., import math.
- Very specific: line 131
Prohibit Wildcard Imports: Never use wildcard imports (from module import *) in normal code.
- Very specific: line 140
Error Handling: Don't use try/except Exception to catch errors broadly.
- Very specific: line 143
Code Validation: Don't use py_compile for syntax checking.
- Very specific: line 144
Use pyright or make check instead for proper type checking and validation.
- Distinctive: line 146
Deprecations: Don't deprecate things -- just delete them and fix the usage sites.
- Distinctive: line 147
Don't create backward compatibility APIs or exports or whatever.
≈ “Common” is an estimate: at least 1 in 5 of the 16,595 AGENTS.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
DO NOT BE OBSEQUIOUS
NEVER use TEST_MODEL_NAME or "test" embedding model outside of test files
Never run git commands that make any changes. (git status and git diff are fine)
Exceptions: git push, git worktree, git branch (for tracking setup), as instructed below.
Exceptions: git push, git worktree, git branch (for tracking setup), as instructed below.
NEVER COMMIT CODE. Do not run git commit or any other git commands
that make changes to the repository. Exception: Worktrees/Branches below.
git add is fine.
When moving, copying or deleting files, use the git commands: git mv, git cp, git rm
When I ask to update AGENTS.md (even if maybe) extract a general rule from what I said before and update AGENTS.md (unless it's already in there -- maybe reformulate since it apparently didn't work). Also, when it looks like I state a general rule, add it to AGENTS.md. In all cases show what you added to AGENTS.md.
- Don't use '!' on the command line, it's some bash magic (even inside single quotes)
- When running 'make' commands, do not use the venv (the Makefile uses 'uv run')
- If a term can refer to OS behavior or repository code behavior (for example, 'force quit'), prefer the in-repo meaning first and verify by searching the code.
- To get API keys in ad-hoc code, call
load_dotenv() - Use
pytest testto run tests in test/ - Use
pyrightto check type annotations in src/, tools/, tests/, examples/ - Ignore build/, dist/
- You can also use the pylance extension for type checking in VS Code
- Use
make checkto type-check all files - Use
make testto run all tests - Use
make check testto runmake checkand if it passes also runmake test - Use
make formatto format all files usingblack. Do this before reporting success. - When validating changes, first run
pytestonly on new/modified test files, then runmake format check testonce at the end. - While building
add_messages.pybefore dedicated tests exist, skip running the full test suite; run full tests after those tests are added. - Keep ad-hoc and performance benchmarks under
tools/, nottests/, somake testdoes not run them. - In add-messages pipeline chunk processing, compute chunk-text embeddings with uncached model calls and related-term embeddings with cached model calls.
- In add-messages pipeline flow, lower stop_at_message_id to min(existing, failing_message_id), and always enqueue queue-1 sentinels even when the input iterator fails so workers can drain and exit cleanly.
- In add-messages pipeline data structures, use
TextLocationas the chunk identifier instead of a formatted string chunk ID. - In add-messages reassembler validation, prefer explicit guard checks over wrapping validation-only logic in
try/exceptblocks. - In add-messages reassembler validation, prefer a single
validation_errorvariable with consistentif/elifchecks over helper functions for simple message-only validation. - When adding precomputed-embedding write paths, expose explicit
*_with_embeddingsmethods and have existing methods compute embeddings then delegate to those methods. - In asyncio code, avoid locks for in-memory state updates that do not
awaitbetween read/modify/write; use locks only when a critical section spansawaitpoints. - Name returned summary/value objects as
*Result; reserve*Statefor mutable shared/internal state. - Keep internal helper type naming consistent within a module; avoid mixing underscored and non-underscored helper class names without a clear API-boundary reason.
- Prefer variable names that reflect role rather than lifecycle; for accumulators like message assemblies, use neutral names (e.g.,
assembly) instead of state-qualified names (e.g.,existing). - Avoid potential import cycles between conversation orchestration and pipeline modules by using neutral payload protocols/arguments instead of importing concrete pipeline result classes across modules.
- Prefer ordinal type aliases (e.g.,
MessageOrdinal,ChunkOrdinal) over rawintin pipeline code for readability. - When the user asks to "fix the test only", update tests/mocks first and avoid adding production compatibility fallbacks unless explicitly requested.
- For date/time range handling, use the half-open interval convention
[start, stop)(stop is exclusive), as agreed in PR #198 — this avoids the ambiguity of an inclusive end (e.g. does "end of day" mean 00:00:00 or 23:59:59.999999?). Prefer this over inclusive-end ranges even when padding the end to end-of-day would also work.
Package Management with uv
- Use
uv add <package>to add new dependencies - Use
uv add <package> --upgradeto upgrade existing packages - Important: uv automatically updates
pyproject.tomlwhen adding/upgrading packages - Do NOT manually edit
pyproject.tomldependency versions after running uv commands - uv maintains consistency between
pyproject.toml,uv.lock, and installed packages - Trust uv's automatic version resolution and file management
- Never raise the lower bounds in
[project.dependencies]or[project.optional-dependencies]as part of a dependency update. Those bounds ship in the wheel metadata and constrain every project that depends on typeagent; a high floor on a shared dependency is a common cause of unsolvable resolutions for downstream users. Raise a floor only when our code actually needs the newer version, and add an upper bound only for a known incompatibility (with a comment saying what breaks and what it would take to lift the cap). - Bumping versions in
[dependency-groups] devis fine -- that only selects which versions the dev tools run with here and in CI, and never reaches the published wheel. Same foruv.lock, which is where routine "get the latest versions" updates belong.
IMPORTANT! YOU ARE NOT DONE UNTIL make format check test PASSES
Code generation
When generating Python code (e.g. when translating TypeScript to Python), please follow these guidelines:
- When creating a new file, add a copyright header to the top:
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.- Assume Python 3.12
from __future__ import annotationsis not allowed.- Always strip trailing spaces
- Keep docstrings in sync with code when changing implementation.
- Keep class and type names in
PascalCase - Use
python_casefor variable/field and function/method names - Use
Literalfor unions of string literals - Keep union notation (
X | Y) for other unions - Use
Protocolfor interfaces whose name starts withIfollowed by a capital letter - Use
dataclassfor other classes and structured types - Use
typefor type aliases (PascalCaseagain) - Use
list,tuple,dict,setetc., notListetc. - Translate
foo?: stringtofoo: str | None = None - When writing tests:
- don't mock; use the regular implementation (maybe introduce a fixture to create it)
- assume
pytest; useassertstatements - match the type annotations of the tested functions
- read the code of the tested functions to understand their behavior
- When using fixtures:
- Fully type-annotate the fixture definitions (including return type)
- Fully type-annotate fixture usages
- Don't put imports inside functions.
Put them at the top of the file with the other imports.
Exception: imports in a
if __name__ == "__main__":block or amain()function. Another exception: pydantic and logfire. Final exception: to avoid circular import errors. - Import Architecture Rules:
- Never import a symbol from a module that just re-exports it
- Always import directly from the module that defines the symbol
- Exception: Package
__init__.pyfiles that explicitly re-export with__all__ - Exception: Explicit re-export patterns like
from ... import X as Xor marked with "# For export" - This prevents circular imports and makes dependencies clear
Python Import Style Guidelines
- Default to Module-Qualified Imports: Prefer importing whole modules and using qualified calls (e.g.,
import math; math.sqrt(16)orimport pandas as pd; pd.DataFrame()) to prevent namespace pollution, avoid name clashes, and provide immediate context for where functions or objects originate. - Use Direct Symbol Imports Cautiously: Restrict direct imports (
from module import symbol) to specific scenarios where they genuinely improve readability or adhere to standard conventions:- Importing classes, exceptions, or constants (e.g.,
from my_project.models import User). - Avoiding severe, repetitive visual clutter in heavy mathematical or algorithmic code.
- Standard library patterns (e.g.,
from collections import defaultdict, Counter). - Exception: In
tests/, importing functions directly to call them in assertions is idiomatic pytest style and is not held to this restriction (see #298).
- Importing classes, exceptions, or constants (e.g.,
- Prohibit Wildcard Imports: Never use wildcard imports (
from module import *) in normal code. Exception: the same explicit re-export aggregator pattern allowed by the Import Architecture Rules above (e.g.interfaces.pyre-exportinginterfaces_core,interfaces_indexes, etc. with__all__) — enforced bymake ruff(see Makefile), with that file listed in[tool.ruff.lint.per-file-ignores]. - Order imports alphabetically after lowercasing; group them as follows
(with a blank line between groups):
- standard library imports
- established third-party libraries
- experimental third-party libraries (e.g.
typechat) - local imports (e.g.
from typeagent.knowpro import ...)
- Error Handling: Don't use
try/except Exceptionto catch errors broadly. Let errors bubble up naturally for proper error handling and debugging at higher levels. - Code Validation: Don't use
py_compilefor syntax checking. Usepyrightormake checkinstead for proper type checking and validation. - Deprecations: Don't deprecate things -- just delete them and fix the usage sites. Don't create backward compatibility APIs or exports or whatever. Fix the usage sites.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

