Code evaluation · Research feature

AI Agents Proposed to Continuously Improve Code Quality in Software Maintenance

A research roadmap outlines how AI could continuously monitor and refine codebases to maintain software quality over time.

Adapted from research by Xin Sun, Daniel Ståhl, Kristian Sandahl and colleagues.

arXiv preprint revision · 2026-09-01 · Attribution & reuse
In this article
Editorial illustration of a sheet of visual frames.

Editor’s introduction

The study examines the potential for large language models to shift refactoring from occasional, manual tasks to a continuous process within software maintenance. It proposes that AI agents should monitor, evaluate, and autonomously improve codebases based on evolving definitions of quality, moving beyond isolated method-level changes. The paper notes that current approaches often focus on functional correctness and static metrics, which may not reflect overall code quality. It also highlights risks such as increased system coupling or memory usage when LLMs modify code to reduce local complexity.

Introduction

The emergence of large language models (LLMs) has brought substantial changes to software engineering. These models demonstrate strong capabilities in generating and modifying source code from natural language prompts. Such capabilities lead to a growing interest in using LLMs not only to implement new features but also to improve existing codebases through code refactoring, aiming to improve code quality and manage technical debt.

Recent work suggests that LLMs can effectively perform code refactoring on relatively straightforward tasks, reducing local complexity, repairing specific defects, and improving performance efficiency while preserving functional behavior. However, in more complex settings, LLM-based refactoring often encounters failures. At the repository level, generated changes may unintentionally violate functional correctness or cause substantial degradation in certain quality dimensions while improving others.

Consider a team maintaining a large-scale enterprise system spanning several million lines of code across hundreds of modules. Static analyzers flag thousands of code smells, but the team knows many are intentional: a deeply nested function preserves a real-time latency constraint, and a duplicated validation block remains in two services because extracting a shared library previously caused integration failures. An LLM-based tool might simplify a single method in isolation, but no existing system can determine which warnings should be addressed, balance a cross-module refactoring against an upcoming release deadline, or recognize that a redundant adapter layer preserves backward compatibility with an external API. This gap highlights the need to reassess how close we are to system-level automated software refactoring and what research methods are required to achieve it.

Code Refactoring

Code refactoring is an essential practice in software engineering. Unlike automated program repair, which aims to modify programs to fix bugs, code refactoring improves the internal structure without changing its behavior. Traditional refactoring relies heavily on developer experience and manual operations, requiring a profound understanding of software architecture and code quality. However, as software systems grow in complexity, manual refactoring becomes a time-consuming and error-prone task, leading many quality improvements to be deferred. The accumulation of deferred quality improvements leads to technical debt, which has been extensively studied as a critical challenge in software evolution. Importantly, technical debt is broader than just postponing to deal with code smells. It also includes invisible issues such as architectural debt and technological gaps, many of which cannot be fully revealed by static analyzers. Managing technical debt systematically requires not only identifying problematic code but also prioritizing and planning remediation efforts within broader project constraints. Existing machine learning approaches have been effective in technical debt detection and classification, but they often struggle to capture the nuanced semantics and context embedded in technical debt descriptions. LLMs provide new opportunities for automating parts of this process and have shown improved performance on related tasks.

The vision of autonomous software maintenance is not entirely new. Kephart and Chess articulated the vision of autonomic computing, in which systems manage themselves through self-configuration, self-optimization, self-healing, and self-protection. Cheng et al. subsequently established a research roadmap for software engineering of self-adaptive systems, identifying key challenges in modeling, requirements, and verification. The current pursuit of LLM-driven autonomous refactoring can be understood as a modern instantiation of these earlier visions, now enabled by the language understanding and generation capabilities of LLMs. Some studies argue that the IDE is the most practical environment for AI-assisted refactoring, combining static analysis tools with human-centered mechanisms to enable trustworthy adoption. However, achieving truly autonomous refactoring requires reasoning beyond the IDE workflow, incorporating repository and system-level context, global dependencies, and long-term evolution.

Unlike, which focuses on feature-level isolation, our roadmap considers refactoring at a much larger scale and emphasizes leveraging heterogeneous data sources to capture system constraints and design intent. Krüger et al. argued that current tools lack the ability to capture change intent and design motivation, calling for future software engineering tools to explicitly model the latent change intentions in software evolution.

Recent studies have explored how developers interact with LLMs during refactoring tasks and how effectively LLMs can identify refactoring opportunities and generate solutions. While these studies suggest promising potential, they also show that the generated refactorings may introduce new defects, hallucinations, or syntax errors, especially in repository-level contexts, requiring additional human verification. To mitigate these issues, researchers have proposed approaches that integrate LLMs with traditional development tools, such as static analysis and IDE environments, to support more reliable method-level refactoring. Other frameworks adopt agent-based workflows and multi-agent architecture that coordinate planning, code analysis, patch generation, and validation in an end-to-end process. Empirical studies suggest that such systems can improve modularity and automation, but maintaining functional correctness and handling large-scale project contexts remain challenging.

