Agents are the top-level orchestrators in LeanDojo v2. Each agent manages the full lifecycle of a theorem-proving experiment: cloning and tracing a Lean repository, training a model on the resulting tactic data, and then driving a prover to closeDocumentation 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.
sorry goals. All three concrete agents — HFAgent, LeanAgent, and ExternalAgent — inherit from the abstract BaseAgent class, which supplies the shared machinery for repository management and the proof loop. You choose an agent based on the kind of model you want to use: a locally fine-tuned HuggingFace checkpoint, a RAG-based retrieval model, or a large hosted model accessed over an API.
Agent Hierarchy
BaseAgent defines the interface that every agent must satisfy. It owns a DynamicDatabase, a list of registered LeanGitRepo objects, and a shared data_path for merged training artifacts. The two abstract methods every subclass must implement are:
_get_build_deps() -> bool— controls whether the Lean tracing step resolves the repository’s external dependencies. SetTruefor retrieval-based workflows (so premises from dependencies appear in the corpus),Falseotherwise._setup_prover()— instantiatesself.proverwith whatever backend the agent uses.
Agent–Trainer–Prover Pairing
| Agent | Trainer | Prover | Builds Deps |
|---|---|---|---|
HFAgent | SFTTrainer or GRPOTrainer | HFProver | False |
LeanAgent | RetrievalTrainer | RetrievalProver | True |
ExternalAgent | (none) | ExternalProver | False |
Choosing an Agent
- HFAgent
- LeanAgent
- ExternalAgent
Use Full example (
HFAgent when you want to fine-tune a HuggingFace causal language model
on your own traced Lean repository and then use that checkpoint for proof
search. It is the right choice when you have a GPU available for local
training and inference, and you want full control over the model, LoRA
adapters, and hyperparameters.HFAgent calls _get_build_deps() → False, so dependency premises are
not added to the training corpus. The prover is initialised from the
same output_dir used by the trainer.Constructorexamples/sft.py)Common Methods
All three agents expose the same public interface defined byBaseAgent.
setup_github_repository(url, commit)
Clones the GitHub repository at the given URL and commit, traces it with Lean
instrumentation, and registers it in the internal DynamicDatabase. The
build_deps flag forwarded to the tracer is determined by _get_build_deps().
ValueError if tracing fails.
setup_local_repository(path)
Uses a local Lean project directory. The method calls
LeanGitRepo.from_path(path) to extract the URL and commit from the project’s
git history, then traces and registers the repo exactly like
setup_github_repository.
train()
Sorts all registered repositories by difficulty (via
database.sort_repositories_by_difficulty()) and calls the agent’s trainer
with the sorted list. Raises ValueError if no repository has been registered.
prove(whole_proof=False)
Collects all unproved sorry theorems across every registered repository, then
calls prove_theorem() for each one. Pass whole_proof=True to generate
complete proofs in a single forward pass instead of running the DFS search.
prove_theorem(theorem, repo, whole_proof=False)
Proves a single theorem. In proof-search mode, the method spins up a
pantograph.Server pointing at the traced repository, then calls
prover.search(server=server, theorem=theorem, verbose=False). In whole-proof
mode, it calls prover.generate_whole_proof(theorem) and prints the result.
True on success or False if no proof was
found, and prints the sequence of used tactics when a proof is found. In
whole-proof mode, prints the generated proof and returns None.
Building a Custom Agent
SubclassBaseAgent and implement the two abstract methods to wire up any
trainer/prover combination you like.
Trainers
Learn how to configure SFTTrainer, GRPOTrainer, RetrievalTrainer, and
ProgressTrainer for different training objectives.
Provers
Explore the three prover backends and understand proof search vs whole-proof
generation strategies.