Self-Programming AI: Code-Learning Agents for Autonomous Refactoring and Architectural Evolution — part 6/7
Cleaned-text code points [66379, 79343). Bibliography omitted here; source.md includes it.
(b) Natural-language rationale: generate a brief English description for each edit (“Extract method to remove duplication”); (c) Changelog/logging: augment commit messages or documentation with these explanations. These steps would make the agent’s actions transparent to developers, addressing a known need in automated refactoring to justify modificationsmdpi.com. Language-Agnosticism: Extending beyond Python is essential for practical impact. We plan to generalize the framework to other languages (C++, Rust, TypeScript, etc.) by leveraging polyglot models and tools. For instance, large multilingual code LLMs already exist: CodeGeeX is a 13B-parameter model trained on 23 languages and shown to generate code in Python, C++, JavaScript, Go, and morear5iv.org. As a proof of concept, we could switch to a polyglot model (or ensemble of models) so that the agent can handle files in multiple languages. In parallel, we would incorporate language-specific parsing/AST libraries to enable the same AST-based editing pipeline in each language. There are also emerging frameworks for cross-language refactoring; for example, Uber’s PolyglotPiranha provides a DSL that applies code transformations across Java, Kotlin, and other languages in one passdanieltrt.github.io. Inspired by that, our agent could use language-agnostic intermediate representations or a set of pattern rules that map conceptually between languages. In practice this might involve training on diverse multilingual repositories, or pre-translating tasks via code conversion, so that the agent learns idiomatic patterns in each language. Challenges here include handling language-specific features (manual m emory management in C++, asynchronous patterns in TypeScript, etc.), but recent trends suggest this is feasible: developers are already using polyglot microservices and LLMs like CodeGeeX that smoothly switch languagesar5iv.org. By building on these polyglot resources, our future agent could refactor and evolve entire multi- language systems, making software updates in one place and propagating analogous changes elsewhere. • Polyglot Support: Practical steps include (a) Multilingual models: adopt or fine-tune LLMs on multi- language code (e.g. CodeGeeX or CodeT5) so the agent can write and understand C++, Rust, TS, etc.ar5iv.org; (b) Polyglot transformations: define refactoring rules that apply across languages, possibly via a unified DSL (following the example of PolyglotPiranhadanieltrt.github.io); (c) Language plugins: integrate parsers/linters for each target language to validate and type-check chang es. These enhancements would enable the agent to operate on diverse codebases without being tied to one language. Long-Horizon Self-Evolution: In the long run, we envision the agent becoming a lifelong learner of the software it maintains. Rather than treating each task as isolated, the agent would accumulate knowledge over months or years. This means tracking the project’s architecture and gradually evolving it: for example, recognizing recurring patterns and refactoring them proactively, handling API deprecations as libraries update, or assimilating domain-specific heuristics. Achieving this will require memory and continual learning mechanisms. Recent surveys of LLM agents highlight that “lifelong learning” (continuous adaptation to a changing environment) is crucial for robust AI systemsarxiv.org. Concretely, the agent could keep a memory module of past edits and design rationales, and use techniques like replay buffers or meta-learning to avoid forgetting old knowledge. Reinforcement learning or self- improvement loops are another avenue: for instance, the agent might optimize for long-term code quality metrics or maintainability, using feedback from builds or user acceptance as rewards. Integrating external knowledge (e.g. dependency graphs, documentation) would also help; as Zheng et al. note, coupling perception, memory, and action modules enables agents to plan across long horizonsarxiv.orgarxiv.org. We can also explore curriculum learning schemes where the agent’s tasks grow in complexity over time, mirroring the project’s evolution. In practice, preliminary steps might include periodically retraining the agent on the project’s updated code or fine-tuning it on issue/commit history so it “remembers” past solutions. Over years, this could allow the agent to adapt to design drift: when a library is deprecated, the agent could recall how similar migrations were done before; when a new architectural pattern emerges, it could gradually refactor toward that pattern. This long-horizon self-evolution aligns with trends in autonomous AI and continual learningarxiv.orgarxiv.org. Though ambitious, it points toward agents that not only code, test, and refactor in the short term, but that also grow and adapt alongside the software, ensuring the system remains coherent and up-to-date over its entire lifecycle. • Lifelong Learning Mechanisms: To realize this vision, future work could incorporate components such as (a) Memory modules: databases of past decisions, code patterns, and context to inform future planning; (b) Continual adaptation: techniques (e.g. replay or Elastic Weight Consolidation) to update the model without forgetting earlier knowledgearxiv.org; (c) Long-horizon planning: use reinforcement learning or curriculum strategies so the agent optimizes for outcomes measured across weeks or monthsarxiv.org; (d) External knowledge integration: connect to APIs, documentation, or knowledge graphs about the code ecosystem to handle deprecations and new features (as recommended for long -term LLM agentsarxiv.org). By building these capabilities, the agent would evolve in tandem with the project, continuously refining its own architecture and strategies rather than remaining static. These extensions – better multi-agent orchestration, full Git-based workflow suppor t, transparent refactoring explanations, polyglot capabilities, and truly continual learning – represent a roadma p towards an increasingly autonomous, scalable coding assistant. They draw on current trends in AI and software engineering: the rise of multi-agent LLM systemsopenreview.netarxiv.org, the automation of DevOps pipelinesmdpi.com, and the pursuit of lifelong learning in AIarxiv.orgarxiv.org. Balancing feasibility and vision, our near-term efforts will focus on prototyping these features incrementally (e.g. agentic branching and simple explanations), while the more speculative goals (cross-lingual refactoring at scale, year-long adaptation) will guide longer-term research. Together, these directions aim to push the boundary of self-improving software agents, moving towards the ultimate goal of AI systems that can manage the full software lifecycle with minimal human intervention. 7. Conclusion This work presents a novel framework for self-programming AI agents capable of autonomously generating, testing, and iteratively refining source code with minimal human intervention. By tightly in tegrating a large language model (GPT-3.5-turbo) with static and dynamic analysis tools, our system demonstrates an end-to-end loop for autonomous software improvement—spanning task specification, initial implementation, metric-driven evaluation, AST-level patching, and final convergence based on rigorous quality criteria. Through experiments on diverse programming tasks, we show that the agent consistently converges to solutions that are not only functionally correct but also maintainable, well-structured, and free of linting violations. Importantly, the agent exhibits emergent behaviors commonly seen in experienced developers: modularizing code, simplifying logic, and proactively addressing complexity. These results highlight the potential of combining large language models with iterative, test-based refinement for achieving production-quality code synth esis. At the same time, our analysis reveals important limitations. The agent’s performance depends heavily on the quality of test cases, and it is still susceptible to hallucinated edits or local minima in design. Addressing these challenges will require future work in multi-agent collaboration, memory-augmented reasonin g, and broader language support. We have outlined a roadmap for extending the system toward Git-integrated workflows, explainable refactoring, cross-language compatibility, and long-horizon architectural evolution. In doing so, we position this work as a foundational step toward a new class of intelligent software agents: not static assistants, but adaptive co-developers that learn from feedback, evolve over time, and contribute meaningfully to the full software lifecycle. As research progresses, such systems may ultimately shift the boundaries of what it means to write, maintain, and understand code—transforming not only how software is built, but who builds it. References 1. Chen, M., Tworek, J., Jun, H., Yuan, Q., Pinto, H. P. de O., Kaplan, J., ... & Zaremba, W. (2021). Evaluating large language models trained on code. arXiv. https://arxiv.org/abs/2107.03374 2. Li, Y ., Li, Z., Ren, X., Liu, Q., ... & Zeng, M. (2024). OpenCodeInterpreter: Integrating code generation with execution and refinement. arXiv. https://arxiv.org/html/2402.14658v2 3. Li, Y ., Xu, Y ., Ren, X., Wu, Y ., & Zeng, M. (2022). Self-programming artificial intelligence using code- generating language models. arXiv. https://arxiv.org/abs/2205.00167 4. Nijkamp, E., Batra, A., Sadhu, A., Khaitan, A., Ng, A. Y ., & Savarese, S. (2022). Competition-level code generation with AlphaCode. arXiv. https://arxiv.org/abs/2203.07814 5. OpenAI. (2023). Function calling and other API updates. https://openai.com/index/function-calling-and- other-api-updates/ 6. Pearce, D., & Weimer, W. (2012). Technical paper: Automated program repair with evolutionary computation. In IEEE Transactions on Software Engineering. https://web.eecs.umich.edu/~weimerw/p/weimer-tse2012-genprog.pdf 7. Radon. (n.d.). Python code complexity analyzer. PyPI. https://pypi.org/project/radon/ 8. doedotdev. (2022). Pylint static code analysis: Python script with adjustable score threshold. Medium. https://doedotdev.medium.com/pylint-static-code-analysis-python-script-with-adjustable-threshold- b0d6d2c8647b 9. LibCST. (n.d.). LibCST documentation. https://libcst.readthedocs.io/ 10. MLflow. (n.d.). MLflow tracking documentation. https://mlflow.org/docs/latest/tracking/ 11. Zhang, M., Wang, Z., Zhang, X., Chen, T., & Ren, X. (2025). Lifelong learning of large language model- based agents: A roadmap. arXiv. https://arxiv.org/html/2501.07278v1 12. Chen, M., Tworek, J., Jun, H., Yuan, Q., Ponde, H., Kaplan, J., ... & Zaremba, W. (2021). Evaluating large language models trained on code. arXiv. https://arxiv.org/abs/2107.03374 13. Li, Y ., Nijkamp, E., An, L., Kosiorek, A., Zolna, K., Brock, A., ... & Vinyals, O. (2022). Competition-level code generation with AlphaCode. arXiv. https://arxiv.org/abs/2203.07814 14. DeepMind. (2022, February 2). Competitive programming with AlphaCode. https://deepmind.google/discover/blog/competitive-programming-with-alphacode/ 15. Coldewey, D. (2022, March 23). PolyCoder is an open source AI code-generator that researchers claim trumps Codex. VentureBeat. https://venturebeat.com/ai/researchers-open-source-code-generating-ai-they- claim-can-beat-openais-codex/ 16. Hugging Face. (n.d.). codeparrot/codeparrot. https://huggingface.co/codeparrot/codeparrot 17. BigCode. (n.d.). santacoder. Hugging Face. https://huggingface.co/bigcode/santacoder 18. Wang, Y ., Fung, P., Lin, Z., Xu, B., Liu, S., & Sun, M. (2021). CodeT5: Identifier-aware unified pre-trained encoder-decoder models for code understanding and generation. arXiv. https://arxiv.org/abs/2109.00859 19. Weimer, W., Nguyen, T., Le Goues, C., & Forrest, S. (2012). Automatically finding patches using genetic programming. IEEE Transactions on Software Engineering, 38(1), 364–384. https://web.eecs.umich.edu/~weimerw/p/weimer-tse2012-genprog.pdf 20. Trafton, A. (2016, January 29). Recognizing correct code. MIT News. https://news.mit.edu/2016/faster- automatic-bug-repair-code-errors-0129 21. Jiang, Z., et al. (2023). [PDF] Automated design of algorithms via genetic improvement: contrast and commonalities. https://lingming.cs.illinois.edu/publications/icse2023a.pdf 22. Peng, X., et al. (2023). Fixing 162 out of 337 bugs for $0.42 each using ChatGPT. ACM. https://dl.acm.org/doi/10.1145/3650212.3680323 23. Yao, S., Zhao, J., Y u, D., Pan, X., Yu, Y ., & Huang, D. (2022). ReAct: Synergizing reasoning and acting in language models. arXiv. https://arxiv.org/abs/2210.03629 24. Shinn, N., Liu, B., Liu, M., & Lu, J. (2023). Reflexion: An autonomous agent with dynamic memory and self-reflection. arXiv. https://arxiv.org/abs/2303.11366v1