Roadmap

The dimensions presented in this roadmap were derived through a thematic analysis of the limitations and open challenges reported across the studies reviewed in Section II and the work of. We first examined the research questions, conclusions, and discussion sections of the selected studies. Statements describing reported challenges and future research directions were extracted and assigned initial codes representing underlying concerns about autonomous refactoring. Then, we iteratively compared and grouped the codes into semantically related themes. This process yielded five dimensions that capture recurring perspectives on future challenges in autonomous refactoring research and two practical concerns for industry adoption as presented in the following subsections.

To enable autonomous code refactoring, an underlying concern across several dimensions is intent communication. Much of what human engineers consider “good code” rests on implicit knowledge about conventions, trade-offs, and domain constraints that are rarely documented. When an AI agent violates these implicit preferences, the result is perceived as poor quality, even if the specification provided to the agent may never have specified those preferences. Addressing this gap requires new mechanisms that allow software engineers to communicate their intent to AI agents in actionable terms, so that agents can grasp contextual constraints and weigh trade-offs accordingly. Developing such mechanisms remains an open research question, to which this paper contributes a roadmap and an initial perspective.

The Multi-objective Optimization Problem

Modern software is a complex system of interdependent, evolving components. Single-objective refactoring at the system scale often harms other quality dimensions, a phenomenon particularly evident in cross-module refactoring. From a computational perspective, automated refactoring is a constrained multi-objective optimization problem (MOP). Given the inherent conflicts between objectives, improving one often degrades another, meaning no single solution optimizes all software quality metrics simultaneously. While local optima are easily found in code snippets, the complex search space created by interacting quality metrics at the system scale requires global constraint awareness to avoid regressive evolution.

However, framing refactoring as an MOP does not mean that existing optimization techniques can directly solve the problem. Software systems contain latent constraints that are not fully known upfront and must be revealed and refined over successive refactoring cycles. At the same time, many commonly used quality indicators are imperfect proxies for global properties, and improvements on these metrics can fail to translate into better system-level quality. These uncertainties shift the core challenge away from applying existing multi-objective optimization techniques and toward defining objective functions and constraints that reflect real-world software quality at the system level. The resulting search space is large and discontinuous, and the interactions among quality dimensions remain poorly understood at scale.

One illustrative direction is to adopt the decomposition and coordination ideas of MOEA/D, which is a multiobjective evolutionary algorithm based on decomposition, to autonomous refactoring. A global agent sets refactoring boundaries and Pareto-front priorities based on developer preferences and established quality standards, while system-level goals are decomposed into sub-tasks executed by specialized agents. Real-time feedback would connect local modifications back to global objectives, allowing the system to detect trade-offs and resolve conflicts across quality dimensions. The open research questions, however, go deeper: How can the trade-off between quality dimensions be characterized at the repository and system levels? What feedback mechanisms are needed to detect when local improvements degrade global properties? How should the search for possible refactoring actions be organized so that system-level optimization remains manageable?

The Problem of Definition and Evaluation

Existing research on refactoring largely focuses on functional correctness and typically evaluates non-functional quality using static analysis tools and manual reviews. However, optimizing specific static metrics does not necessarily improve overall code quality. Evidence suggests that LLMs may increase memory usage to reduce runtime or over-partition code to lower local complexity, thereby increasing system-level coupling. Furthermore, developers and organizations often hold subjective preferences regarding what constitutes “good code”. The absence of evaluation frameworks that reconcile structured metrics with contextual preferences makes automated systems prone to local optima or the creation of unmaintainable systems.

Simply adding more metrics or running more tests cannot solve this problem. Many quality attributes are emergent and cannot be fully captured by static analyzers, and trade-offs between attributes are common and often unavoidable. Thus, evaluations must support decision-making under incomplete observations and evolving, sometimes conflicting, preferences, rather than relying on a fixed set of universal rules.

Thus, the core difficulty of this problem is not engineering but conceptual: how to formalize subjective, context-dependent notions of quality into representations that autonomous agents can act on. Any viable solution must combine structured metrics with specific preferences, adapt as projects evolve, and detect regressions across quality dimensions. One possible direction is an evaluation framework that integrates static analysis, sandbox testing, and organizational preferences using utility functions to support quantitative quality decisions.

Multi-timescale Integration of Heterogeneous Signals

Static tools provide a snapshot of code quality and capture only a limited aspect of continuous software evolution. In agile development, quality preferences are often hidden within temporal archives such as logs, test results, and commit histories. Such data explain seemingly irrational designs, such as redundant code maintained for legacy compatibility or historical bug fixes. Moreover, different signals emerge at varying frequencies, from static metrics computed on each commit to real-time production loads, to customer feedback that arrives on much longer timescales. Autonomous refactoring must synchronize these multi-speed information sources to maintain system stability after refactoring. Yet using heterogeneous data in refactoring requires more than collecting it.

