Mistral 发布面向 Lean 4 的开源代码智能体 Leanstral
Leanstral: Open-Source foundation for trustworthy vibe-coding
Mistral 发布面向 Lean 4 的开源代码智能体 Leanstral(Leanstral-120B-A6B,激活参数 6B),权重采用 Apache 2.0。
AI 智能体已被证明是代码生成方面能力极强的工具。然而,当我们将这些模型推向高风险领域——从前沿研究数学到任务关键型软件——便会遇到一个规模化瓶颈:人工审查。人工验证所需的时间与专业知识,成为工程速度的主要阻力。
我们设想新一代更有帮助的编程智能体,既能执行其任务,又能依据严格规范对其实现作出形式化证明。人类不再调试机器生成的逻辑,而是规定自己想要什么。今天,我们正朝着这一愿景迈出第一个重大步骤。
隆重推出 Leanstral
我们发布 Leanstral,这是首个专为 Lean 4 设计的开源代码智能体。Lean4 是一种证明助手,能够表达复杂的数学对象,例如 完美胚空间,以及软件规范,例如 Rust 片段的性质。与现有那些作为大型通用模型封装器、或专注于单个数学问题的证明系统不同,Leanstral 以高效为目标(活跃参数为 6B),并针对在真实形式化仓库中运行进行了训练。
开放且易获取:我们以 Apache 2.0 许可证发布 Leanstral 权重,可在 Mistral vibe 的智能体模式中使用,也可通过免费 API 端点访问。我们还将发布一份详述训练方法的技术报告,以及新的评测套件 FLTEval,使评测不再局限于竞赛数学。
高效且强大:我们为 Leanstral 采用高度稀疏的架构,并针对证明工程任务加以优化。借助并行推理,并以 Lean 作为完美验证器,相较现有闭源竞争对手,Leanstral 既具备高性能,又具有成本效率。
可通过 MCP 升级:Leanstral 通过 vibe 支持任意 MCP,并经过专门训练,以在常用的 lean-lsp-mcp 上实现最佳性能。
评测
为体现其在真实证明工程场景中的用处,我们评测 Leanstral 能否完成 FLT 项目每个 PR 中的全部形式化证明,并正确定义新的数学概念,而不是孤立的数学问题。我们将 Leanstral 与领先的编程智能体(Claude Opus 4.6、Sonnet 4.6、Haiku 4.5)以及开源模型(Qwen3.5 397B-A17B、Kimi-K2.5 1T-A32B、GLM5 744B-A40B)进行比较。
Leanstral 与开源模型
Leanstral-120B-A6B 相较体量大得多的开源同类展现出显著的效率优势。尽管 GLM5-744B-A40B 和 Kimi-K2.5-1T-32B 等模型难以扩展,其 FLTEval 分数分别最高仅约 16.6 和 20.1,Leanstral 仅凭单次通过便超越了二者。
即便是所示最强的开源竞争对手 Qwen3.5-397B-A17B,也需要 4 次通过才能达到 25.4 分。相比之下,Leanstral 以一半的投入(pass@2)便取得更优的 26.3 分,并继续线性扩展,在相同成本水平达到 29.3。

