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

*Ruida Wang, Jerry Huang, Pengcheng Wang, Xuanqing Liu, Chris Kong, Tong Zhang*

[NeurIPS page](https://neurips.cc/virtual/2026/poster/153964) · [Open on the map](../papers.html#p153964)

Category: [LLM Agents, Evals & Benchmarks](../pcat/17.md) › [LLM-Driven Code Synthesis and Verification](../pgroup/32.md) · Type: new method · Keywords: formal verification, LLM agents, workflow modeling, dependent-type languages, semantic consistency, software engineering benchmarks

Areas: [AI Agents](../areas/agents.md) › Agent Benchmarking › Agentic code and proof generation; [Evaluation & Benchmarks](../areas/evaluation.md) › Language Model and Agent Benchmarks › Code Generation Benchmarks; [Benchmarks for LLMs & Agents](../areas/bench-llm-agents.md) › Cross-Domain Agent Evaluation › Agent Benchmarking

## Summary
Lean4Agent introduces a framework using Lean4 to formally model and verify LLM agent workflows, improving reliability and enabling workflow evolution.

## Explained to a 5-year-old
Some smart computer programs called LLMs try to do many steps to solve problems. Right now, people don't have a way to be sure these steps are always correct. This paper creates a new method that uses a special language to check that the steps make sense. It also helps fix the steps when they go wrong, making the program work better. This helps make the computer helpers more trustworthy and useful.

## Explained to a 5-year-old, longer
Large language models are computer programs that can talk and write. Sometimes they are asked to do many things in a row, like solving a puzzle step by step. It is hard to know if they will always do those steps correctly. Without checking, they might make mistakes that are hard to find. This paper introduces a way to write down the steps in a very precise language. This precise language works like a set of rules that can be checked automatically. By using this language, the authors can see if the steps match what they are supposed to do. They also built a tool that points out where a mistake happens in the steps. With this tool, they can fix the steps so they work better. They tested the tool on two sets of problems, one about fixing code and one about other tasks. The steps that passed the check worked much better than those that didn't. This makes the computer helpers more reliable and easier to trust.

## For a technical reader
The authors propose a framework that uses a formal, type-based language to describe and verify the behavior of multi-step LLM agents. It includes an extensible library that lets developers model workflows, enforce semantic consistency under explicit assumptions, and pinpoint execution failures from recorded trajectories. Building on this library, they add a workflow-revision module that automatically adjusts workflows to improve success rates. Experiments on two benchmark suites show that verified workflows outperform unverified ones by roughly 12 % and that the revision step adds another ~7 % gain on software-engineering tasks. The approach provides a practical way for engineers to build more reliable agents without having to manually debug every step.

## Problem
Equipping large language models to execute reliable multi-step workflows is challenging because existing agent systems lack formal methods for specifying, verifying, and debugging their behavior.

## Method
The approach uses a dependent-type formal language to create an extensible library for modeling agent workflows, verifying semantic consistency under assumptions, localizing execution failures, and revising workflows to improve performance.

## Results
The approach achieved an average 11.94% improvement on verification-passing workflows compared to failing ones, and the workflow revision component further improved performance by 7.47% on SWE-Bench.

## Contributions
The paper introduces a formal framework using dependent-type languages for modeling and verifying agent workflows, provides an extensible library for semantic consistency and failure localization, and demonstrates workflow revision to enhance capability.

## Practical relevance
It enables developers to build more reliable LLM agents by formally verifying their workflows, reducing debugging effort and improving performance.

## Research questions this paper is counted under

- [How can large language models be guided to generate better intermediate reasoning steps and avoid redundant or over-long chains during problem solving?](../q/15.md)

This page was written by language models from the title and abstract of each paper, and the answers were checked by two other models. It can be wrong: check the paper itself. [Suggest a correction](../feedback/?on=p/153964)
