← Latest papers
💻 computer science

SAGE: A Self-Adaptive Agentic Framework for Execution-Guided Code Generation and Self-Repair

This paper introduces SAGE, a self-adaptive multi-agent framework that significantly improves the reliability of generating runnable multi-file projects by employing a closed-loop MAPE-K control cycle to iteratively execute code, analyze runtime errors, and perform self-repair, thereby achieving a statistically significant increase in success rates compared to single-pass generation.

Original authors: Harshil Lodhiya

Published 2026-08-11
📖 5 min read🧠 Deep dive

Original authors: Harshil Lodhiya

Original paper licensed under CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). This is an AI-generated explanation of the paper below. It is not written or endorsed by the authors. For technical accuracy, refer to the original paper. Read full disclaimer

Imagine you are trying to teach a brilliant but slightly absent-minded robot how to build a complex LEGO castle. You give the robot a simple instruction: "Build a castle with a moat and a drawbridge." The robot, trained on millions of pictures of castles, might instantly snap together a structure that looks perfect. But if you try to pull the drawbridge, it might snap off because the robot used a piece that was discontinued years ago, or it forgot to glue the base to the ground. In the world of computer science, this is the challenge of "Large Language Models" (LLMs). These are AI systems that are incredibly good at writing small pieces of code, like a single function, but they often struggle when asked to build a whole, working software project from scratch. They might forget to install necessary tools, use outdated instructions, or create a program that looks correct on paper but crashes the moment you try to run it.

For a long time, the solution was to just ask the robot to try again, hoping it gets it right the first time. But this paper introduces a smarter approach: instead of just guessing, let the robot actually build the castle, try to open the drawbridge, and if it breaks, fix it immediately. This is the core idea of "execution-guided self-repair." It's like having a quality control inspector who doesn't just look at the blueprints but actually tries to use the product. If the product fails, the inspector tells the builder exactly what went wrong, and the builder fixes it. This cycle of building, testing, and fixing continues until the project works perfectly. The big question researchers have been asking is: Does this "try, fail, fix" loop actually make the AI much better at building complex software, or does it just make the robot spin its wheels and get confused?

The researcher behind this study, Harshil Lodhiya, created a new system called SAGE (Self-Adaptive Agentic Framework for Execution-Guided Code Generation and Self-Repair) to answer that question. Think of SAGE as a tiny, automated construction crew with four distinct roles working in a loop. First, a Planner breaks down your big goal into a detailed checklist. Second, a Coder builds the files based on that list. Third, a Validator acts as the strict inspector: it sets up a clean, isolated workshop, installs the necessary tools, and tries to run the program. If the program crashes or fails to do what it was supposed to do, the Validator doesn't just give up; it sends the error message to a fourth member, the Feedback Agent. This agent acts like a detective, reading the error report and telling the Coder exactly which file to change and how to fix it. The Coder then makes the repair, and the whole team tries again. This cycle repeats until the project runs successfully or they run out of attempts.

The team tested SAGE on a special set of 15 tricky tasks they designed specifically to trip up AI, such as using old library commands that no longer exist or missing a required output file. They compared SAGE's "fix-it" loop against a standard AI that just tries to build the project once and hopes for the best. The results were clear: the self-repair loop made a huge difference. When using a strong AI model (gpt-4.1-mini), the standard "one-shot" approach succeeded in about 69.3% of the cases. But when they added the SAGE repair loop, the success rate jumped to 92.0%. That is a 22.7 percentage point improvement, which the researcher says is a significant and meaningful gain. Essentially, the loop rescued tasks that the AI would have otherwise failed completely, such as fixing code that tried to use a "month" frequency alias that had been removed from a popular data library.

However, the paper also tested a more aggressive version of the idea. They wondered: what if the AI didn't just fix crashes, but also checked if the program was perfectly complete, even if it didn't crash? For example, if a program was supposed to generate a report file but finished without making an error, just without the file, would the AI catch that? They built a "correctness-aware" system to do this. Surprisingly, this extra strictness didn't help much. The success rate only went up by a tiny 2.7 points (to 94.7%), and the researcher found this difference wasn't statistically significant. In fact, the extra checking sometimes caused the AI to "over-fix" things, breaking programs that were already working fine. The lesson here is that while telling the AI exactly what success looks like is helpful, constantly forcing it to re-check and re-fix things can actually make it worse.

In short, the paper shows that giving AI a "try, fail, fix" loop is a powerful way to build working software, turning a success rate of about 69.3% into 92.0%. It proves that letting the AI see its own mistakes in a real, isolated environment is the key to unlocking its potential for complex projects. But it also warns us that being too perfectionist can backfire; sometimes, it's better to let the AI fix the big errors and leave the rest alone. The researcher has made their code and their test suite open for anyone to use, hoping to help others build software that can heal itself.

Drowning in papers in your field?

Get daily digests of the most novel papers matching your research keywords — with technical summaries, in your language.

Try Digest →