# Lean4Agent: Formal Modeling and Verification for Agent Workflow and Trajectory

DevFeed: [Lean4Agent: Formal Modeling and Verification for Agent Workflow and Trajectory](<https://devfeed.tech/articles/lean4agent-formal-modeling-and-verification-for-agent-workflow-and-trajectory-94599.md>)

Original publisher: [Read original article](<https://arxiv.org/abs/2606.06523>)

Author: Ruida Wang, Jerry Huang, Pengcheng Wang, Xuanqing Liu, Luyang Kong, Tong Zhang

Published: 2026-10-22T04:00:00Z

Content type: article

Language: en

Sources: [arXiv: Machine Learning](<https://devfeed.tech/sources/arxiv-machine-learning.md>), [arXiv: Software Engineering](<https://devfeed.tech/sources/arxiv-software-engineering.md>)

Topics: [Formal verification](<https://devfeed.tech/topics/formal-verification.md>), [Formal methods](<https://devfeed.tech/topics/formal-methods.md>), [Automated reasoning](<https://devfeed.tech/topics/automated-reasoning.md>), [llm-reasoning](<https://devfeed.tech/topics/llm-reasoning.md>), [Artificial Intelligence](<https://devfeed.tech/topics/ai.md>), [ai evaluation](<https://devfeed.tech/topics/ai-evaluation.md>)

Tags: [agent](<https://devfeed.tech/tags/agent.md>), [agent-workflows](<https://devfeed.tech/tags/agent-workflows.md>), [cs-ai](<https://devfeed.tech/tags/cs-ai.md>), [cs-lg](<https://devfeed.tech/tags/cs-lg.md>), [cs-lo](<https://devfeed.tech/tags/cs-lo.md>), [cs-se](<https://devfeed.tech/tags/cs-se.md>), [formal](<https://devfeed.tech/tags/formal.md>), [formal-methods](<https://devfeed.tech/tags/formal-methods.md>), [foundation](<https://devfeed.tech/tags/foundation.md>), [framework](<https://devfeed.tech/tags/framework.md>), [language-models](<https://devfeed.tech/tags/language-models.md>), [large-language-models-llms](<https://devfeed.tech/tags/large-language-models-llms.md>), [llms](<https://devfeed.tech/tags/llms.md>), [modeling](<https://devfeed.tech/tags/modeling.md>), [verification](<https://devfeed.tech/tags/verification.md>), [workflow](<https://devfeed.tech/tags/workflow.md>), [workflows](<https://devfeed.tech/tags/workflows.md>)

## AI overview

Lean4Agent uses Lean4's dependent types to model and verify agent workflows under explicit assumptions. Its FormalAgentLib library checks workflow semantic consistency and helps localize execution failures from trajectories; LeanEvolve builds on those results to revise workflows. In experiments across five LLMs on a hard subset of SWE-Bench-Verified and a subset of ELAIP-Bench, verification-passing workflows outperformed failing ones by an average of 11.94%, while LeanEvolve improved SWE performance by an average of 7.47%. These are reported results on the specified subsets; the supplied text is an abstract and does not provide further methodological detail.

## Source excerpt

arXiv:2606.06523v3 Announce Type: replace-cross Abstract: Equipping Large Language Models (LLMs) to execute reliable multi-step workflows has become a central challenge in artificial intelligence. Despite recent advances in LLMs' agentic capabilities, most agent systems still lack formal methods for specifying, verifying, and debugging their workflow and execution trajectories. This challenge mirrors a long-standing problem in mathematics, where the ambiguity of natural languages (NLs) motivates the development of formal languages (FLs). Inspired by this paradigm, we propose **Lean4Agent**, to the best of our knowledge, the first framework that uses Lean4, a dependent-type FL to model and verify agent behavior. **Lean4Agent** launches **FormalAgentLib**, an extensible Lean4 library for formally modeling and verifying agent workflows' semantic consistency under explicit assumptions, and enabling localization of execution-time failures revealed by trajectories. Building on **FormalAgentLib**, we further develop **LeanEvolve**, which applies results in **FormalAgentLib** to revise workflows to enhance its capability. Extensive experiments on a hard problem subset of SWE-Bench-Verified and a subset of ELAIP-Bench across 5 leading LLMs indicate that the verification-passing workflows outperform the failing ones by an average of **11.94%**, and **LeanEvolve** further improves SWE performance by **7.47%** on average. Furthermore, **Lean4Agent** establishes a foundation for a new field of using expressive dependent-type FL to formally model and verify agent behavior.