← Latest papers
💬 NLP

KAPSO: A Knowledge-grounded framework for Autonomous Program Synthesis and Optimization

KAPSO is a modular, knowledge-grounded framework that enhances autonomous program synthesis and optimization by integrating a git-native experimentation engine, a structured knowledge system, and a cognitive memory layer to iteratively improve code artifacts and overcome long-horizon failures in coding agents.

Original authors: Alireza Nadafian, Alireza Mohammadshahi, Majid Yazdani

Published 2026-02-03
📖 5 min read🧠 Deep dive

Original authors: Alireza Nadafian, Alireza Mohammadshahi, Majid Yazdani

Original paper licensed under CC BY 4.0 (http://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 build a complex machine, like a high-performance race car, but you don't have a single blueprint. Instead, you have a goal: "Make the fastest car possible."

In the past, if you asked a smart computer assistant (an AI coding agent) to build this, it would try to write the whole car at once. If the engine didn't start, the AI would get confused, forget what it tried before, or keep making the same mistake over and over. It was like a builder who keeps forgetting which tools they used yesterday.

KAPSO is a new framework that changes how we build software. Instead of asking the AI to "write the code and be done," KAPSO treats coding as a long-term scientific experiment. It doesn't just write; it learns how to write better by running thousands of tiny tests, keeping perfect records, and remembering what worked.

Here is how KAPSO works, broken down into three simple parts:

1. The "Git-Native" Lab Notebook (The Experimentation Engine)

Imagine a scientist who never throws away a single experiment. Every time they try a new idea, they don't just scribble on a napkin; they open a brand new, isolated notebook (a "branch").

  • What KAPSO does: Every time the AI tries to fix or improve the code, KAPSO creates a separate, safe "branch" in a version control system (like Git).
  • Why it matters: If the experiment fails, the AI doesn't lose its mind. It can look back at that specific notebook, see exactly what went wrong, and try a different path without breaking the original work. It keeps a perfect history of every attempt, like a detective keeping a case file for every clue.

2. The "Super-Librarian" (The Knowledge System)

Imagine you are building that race car, but you have access to a library containing every car manual, every engineering textbook, and every blog post ever written about engines.

  • What KAPSO does: It doesn't just guess. It has a "Knowledge System" that reads through thousands of real-world code repositories, scientific papers, and internal guides. It organizes this massive amount of information into a structured map (a "Knowledge Graph").
  • Why it matters: When the AI gets stuck, it doesn't just hallucinate a solution. It asks the Librarian: "Has anyone built a suspension system like this before? What worked?" It pulls up specific, proven ideas and pastes them into the current project, ensuring it uses expert-grade engineering rather than random guesses.

3. The "Memory Coach" (The Cognitive Memory)

Imagine a coach who watches your practice runs. If you trip over the same rock three times, the coach doesn't just say "try again." They say, "Hey, remember last Tuesday? You tripped on that rock because you were looking at your watch. Next time, look at the track."

  • What KAPSO does: It has a "Cognitive Memory" that stores "lessons learned" from every failed or successful experiment. It remembers specific error patterns (like "this code crashes when the data is empty") and successful tricks.
  • Why it matters: This stops the AI from making the same mistake twice. If it fails, it instantly recalls the "lesson" from a previous attempt and adjusts its strategy. It turns a long, frustrating loop of errors into a fast, smart learning curve.

How It All Works Together

KAPSO runs in a loop called "Evolve":

  1. Ideate: The AI looks at the goal and asks the Librarian for ideas.
  2. Build: It writes code in a safe, isolated "branch."
  3. Test: It runs the code against a strict "Evaluator" (a judge that checks if the car is fast enough).
  4. Learn: If it fails, the Coach steps in, reviews the logs, and tells the AI what to fix next.
  5. Repeat: It keeps doing this until the code is perfect.

The Results: Did It Work?

The paper tested KAPSO (which they call "Leeroo" in the results) against other top AI coding agents in two very tough arenas:

  • MLE-Bench (Machine Learning Competitions): Think of this as a contest to build the best AI model for predicting things. KAPSO beat all other open-source agents, especially in the hardest challenges. While others struggled with complex problems, KAPSO kept improving and reached much higher scores.
  • ALE-Bench (Heuristic Optimization): Think of this as a math puzzle contest where you have to find the best possible solution under a strict time limit. KAPSO achieved a higher score than the previous best agent (ALE-Agent) while actually spending less money on computing power.

The Bottom Line

KAPSO isn't just a tool that writes code; it's a system that manages the entire lifecycle of building software. By combining a perfect record-keeping system, a massive library of human knowledge, and a memory that learns from mistakes, it turns the chaotic process of coding into a reliable, step-by-step optimization loop. It proves that for hard problems, the secret isn't just writing code faster—it's knowing how to learn from every single attempt.

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 →