mistral-common
AGENTS.md960 starsChanged 12 days agoApache-2.0View on GitHub
Mistral-Common is a preprocessing library for Mistral's Large Language Models (LLMs). It encodes requests for Instruct, Transcription or Fill-In-The-Middle (FIM) tasks to tokens and optionally processed images or audios. - Language: Python 3.11 to 3.15 - Package Manager: uv - Testing: pytest - Formatting and Linting: Ruff - Type checker: mypy - CI: GitHub Actions
Where files are headingNew AGENTS.md files have more rules about keeping secrets out of the code, and fewer about code style.
Of the AGENTS.md files we read, the 31,439 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.
The file
Show its rules and text
We split this AGENTS.md into the rules it gives an agent
24 rules. About 0 are common, 15 are distinctive, and 9 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈15
Distinctive · estimate
This author's own choices. Worth a look.
9
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 117
Use Python functionalities supported by Python 3.11
- Very specific: line 118
Call function arguments explicitly by keyword, not implicitly by position (e.g.
- Distinctive: line 121
Do NOT write comments that paraphrase or restate what the code already says.
- Distinctive: line 125
Use absolute imports for modules within the project
- Distinctive: line 126
Do NOT use wildcard imports
- Very specific: line 127
Do NOT add import inside __init__
- Very specific: line 128
Use TYPE_CHECKING blocks for type-only imports
- Very specific: line 129
Do NOT use from __future__ import annotations
- Distinctive: line 132
Use Python's type hints extensively
- Distinctive: line 133
Use modern (Python 3.11+) typing module types
- Very specific: line 136
Use custom exceptions from mistral_common.exceptions
- Very specific: line 143
Use r""" for raw docstrings
- Distinctive: line 144
Document all parameters and return values.
- Distinctive: line 145
Do NOT put types in the docstring for parameters and return values.
- Distinctive: line 152
Avoid coverage-only comments.
- Distinctive: line 171
Follow code style guidelines
- Distinctive: line 172
Write tests for new functionality
- Very specific: line 174
When adding dependencies, modify root pyproject.toml, then run uv lock followed by uv sync --frozen
- Distinctive: line 186
Run the type checker:
- Distinctive: line 192
Run unit tests with coverage:
- Very specific: line 204
Run integration tests when changing chat templates, integrations, or tokenizer behavior those templates cover.
- Very specific: line 223
Use uv run zensical build for a one-shot static build into site/.
- Distinctive: line 226
After adding your changes before committing ensure pre-commit is installed or run it manually.
- Distinctive: line 227
Use imperative grammar, start with a verb and be concise.
≈ “Common” is an estimate: at least 1 in 5 of the 40,246 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
AGENTS.md
Project overview
Mistral-Common is a preprocessing library for Mistral's Large Language Models (LLMs). It encodes requests for Instruct, Transcription or Fill-In-The-Middle (FIM) tasks to tokens and optionally processed images or audios.
- Language: Python 3.11 to 3.15
- Package Manager: uv
- Testing: pytest
- Formatting and Linting: Ruff
- Type checker: mypy
- CI: GitHub Actions
Project Structure
mistral-common/
├── src/
│ └── mistral_common/
│ ├── guidance/
│ ├── integrations/
│ ├── protocol/
│ ├── tokens/
│ └── ...
├── scripts/
├── tests/
├── docs/
├── .github/
├── .pre-commit-config.yaml
├── pyproject.toml
└── README.mdRoot-level files in src/mistral_common/
audio.py: Audio processing utilities including Audio class and mel-scale conversionsbase.py: Base Pydantic model configurationdeprecation.py: Deprecation utilities (deprecated_import,warn_once) for emitting one-shot warnings on moved or removed symbolsexceptions.py: Custom exception classes for the libraryimage.py: Image processing utilities including download and serializationimports.py: Import utilities and dependency checksmultimodal.py: Multimodal processing utilities deprecated in favor toimage.py
Protocol
src/mistral_common/protocol/: Protocol handlinginstruct/: Instruct protocolchunk.py: Chunks content used by messagesconverters.py: Converter helpers betweenChatCompletionRequestandOpenairequestsmessages.py: Instruct messages definitionnormalize.py: Normalizers forChatCompletionRequestrequest.py: Definition ofChatCompletionRequest. This is the entry point of user queries for Instruct requeststool_calls.py: Tool calling logicvalidator.py: Validators forChatCompletionRequest
fim/: Fill-in-the-middle protocolrequest.py: Definition ofFIMRequest. This is the entry point of user queries for FIM requests
transcription/: Transcription protocolrequest.py: Definition ofTranscriptionRequest. This is the entry point of user queries for Transcription requests
speech/: Speech protocolrequest.py: Definition ofSpeechRequest. This is the entry point of user queries for Speech requests
base.py: Definition ofBaseCompletionRequestsubclassed by FIM and Instruct requestsutils.py: Utility functions
Tokenization
src/mistral_common/tokens/: Tokenizationtokenizers/: Tokenizer implementationsaudio.py: Audio processingbase.py: Base Tokenizer implementationimage.py: Image processinginstruct.py: Instruct Tokenizer that encodes requests via Tekken tokenizermistral.py: Mistral Tokenizer that normalizes and validates requests to pass them to an instruct tokenizermodel_settings_builder.py: Builders (FieldBuilder,EnumBuilder,ModelSettingsBuilder) for validating and constructing model settingsmultimodal.py: deprecated in favor ofimage.pysentencepiece.py: Sentence Piece tokenizer (deprecated)tekken.py: Tekken tokenizer used by all recent modelsutils.py: Utility functions for the tokenizers
instruct/: deprecated in favor ofsrc/mistral_common/protocol/instruct/request.py
Guidance (Grammar)
src/mistral_common/guidance/: Creates Lark grammars for tool calls, JSON schema and reasoning using llguidancegrammar_factory.py:GrammarFactorythat builds and renders Lark grammars from Jinja templatestokenizer.py: Adapts Tekken tokenizer for llguidancedata/: Jinja-templated Lark grammar files for base, thinking (special tokens) and thinking (plain text) modes
Integrations
src/mistral_common/integrations/: Third-party framework integrationschat_templates/: Chat template generation for HuggingFace Transformerschat_templates.py: Public API for generating chat templates (generate_chat_template)template_generator.py: Core template generation engine withTemplateConfigandbuild_chat_template
Scripts
scripts/generate_chat_template.py: CLI for generating and saving chat templates
Experimental
src/mistral_common/experimental/: Experimental featuresutils.py: Utility functionstools.py: Tool calls parserthink.py: Thinking parserapp/: FastAPI applicationrouters.py: API routersmain.py: Application entry pointmodels.py: Pydantic models
Data
src/mistral_common/data/: Data files for tokenizers
Other files and directories
tests/: Test suitedocs/: Documentation.github/workflows/: CI/CD workflows.pre-commit-config.yaml: Pre-commit hookspyproject.toml: Project configuration
Code Style Guidelines
Style
- Respect ruff and mypy rules
- Naming: snake_case for functions/variables, PascalCase for classes
- Use Python functionalities supported by Python 3.11
- Call function arguments explicitly by keyword, not implicitly by position (e.g.
fn(x=1, y=2), notfn(1, 2))
Comments
- Do NOT write comments that paraphrase or restate what the code already says.
- Comments should explain the "why" (intent, rationale, non-obvious constraints), not the "what".
Imports
- Use absolute imports for modules within the project
- Do NOT use wildcard imports
- Do NOT add import inside
__init__ - Use
TYPE_CHECKINGblocks for type-only imports - Do NOT use
from __future__ import annotations
Type Hints (Required)
- Use Python's type hints extensively
- Use modern (Python 3.11+) typing module types
Error Handling
- Use custom exceptions from
mistral_common.exceptions - Provide meaningful error messages
Docstrings (Required)
- Use Google-style docstrings
- One-liner for simple functions
- Multi-line with Args/Returns for complex ones
- Use
r"""for raw docstrings - Document all parameters and return values.
- Do NOT put types in the docstring for parameters and return values.
- For the returns sections, only describe the returned value and do not write its name
- Include examples where appropriate that can be tested via
doctest
Coverage
- Aim for high, meaningful coverage. Prioritise tests that verify behaviour over hitting a line-count target.
- New and changed code should be covered by tests.
- Avoid coverage-only comments. Prefer restructuring so branches are genuinely reachable and tested (e.g. validate inputs and test the error path) over excluding lines.
Test organization
- New unit tests belong under
tests/unit/and mirror the source package structure. - New integration tests belong under
tests/integration/and exercise public workflows. - Existing tests elsewhere are legacy during the ongoing migration and are removed as their replacements land.
Development Workflow
- Set up using uv
uv sync --frozen --all-extras --group dev --python 3.12
source .venv/bin/activate
uv run pre-commit install- Make Changes
- Follow code style guidelines
- Write tests for new functionality
- Update documentation
- When adding dependencies, modify root
pyproject.toml, then runuv lockfollowed byuv sync --frozen - Backward Compatibility: Don't break existing functionality
Run checks
- Lint and check formatting:
uv run ruff check . uv run ruff format . --check- Run the type checker:
uv run mypy .- Run unit tests with coverage:
uv run pytest --cov=mistral_common tests/ --ignore=tests/integrations --ignore=tests/integration -n auto --dist loadfile- Run doctests:
uv run pytest --doctest-modules ./src- Run integration tests when changing chat templates, integrations, or
tokenizer behavior those templates cover. Install the
test-integrationsdependency group first, otherwise the Transformers tests are skipped:
uv sync --frozen --all-extras --group dev --group test-integrations uv run pytest tests/integrations/ -n auto --dist loadfile
Build documentation locally
The documentation is built with Zensical (a drop-in successor to MkDocs that reads mkdocs.yml natively):
uv sync --frozen --all-extras --group docs
uv run python docs/gen_api_pages.py # generate the code reference pages
uv run zensical serve # live preview at http://localhost:8000Use uv run zensical build for a one-shot static build into site/.
Commit
- After adding your changes before committing ensure pre-commit is installed or run it manually.
- Use imperative grammar, start with a verb and be concise.
Additional Resources
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.