Leanstral 与 Claude 系列
Leanstral 是 Claude 套件的高价值替代方案,以极低的价格提供有竞争力的性能:Leanstral 的 pass@2 达到 26.3 分,比 Sonnet 高出 2.6 分,而运行成本仅为 $36,Sonnet 则为 $549。在 pass@16 时,Leanstral 达到 31.9 分,以 8 分的优势轻松击败 Sonnet。尽管 Claude Opus 4.6 在质量上仍居领先,但其成本高达 $1,650,比运行 Leanstral 高出 92 倍。
在我们的基准测试中,我们使用 Mistral Vibe 作为脚手架,未针对本次评测做任何专门修改。
模型 | 成本($) | 得分 |
|---|---|---|
Haiku | 184 | 23.0 |
Sonnet | 549 | 23.7 |
Opus | 1,650 | 39.6 |
Leanstral | 18 | 21.9 |
Leanstral pass@2 | 36 | 26.3 |
Leanstral pass@4 | 72 | 29.3 |
Leanstral pass@8 | 145 | 31.0 |
Leanstral pass@16 | 290 | 31.9 |
案例研究
回答关于最新 Lean 版本变更的 Stack Exchange 帖子
当破坏性变更出现在新的 Lean 版本中时,迁移代码可能会非常头疼。我们向 Leanstral 提供了来自 Proof Assistants Stack Exchange 的一个真实问题,内容是一段脚本在 Lean 4.29.0-rc6 中莫名其妙无法编译(由于该版本较新,我们并未用它进行训练)。罪魁祸首是一个重写(rw)策略,它突然无法匹配涉及简单类型别名的模式,该别名最初写作 def T2 := List Bool。
Leanstral 并没有盲目尝试,而是动手排查。它成功编写了测试代码以复现失败环境,并诊断出定义相等性方面的根本问题。模型正确识别出:由于 def 会创建需要显式展开的刚性定义,它实际上阻碍了 rw 策略看到其匹配所需的底层结构。
它提出的修复很简单:只需把 def 换成 abbrev。因为 abbrev 会创建一个与原始类型立即定义相等的透明别名,rw 策略便能再次在证明中完美匹配模式 (L2 n).length。Leanstral 完成了这项工作,并向用户完美解释了其中的原理。
对程序进行推理
我们从 https://www.cs.princeton.edu/courses/archive/fall10/cos441/sf/Imp.html 复制了 Rocq 中的定义,并要求 Leanstral 将其转换为 Lean。它成功完成了转换,甚至实现了自定义记号。示例片段:
inductive ceval : com → state → state → Prop where
| E_Skip (st : state) : ceval .CSkip st st
| E_Ass (st : state) (a1 : aexp) (n : Nat) (l : ident) (h : aeval a1 st = n) :
ceval (.CAss l a1) st (update st l n)
| E_Seq (c1 c2 : com) (st st' st'' : state) (h1 : ceval c1 st st') (h2 : ceval c2 st' st'') :
ceval (.CSeq c1 c2) st st''
| E_IfTrue (st st' : state) (b1 : bexp) (c1 c2 : com) (h : beval b1 st = true) (h1 : ceval c1 st st') :
ceval (.CIf b1 c1 c2) st st'
| E_IfFalse (st st' : state) (b1 : bexp) (c1 c2 : com) (h : beval b1 st = false) (h1 : ceval c2 st st') :
ceval (.CIf b1 c1 c2) st st'
| E_WhileEnd (b1 : bexp) (st : state) (c1 : com) (h : beval b1 st = false) :
ceval (.CWhile b1 c1) st st
| E_WhileLoop (st st' st'' : state) (b1 : bexp) (c1 : com) (h1 : beval b1 st = true) (h2 : ceval c1 st st') (h3 : ceval (.CWhile b1 c1) st' st'') :
ceval (.CWhile b1 c1) st st''
-- Notation for command evaluation
notation:50 c " / " st " ⇒ " st' => ceval c st st'
它还可以在仅给出 Rocq 语句(不含证明)的情况下,将其翻译为 Lean,然后证明该语言中程序的一些性质:
-- Example command: adds 2 to variable X
def plus2 : com := .CAss "X" (.APlus (.AId "X") (.ANum 2))
-- Theorem: The plus2 command correctly adds 2 to variable X
-- Intuition: If X has value n in the initial state, after executing plus2,
-- X will have value n+2 in the final state
-- This specifies the behavior of the plus2 command
theorem plus2_spec (st : state) (n : Nat) (st' : state) (h1 : st "X" = n) (h2 : plus2 / st ⇒ st') :
st' "X" = n + 2 := by
-- plus2 is defined as .CAss "X" (.APlus (.AId "X") (.ANum 2))
-- Use equation compiler to unfold it
change ceval (.CAss "X" (.APlus (.AId "X") (.ANum 2))) st st' at h2
cases h2 with
| E_Ass _ _ n l h =>
have : aeval (.APlus (.AId "X") (.ANum 2)) st = n := h
simp only [aeval] at this
rw [update]
simp [← this, h1]
要求证明。立即试用 Leanstral。
Leanstral 即日起向所有人开放使用。
在 Mistral Vibe 中零配置:我们已将 Leanstral 直接集成到 Mistral Vibe 中,可立即进行零配置的 vibe 编程与证明。使用
/leanstall以激活。 然后要使用 Leanstral,请按Shift+Tab,直到模型显示为 Leanstral, 或者使用vibe --agent lean。Labs API:通过我们免费/近乎免费的 API 端点
labs-leanstral-2603访问该模型。我们将在有限时间内保持该端点高度可访问,以收集真实反馈和可观测性数据,为下一代经过验证的代码模型提供助力。拥有权重:下载采用 Apache 2.0 许可的模型,并在你自己的机器上运行。
来源:Mistral AI · mistral.ai