NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

CodeDistiller: Automatically Generating Code Libraries for Scientific Coding Agents

Peter A. Jansen, Samiah Hassan, Pragnya Narasimha

TL;DR

CodeDistiller is a new system that automatically transforms messy, complex GitHub repositories into clean, "vetted" code libraries for AI scientific agents. By autonomously identifying a repository's purpose, selecting relevant files, and iteratively debugging generated examples, it allows AI agents to perform complex experiments in specialized fields like materials science with significantly higher accuracy than relying on their internal training data alone.

What Problem Does This Paper Address?

Automated Scientific Discovery (ASD) aims to create AI agents that can hypothesize, design experiments, and execute code to reach new conclusions. However, these agents face a "knowledge gap." They typically rely on parametric knowledge—the information they "remember" from their initial training. When a task requires a specific, niche scientific library (like a molecular dynamics simulator), the agent often struggles to write working code from scratch or hallucinates API calls.

Currently, researchers solve this by either manually writing code templates for the AI to follow or limiting the AI to very simple tasks. Neither approach scales. The challenge is: how do we give an AI agent the ability to "learn" how to use any scientific software library on the fly without human intervention?

Methods

The authors introduce a three-stage pipeline called CodeDistiller:

  1. Purpose Identification: The system reads a repository's README.md to summarize its core function and identify critical files for setup.
  2. Relevant File Classification: Using an "LLM-as-a-judge" approach, the system scans every file in the repository. It categorizes them (e.g., source code, documentation, entry points) and assigns a relevance score from 1 to 5. This prevents the code generator from being overwhelmed by hundreds of irrelevant files.
  3. Code Generation & Iterative Debugging: The system provides the top-ranked files to a high-end LLM to generate a self-contained Python example, a requirements file, and a setup script. Crucially, it then runs this code in a sandboxed Ubuntu container. If the code fails, the system captures the error logs and feeds them back into the LLM for up to eight rounds of iterative debugging.

This process results in a "vetted" library—a collection of code that is guaranteed to run and demonstrates the repository's core scientific functionality.

Datasets

The researchers focused their evaluation on the Materials Science domain.

  • Source: They used the GitHub API to identify 3,802 active repositories that import popular materials science libraries (like pymatgen or LAMMPS).
  • Evaluation Set: They randomly subsampled 250 repositories for testing.
  • Downstream Task: They created a set of 60 discovery problems (e.g., predicting toxicity or modeling crystal volume changes) to test if the distilled libraries actually helped an AI agent perform better science.

Key Insights and Ideas

  • The "Overcounting" Problem: One of the most striking findings was the gap between AI and human judgment. While an LLM-as-a-judge might claim a generated code example is "successful" 70% of the time, human experts found the actual "correct functionality" rate was often lower (e.g., 61% for GPT-5). This highlights the danger of relying solely on automated metrics for scientific code.
  • Code-RAG is the Future: The paper demonstrates that "Code-RAG" (Retrieval-Augmented Generation for code) is far superior to "zero-shot" generation. By giving the agent a working example of how to use a library, the agent doesn't have to guess the syntax; it just has to adapt a proven template.
  • Iterative Debugging is Non-Negotiable: The system averaged about 2 debug iterations per successful case. Without this "try-fail-fix" loop, the success rate for complex scientific software would be near zero.

Key Results

  • High Success Rate: Using Claude 4-5 (Sonnet), CodeDistiller successfully produced functional, scientifically accurate examples for 74.1% of the tested repositories.
  • Cost vs. Performance: There is a massive trade-off. A small, open-weight model (GPT-OSS-120B) was very cheap ($0.09 per success) but only worked for ~26% of repos. Claude 4-5 was much more capable but cost $1.71 per successful distillation.
  • Scientific Impact: In A/B testing, scientific reports generated by agents using CodeDistiller were preferred by judges nearly 2:1 over those using generic examples. The reports were rated as more accurate, more complete, and more scientifically sound.

Limitations and Future Work

  • The Human Bottleneck: Even with CodeDistiller, verifying that the science in the code is correct (not just that the code runs) still requires a domain expert. The authors note that exhaustive human evaluation is currently too slow to keep up with the speed of AI generation.
  • Dependency on Documentation: The system relies heavily on the quality of the original repository's README.md. If a repository is poorly documented, CodeDistiller struggles to identify its "core purpose."
  • Future Directions: The authors suggest expanding the system to automatically identify and download the specific datasets required to run scientific code, which remains a manual step in many cases. They also aim to scale this beyond materials science to other data-heavy fields like genomics or climate modeling.

Summary updated

BibTeX
@inproceedings{jansen2026codedistiller,
  author = {Peter A. Jansen and Samiah Hassan and Pragnya Narasimha},
  title = {{CodeDistiller: Automatically Generating Code Libraries for Scientific Coding Agents}},
  booktitle = {Annual Meeting of the Association for Computational Linguistics},
  year = {2026},
  doi = {10.18653/v1/2026.acl-demo.10},
}
Figure