Introduction
While Large Language Models (LLMs) have demonstrated remarkable proficiency in generating standalone code snippets, their performance often falters when tasked with developing complex classes within a real-world software repository. Modern software development involves a dense web of cross-file dependencies, where a single class may rely on method signatures, inherited structures, and specific imports defined elsewhere in the codebase. This paper introduces RepoClassBench, a benchmark designed to evaluate class-level code generation, and proposes Retrieve-Repotools-Reflect (RRR), an agentic framework that empowers LLMs with repository-aware tools to navigate these complexities.
The Challenge of Dependency Context
Traditional code generation benchmarks like HumanEval focus on isolated functions. In contrast, repository-level development requires deep "dependency context." Current Retrieval-Augmented Generation (RAG) approaches often rely on finding "similar" code snippets. However, similarity does not always equate to relevance; a model may find a similar-looking class but still lack the specific method signatures needed for a successful compilation. When an LLM encounters a compilation error due to a missing dependency or an incorrect method name, standard one-shot generation models lack the mechanism to explore the repository and find the correct information.
The RRR Framework
To address these limitations, the authors propose the Retrieve-Repotools-Reflect (RRR) framework. RRR transforms code generation from a single-shot task into an iterative, tool-enhanced reasoning process.
The framework operates in a five-stage loop:
- Initial Generation: The LLM generates an initial draft based on a natural language description and basic retrieved snippets.
- Oracle Call: The generated code is evaluated by a compiler or test runner. Error logs are captured and fed back to the model.
- Tool Invocation: The LLM acts as an agent, utilizing a suite of "Repotools"—static analysis functions such as
get_class_info,get_signature, andget_method_body—to query the repository for missing information. - Reflection: The model analyzes the error feedback and tool outputs to identify the root cause of the failure.
- Improve Generation: A refined version of the code is produced. This cycle repeats until the code passes or a maximum iteration limit is reached.
RepoClassBench: A New Benchmark
The researchers developed RepoClassBench to rigorously test these capabilities across three major programming languages:
- Java: 130 classes from 10 repositories.
- Python: 97 classes from 10 repositories.
- C#: 60 classes from a large repository.
To ensure the models are genuinely reasoning rather than relying on memorized training data, the benchmark employs symbol renaming. By paraphrasing internal variable and method names, the researchers force the model to rely on its ability to explore the repository structure rather than its internal knowledge of popular GitHub projects.
Experimental Results
The RRR framework consistently outperforms existing baselines, including NaiveRAG and RepoCoder, across all tested languages.
Key findings include:
- Superior Accuracy: In Java, RRR achieved a 77.56% Pass@1 score, significantly higher than RepoCoder (54.74%) and basic prompting (2.18%).
- High Compilation Rates: The iterative loop proved highly effective at resolving syntax and dependency issues, with Java code reaching a 92.56% compilation rate.
- Robustness to Context Loss: Unlike RAG-based models that struggle when "similar" code is removed from the index, RRR remains robust by actively searching for specific dependencies via static analysis.
Conclusion
The success of RRR highlights that for complex, repository-level tasks, LLMs require more than just "similar" context; they need the ability to interact with the codebase through structured tools. While challenges remain—such as context window limitations and occasional reasoning errors—this research provides a clear path forward for building AI agents capable of navigating the intricacies of real-world software development.
Summary updated