CORTEXA
← Browse
crossref2026-07-15Cited by 0

Agentic AI for Code Quality: A Four-Agent Machine Learning System for Repository Refactoring, Public RAG, Groq Reasoning, and Reinforcement Learning

Abhishek Prithvi Tejs

Abstract Background: Software repositories continuously accumulate technical debt in the form of code smells, duplicated logic, high complexity, and poor maintainability. Although static analysis tools can identify these issues, they typically stop at diagnosis and do not autonomously perform behavior-preserving repairs or compare multiple repair strategies. Objective: This work presents an Agentic AI framework for autonomous code quality improvement that integrates multiple artificial intelligence approaches to detect, analyze, refactor, and validate software repositories while preserving functional correctness. Methods: The proposed system implements four complementary agents: (i) a deterministic Rule-Based Agent, (ii) a Retrieval-Augmented Generation (RAG) Agent using public software engineering knowledge and Tavily search, (iii) a Groq-powered Large Language Model Agent for semantic reasoning, and (iv) a Q-Learning Agent for adaptive refactoring policy selection. Python repositories are analyzed using Abstract Syntax Tree (AST)-based static analysis to extract maintainability metrics, detect code smells and clone patterns, and compute repository-level quality indicators. Each agent independently performs refactoring on isolated repository copies, followed by automated syntax checking, test validation, and metric-based evaluation. A Supervisor Agent compares all candidate solutions and selects the best validated outcome. Results: The framework was evaluated on four publicly available GitHub repositories: GildedRose, ExpenseReport Refactoring Kata, Theatrical Players Refactoring Kata, and Dependency Breaking Katas. Experimental results demonstrated measurable improvements in repository quality, including quality score gains of up to 64.44% , issue reductions of up to 66.67% , and risk reductions approaching 40% , while preserving software behavior through automated validation. Comparative evaluation further showed that different AI agents exhibit distinct strengths depending on repository characteristics, with Rule-Based, RAG, LLM, and Reinforcement Learning approaches outperforming one another under different software maintenance scenarios. Conclusion: The proposed multi-agent architecture demonstrates that combining static analysis, Retrieval-Augmented Generation, large language models, reinforcement learning, and automated validation enables a practical self-healing software engineering pipeline. The framework advances autonomous software maintenance by moving beyond issue detection toward intelligent diagnosis, safe behavior-preserving refactoring, empirical agent comparison, and production-oriented code quality improvement.

View free PDFSource page