Self-Programming AI: Code-Learning Agents for Autonomous Refactoring and Architectural Evolution
Abstract
We present a novel implementation of a Self-Refining Programming Agent (SPA) designed to autonomously generate, test, and iteratively optimize Python code directly from natural-language specifications. The SPA leverages OpenAI's GPT-3.5-Turbo model through structured function-calling to produce an initial implementation and corresponding test suite. It then enters a self-improvement loop that integrates static and dynamic analysis tools, including pytest for correctness, coverage.py for test coverage, Radon for cyclomatic complexity and maintainability metrics, and Pylint for code-quality enforcement. Based on the collected metrics, SPA autonomously suggests AST-level refinements using LibCST transformations. To address common API limitations such as rate-limiting, we implemented an exponential backoff retry strategy, enhancing the robustness of agent interactions. Experimental evaluation demonstrates that the SPA consistently and autonomously refines generated code to meet rigorous software engineering standards, including high test coverage (> 80%), low complexity, zero lint errors, and full compliance with specified functional requirements. This implementation represents a significant step toward fully autonomous, AI-driven software development workflows.
Related articles
Related articles are currently not available for this article.