A research team has introduced FM-Agent, the first framework to achieve automated compositional reasoning for large-scale software systems, addressing a critical challenge in verifying code generated by large language models (LLMs). The work, detailed in a paper on arXiv, demonstrates how LLMs themselves can be harnessed to scale formal methods to systems with up to 143,000 lines of code, uncovering hundreds of bugs missed by conventional testing.
The Problem: Formal Methods at Scale
LLM-assisted software development has become increasingly prevalent, producing large-scale systems such as compilers. Ensuring the correctness of such code is crucial, but automated reasoning remains difficult due to code complexity. Hoare logic, a formal system for reasoning about program correctness, offers a way to decompose a large system into smaller components and reason about them separately (compositional reasoning). However, according to the paper, existing approaches struggle because Hoare logic requires writing formal specifications for each function, imposing a heavy human burden. This problem is exacerbated when code is generated by LLMs, as developers lack a deep understanding of each function's expected behavior.
How FM-Agent Works
FM-Agent leverages LLMs to introduce a top-down paradigm that automatically generates function-level specifications. Specifically, it derives the specification of a function from how its callers expect the function to behave, so the generated specifications can reflect the developer's intent even if the implementation is buggy. Developers' intent is usually expressed in natural language, while existing verifiers only support formulas. Therefore, FM-Agent generalizes Hoare-style inference to reason about functions against natural-language specifications. Finally, to confirm bug existence and explain bug causes, it automatically generates test cases to trigger potential bugs.
Evaluation Results
The researchers evaluated FM-Agent on large-scale systems, each with up to 143,000 lines of code. The systems had already been tested by their developers, but FM-Agent still found 522 newly discovered bugs. The paper states that these bugs can cause serious consequences, including system crashes and incorrect execution results. FM-Agent completed its reasoning within two days for each system.
Implications for Enterprise Software
For enterprise technology leaders, the ability to automatically verify code correctness at scale is significant. As organizations increasingly rely on LLM-generated code for critical applications—from compilers to data processing pipelines—the risk of hidden bugs rises. FM-Agent's approach offers a path to reduce that risk by automating formal verification without requiring developers to write exhaustive specifications. While the research is still in academic stages, the findings suggest that combining LLMs with formal methods could become a practical tool for ensuring software reliability in production environments.