The key challenge is reasoning about the intent and constraints behind the data at multiple abstraction levels. This requires both spatial awareness of system structure and dependencies and temporal awareness of how the project evolved and why earlier decisions were made. LLMs offer promising capabilities for processing unstructured data, but extracting actionable constraints from diverse sources remains an unsolved problem. In addition, mechanisms are needed to detect pseudo-optimizations, which appear beneficial locally but degrade quality elsewhere, so that the refactoring process remains robust across successive iterations. More specifically, the open questions include: How should heterogeneous temporal data be represented and prioritized for refactoring decisions? What architectures can support real-time integration of multi-speed data streams? How can implicit design rationale be reliably extracted from historical artifacts such as commit histories, bug reports, code reviews, and operational logs?

Architecture and Design Pattern Challenges

Building a practical autonomous refactoring system raises challenges in both model selection and architecture design. Selecting a model based solely on aggregate benchmark performance is insufficient, as different models exhibit distinct capability profiles that must be matched to task requirements. For example, some models handle long context better, while others perform more reliably on structured reasoning tasks. However, the field currently lacks a taxonomy that categorizes models according to these specialized capabilities, making principled model selection difficult.

Software refactoring is not a single-step generation task. It involves system-level reasoning, constraint checking, and coordination across components, which may exceed the capability of a single agent. Multi-agent architectures, in which different agents handle different subtasks, offer a promising direction, but introduce new challenges in communication, coordination, and conflict resolution.

To address these challenges, the field would benefit from an evaluation framework grounded in model performance on refactoring tasks, rather than relying on existing rankings based primarily on general coding ability for model selection. If multi-agent approaches are to scale, they must include interpretable coordination and conflict-resolution mechanisms that reconcile competing edits across dependencies, semantics, and quality objectives. These considerations lead to several open questions: What capabilities should be used to classify models so that appropriate models can be selected for different refactoring sub-tasks? What coordination mechanisms can resolve conflicts when multiple agents propose competing changes? How should the system architecture itself adapt as model capabilities evolve rapidly?

The Trust Problem

Automation does not eliminate the need for human involvement; rather, the nature of that involvement must evolve. A reliable system must define clear boundaries of autonomy and determine when human intervention is required, based on task risk and output uncertainty. Granting full autonomy in high-risk scenarios can lead to serious failures, while escalating too many low-risk cases to humans undermines efficiency. The deeper question is not how to route decisions to humans, but what it takes to build sufficient trust so that the scope of autonomous action can grow over time.

Building such trust requires mechanisms through which the refactoring system’s behavior can be incrementally evaluated and verified. When handoff to human developers does occur, the interaction should itself be informative: agents should provide clear rationales, expected benefits, and potential side effects, enabling developers to shift from line-by-line code inspection to validating intent and decision logic. These handoff interactions should also be recorded as temporal feedback, letting the system learn implicit constraints and refine its preference model from human responses. Thus, the open questions are: How can the trustworthiness of an autonomous refactoring system be measured in practice? What evidence and explanation mechanisms are needed for developers to trust autonomous refactoring decisions?

Conclusion

This paper argues for a paradigm shift in how software quality should be managed in the age of LLM-driven development. Rather than treating refactoring as an occasional, manually initiated intervention, we propose that continuous autonomous refactoring should be integrated into software maintenance as a persistent process, in which LLM-based agents monitor, evaluate, and improve codebases against an explicit and evolving specification of what constitutes “good”. Under this view, quality is no longer a constraint on code generation but a primary, ongoing objective.

The roadmap outlined in this paper identifies the research challenges that need to be addressed to realize this vision. A key insight is that the strengths of LLMs in code generation can be combined with the verification capabilities of established engineering tools. This combination enables improving local code quality while preserving global architectural consistency. In addition, incorporating temporal data and utility-based evaluation helps ensure that automated refactoring remains aware of project history and aligned with specific priorities of the team. The earlier traditions of autonomic computing and self-adaptive systems laid the conceptual groundwork; the capabilities of modern LLMs now make a renewed and more ambitious pursuit of this vision both timely and feasible.

We call on the research community to take up these questions. Tools and model capabilities are advancing rapidly, but the conceptual and methodological foundations for system-level autonomous refactoring still lag behind. Progress on these dimensions would not only advance automated software maintenance but also reshape how human developers collaborate with AI systems. It points toward adaptive software that evolves continuously and manages its own quality over time. We plan to pursue this agenda in our future work, and we invite the broader community to help define the methods, tools, and evaluation frameworks needed to bring continuous autonomous refactoring from vision to practice.