LeanDojo v2 is built around a four-layer pipeline that takes a raw Lean 4 repository all the way through structured theorem data, model training, and automated proof search. Each layer has clean boundaries so you can reuse any slice — run the tracer without an agent, swap in a custom trainer, or point an existing model at a Pantograph server without touching the database. Understanding how the layers connect is the fastest way to orient yourself in the codebase.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/lean-dojo/LeanDojo-v2/llms.txt
Use this file to discover all available pages before exploring further.
The Four-Layer Model
Trace — instrument and extract
The
lean_dojo_v2.lean_dojo sub-package clones a repository, runs lake build, then injects the custom ExtractData.lean module and re-runs lake env lean --run ExtractData.lean to capture .ast.json and .dep_paths artifacts for every compiled Lean file. The result is a TracedRepo object that holds typed wrappers around every theorem, tactic, premise, and AST node.Key classes: LeanGitRepo (describes a repo by URL + commit), trace() (the public entry-point function), TracedRepo, TracedFile, TracedTheorem, TracedTactic.Store — manage the dynamic database
DynamicDatabase is a JSON-backed persistent store. After tracing, it records every Repository object along with its theorems (categorised as proven, sorry-proved, or sorry-unproved), premise files, traced file paths, and difficulty ratings. It also exposes export_merged_data() to produce the JSONL datasets that trainers consume.Key classes: DynamicDatabase, Repository, Theorem, PremiseFile.Train — fine-tune models on theorem data
The
trainer layer reads the exported datasets and fine-tunes language models or retrieval encoders. All trainers integrate with Hugging Face Transformers, and the supervised and RL trainers support LoRA via PEFT and DeepSpeed for multi-GPU runs.Key classes: SFTTrainer (supervised fine-tuning), GRPOTrainer (group-relative policy optimisation), RetrievalTrainer (ByT5-based dense retrieval), ProgressTrainer (step-count regression head).Prove — search for proofs via Pantograph RPC
The
prover layer opens a Pantograph Lean RPC server and iteratively applies tactics until the goal list is empty. All provers share a common search interface: the difference is how they generate candidate tactics — from a local HF checkpoint, from the HF Inference API, or from a retrieval-augmented tactic generator.Key classes: HFProver, ExternalProver, RetrievalProver.Agent Abstractions
BaseAgent orchestrates the entire pipeline. It wraps DynamicDatabase, calls trace_repository() during setup, delegates to a trainer during train(), and delegates to a prover during prove(). Subclasses override _get_build_deps() to control whether dependency packages are traced, and _setup_prover() to wire in the right prover implementation.
Agent-Trainer-Prover Pairings
| Agent | Trainer | Prover | Notes |
|---|---|---|---|
HFAgent | SFTTrainer / GRPOTrainer | HFProver | Local GPU inference; LoRA-ready |
LeanAgent | RetrievalTrainer | RetrievalProver | Lifelong learning; build_deps=True required |
ExternalAgent | (none) | ExternalProver | HF Inference API; no local training |
ExternalAgent skips the training step entirely and delegates proof search directly to the HF Inference API (default: DeepSeek-Prover-V2-671B). It is the fastest way to prove theorems without local GPU resources.HFAgent Example
LeanAgent Example
External API Layer
Thelean_dojo_v2/external_api/ folder exposes a FastAPI + uvicorn HTTP server alongside Lean frontend snippets that allow Lean editor plugins (via LeanCopilot) to query large language models for tactic suggestions. This layer is independent of the agent pipeline — you can run it as a standalone service pointed at any OpenAI-compatible inference backend.
Component Map
Tracing
How
LeanGitRepo, trace(), and ExtractData.lean instrument a Lean 4 repository to extract proof states, ASTs, and premises.Database
How
DynamicDatabase stores repositories, theorems, premise files, and sorry status across lifelong training runs.Curriculum Learning
How difficulty scores and percentile thresholds sort repositories and theorems into progressive training schedules.
Quickstart Guide
End-to-end example: trace a repo, build a dataset, fine-tune a model, and prove sorry theorems in minutes.