YAML Metadata Warning:empty or missing yaml metadata in repo card
Check out the documentation for more information.
Multi-agent generative AI with formal verification in Lean 4
Course project, Inteligencia Computacional, Universidad Pedagógica y Tecnológica de Colombia (UPTC), Sogamoso. Authors: Kimberly Natalia Figueroa Zapata, Alisson Páez Alarcón.
A multi-agent system attempts to prove competition-level theorems from miniF2F in Lean 4 / Mathlib. A proof counts only if the Lean kernel accepts it. Six agents are orchestrated with LangGraph:
| Agent | Role |
|---|---|
| Planner | splits the problem into 2–5 subgoals |
| Retriever (RAG) | retrieves Mathlib lemmas by cosine similarity (BAAI/bge-small-en-v1.5, 123,201 theorems) |
| Generator | writes a detailed proof strategy |
| AutoFormalizer | turns the strategy into a Lean 4 tactic proof |
| LeanVerifier | compiles the proof with Lean/Mathlib |
| Critic | decides: retry (k ≤ 3), replan (r ≤ 1), finish or fail |
Control flow: PLAN → RETRIEVE → GENERATE → FORMALIZE → VERIFY → (CRITIQUE | DONE | FAIL).
Experiment
Five configurations on 30 miniF2F problems (10 development, 20 test; the test set was evaluated once, after the code was
frozen, tag congelado): Baseline A (one LLM call that writes the Lean proof directly, verified by Lean before delivery), Baseline B (two LLM
calls: reasoning in natural language, then Lean code. It is never verified before delivery, so it "delivers" every
proof and Lean is applied afterwards), w/o RAG, w/o Critic, Full. LLM: gemini-3.5-flash-lite (temperature 0, one run per configuration).
Test results (n = 20)
| Configuration | pass@1 | 95 % Wilson CI | Delivered | False positives | Mean LLM calls |
|---|---|---|---|---|---|
| Baseline A | 1/20 | [0.01, 0.24] | 1 | 0 | 1.0 |
| Baseline B | 2/20 | [0.03, 0.30] | 20 | 18 | 2.0 |
| w/o RAG | 3/20 | [0.05, 0.36] | 3 | 0 | 9.6 |
| w/o Critic | 2/20 | [0.03, 0.30] | 2 | 0 | 3.0 |
| Full | 2/20 | [0.03, 0.30] | 2 | 0 | 10.2 |
Honest reading: very few problems are solved; differences are at most one problem and none is statistically significant
(exact McNemar, Bonferroni ×5). The clear effect is verification: Baseline B delivered 20 proofs and Lean rejected 18.
No correct proof used a lemma retrieved by RAG, so RAG gets no credit here. See docs/TECHNICAL.md for details and limitations.
Repository map
| Folder or file | Content |
|---|---|
src/agents.py, src/contracts.py, src/prompts.py |
the six agents, their input/output contracts and prompts |
src/graph.py, src/pipeline.py |
orchestrator (LangGraph state machine) and the ablation presets |
src/retriever.py, rag/ |
RAG: Mathlib dump, index building, retrieval and its evaluation |
src/verifier_*.py, src/verify_*.py, lean_config/ |
Lean 4 + Mathlib verification (server, client, project files) |
src/baselines.py |
Baselines A and B |
data/ |
curated 30 problem set (eval_set.jsonl), audit notes, RAG reference queries |
results/ |
raw results (.jsonl) and analysis for development and test |
paper_results/ |
figures, tables and scripts used in the report (these replace notebooks) |
demo/ |
Gradio app (results explorer). The live demo is a static Space, see Links |
docs/ |
technical documentation (see below) |
tests/ |
114 unit, contract and integration tests (mock LLM, no API key needed) |
Documentation: docs/TECHNICAL.md (architecture and protocol), docs/INSTALL.md, docs/USER_GUIDE.md,
docs/AGENTS_INTERFACES.md, docs/REPRODUCE_ABLATIONS.md, docs/RESULTS.md.
Note: retrieval/ and experiments/ are early copies of rag/ and src/stats.py kept for history.
Links
- Space (results explorer, static): https://huggingface.co/spaces/KimberlyFigueroa01/lean-multiagent-explorer-static
(the Gradio version is in
demo/: Gradio hosting on the free tier requires a Hugging Face PRO plan) - Dataset and results: https://huggingface.co/datasets/KimberlyFigueroa01/lean-multiagent-minif2f-eval
- Code on GitHub: https://github.com/KimberlyFigueroa21/proyecto_ia_lean (tag
congelado) - Technical documentation:
docs/TECHNICAL.md; dataset card:DATASET_CARD.md
Reproducing
Requirements: Docker with Lean 4.36.0-rc2 + Mathlib (commit 9d581dfff2e41de989072ea63abf3daf69311520), Python 3.12,
a Gemini API key (GEMINI_API_KEY), the RAG index (rag_data/idx2, not in Git because of its size; see Hugging Face).
export GEMINI_MODEL=gemini-3.5-flash-lite
export GEMINI_API_KEY=... # never commit it
python3 -m src.verify_server & # Lean verification server (startup takes several minutes)
python3 run_experiment.py --split dev --rag-query lean --auto-resume
python3 run_experiment.py --split test --rag-query lean --auto-resume --allow-test
python3 analyze_results.py --split test
python3 -m pytest tests # 114 tests, no API key needed (mock LLM)
Free-tier limits (10 requests/minute, 500/day) make a full run take about a day; responses are cached on disk.
Limitations
Small evaluation set, single model and single run, tuning on 10 development problems, possible training-data contamination (miniF2F is public), heuristic error taxonomy, results tied to one Lean/Mathlib version.
Licenses
Code: MIT (see LICENSE). Lean 4 and Mathlib are Apache 2.0 licensed. miniF2F, the embedding model (BAAI/bge-small-en-v1.5) and the LLM (Gemini via Google AI Studio) keep their own licenses and terms.