How lean-dojo/leancopilot works
Main Components
• Core Lean Copilot Package: Represent the Lean code, including files like LeanCopilot.lean, LeanCopilot/Frontend.lean, LeanCopilot/Tactics.lean, and related option/configuration files. This part implements tactics such as suggest_tactics, search_proof, and select_premises.
• Model Infrastructure: Show the different model modules under LeanCopilot/Models, e.g., Builtin, ByT5, External, FFI, Generic, Interface, Native, and Registry. They are key in abstracting different “model types” (generators and encoders) and their APIs.
• Model Checkpoint Manager: Include the separate component (ModelCheckpointManager directory) that handles downloading and managing model checkpoint files.
• External Integration:
• C++ Integration: The cpp directory (with ct2.cpp and headers) provides C++ integration for native model inference with CTranslate2, used via Lean’s FFI.
• Python API Server: The python directory illustrates an external server component that wraps around various external models (see python/external_models/*) and exposes them using an API (supported by external_model_api.yaml).
• Build and Testing Infrastructure: Represent build tools and scripts (Dockerfile, .dockerignore, build scripts in scripts/, lakefile.lean and lake-manifest.json) as well as the test suite (LeanCopilotTests directory).
Detail the Relationships and Interactions
• That the Lean Copilot core acts as the orchestration layer:
• It calls the Model APIs (via abstract interfaces defined in the Models directory) to generate tactic suggestions, perform proof search, and select premises.
• There is a direct connection between the core tactics and the underlying model activations.
• Distinguish between the native and external model flows:
• Native flow: Illustrate that when using the native generators/encoders, Lean Copilot relies on FFI to interact with the C++ component (cpp/) and CTranslate2 libraries.
• Also, show the model checkpoint/management component that interacts with both native and external model lifecycles (e.g., downloading or updating checkpoints).
Architectural Patterns and Design Principles
• Modular design: The clear separation between core Lean tactics and model adapters (generator and encoder interfaces) suggests a layered design.
• Abstraction: Emphasize the use of typeclasses (e.g., TextToText, TextToVec) that enable plug-and-play of different models.
• Interoperability: Note the integration of Lean with external components in C++ (using FFI) and Python, showing a multi-language, multi-backend architecture.
• Testing and Continuous Integration: Include components that represent the test suites and CI configurations (.github/workflows).