Skip to content

Commit d493e11

Browse files
gvanrossum-msgvanrossum
authored andcommitted
Move instructions to AGENTS.md
1 parent efb8e36 commit d493e11

File tree

2 files changed

+102
-193
lines changed

2 files changed

+102
-193
lines changed

.github/copilot-instructions.md

Lines changed: 0 additions & 193 deletions
This file was deleted.

AGENTS.md

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
---
2+
applyTo: '**/*.py'
3+
---
4+
5+
**DO NOT BE OBSEQUIOUS**
6+
7+
# For Agent mode
8+
9+
**NEVER use TEST_MODEL_NAME or "test" embedding model outside of test files**
10+
11+
Never run git commands that many any changes. (`git status` and `git diff` are fine)
12+
13+
**NEVER COMMIT CODE. Do not run `git commit` or any other git commands that make changes to the repository. Not even `git add`**
14+
15+
When moving, copying or deleting files, use the git commands: `git mv`, `git cp`, `git rm`
16+
17+
When the working directory is ~/TypeAgent/python/ta/:
18+
19+
- Don't use '!' on the command line, it's some bash magic (even inside single quotes)
20+
- Activate `.venv`: make venv; source .venv/bin/activate
21+
- To get API keys in ad-hoc code, run `typeagent.aitools.utils.load_dotenv()`
22+
- Use pytest to run tests in test/
23+
- Use pyright to check type annotations in tools/, test/, typeagent/
24+
- Ignore build/, dist/
25+
- You can also use the pylance extension for type checking in VS Code
26+
- Use `make check` to type-check all files
27+
- Use `make test` to run all tests
28+
- Use `make check test` to run `make check` and if it passes also run `make test`
29+
30+
## Package Management with uv
31+
32+
- Use `uv add <package>` to add new dependencies
33+
- Use `uv add <package> --upgrade` to upgrade existing packages
34+
- **Important**: uv automatically updates `pyproject.toml` when adding/upgrading packages
35+
- **Do NOT** manually edit `pyproject.toml` dependency versions after running uv commands
36+
- uv maintains consistency between `pyproject.toml`, `uv.lock`, and installed packages
37+
- Trust uv's automatic version resolution and file management
38+
39+
**IMPORTANT! YOU ARE NOT DONE UNTIL `make check test format` PASSES**
40+
41+
# Code generation
42+
43+
When generating Python code (e.g. when translating TypeScript to Python),
44+
please follow these guidelines:
45+
46+
* When creating a new file, add a copyright header to the top:
47+
```
48+
# Copyright (c) Microsoft Corporation.
49+
# Licensed under the MIT License.
50+
```
51+
52+
* Assume Python 3.12
53+
54+
* Always strip trailing spaces
55+
56+
* Keep class and type names in `PascalCase`
57+
* Use `python_case` for variable/field and function/method names
58+
59+
* Use `Literal` for unions of string literals
60+
* Keep union notation (`X | Y`) for other unions
61+
* Use `Protocol` for interfaces whose name starts with `I`
62+
followed by a capital letter
63+
* Use `dataclass` for other classes and structured types
64+
* Use `type` for type aliases (`PascalCase` again)
65+
* Use `list`, `tuple`, `dict`, `set` etc., not `List` etc.
66+
67+
* Translate `foo?: string` to `foo: str | None = None`
68+
69+
* When writing tests:
70+
- don't mock; use the regular implementation (maybe introduce a fixture to create it)
71+
- assume `pytest`; use `assert` statements
72+
- match the type annotations of the tested functions
73+
- read the code of the tested functions to understand their behavior
74+
- When using fixtures:
75+
- Fully type-annotate the fixture definitions (including return type)
76+
- Fully type-annotate fixture usages
77+
78+
* Don't put imports inside functions.
79+
Put them at the top of the file with the other imports.
80+
Exception: imports in a `if __name__ == "__main__":` block or a `main()` function.
81+
Another exception: pydantic and logfire.
82+
Final exception: to avoid circular import errors.
83+
84+
* **Import Architecture Rules**:
85+
- **Never import a symbol from a module that just re-exports it**
86+
- **Always import directly from the module that defines the symbol**
87+
- **Exception**: Package `__init__.py` files that explicitly re-export with `__all__`
88+
- **Exception**: Explicit re-export patterns like `from ... import X as X` or marked with "# For export"
89+
- This prevents circular imports and makes dependencies clear
90+
91+
* Order imports alphabetically after lowercasing; group them as follows
92+
(with a blank line between groups):
93+
1. standard library imports
94+
2. established third-party libraries
95+
3. experimental third-party libraries (e.g. `typechat`)
96+
4. local imports (e.g. `from typeagent.knowpro import ...`)
97+
98+
* **Error Handling**: Don't use `try/except Exception` to catch errors broadly.
99+
Let errors bubble up naturally for proper error handling and debugging at higher levels.
100+
101+
* **Code Validation**: Don't use `py_compile` for syntax checking.
102+
Use `pyright` or `make check` instead for proper type checking and validation.

0 commit comments

Comments
 (0)