CODEAGENT: Enhancing Code Generation with Tool-Integrated Agent Systems for Real-World Repo-level Coding Challenges (2024)

Abstract: Large Language Models (LLMs) have shown promise in automated code generation but typically excel only in simpler tasks such as generating standalone code units. However, real-world software development often involves complex code repositories with complex dependencies and extensive documentation. To enable LLMs to handle these realworld repo-level code generation, we present CODEAGENT, a novel LLM-based agent framework that employs external tools for effective repo-level code generation. CODEAGENT integrates five programming tools, enabling interaction with software artifacts for information retrieval, code implementation, and code testing. We implement four agent strategies to optimize these tools’ usage. To the best of our knowledge, CODEAGENT is the first agent framework specifically for repolevel code generation. In order to measure the effectiveness of our method at the repository level, we design a repo-level benchmark CODEAGENTBENCH. The performance on this benchmark shows a significant improvement brought by our method, with improvements in pass rate ranging from 2.0 to 15.8. Further tests on the HumanEval benchmark confirm CODEAGENT’s adaptability and efficacy across various code generation tasks. Notably, CODEAGENT outperforms commercial products like GitHub Copilot, showcasing superior accuracy and efficiency. These results demonstrate CODEAGENT’s robust capabilities in code generation, highlighting its potential for real-world repo-level coding challenges.

heading: 1 Introduction
text: Code generation automatically generates programs for the natural language (NL) requirement. Recent years have seen a trend in tackling code generation tasks with large language models (LLMs), such
*The two authors share equal contribution. †Corresponding authors.
as Code Llama (Rozière et al., 2023), StarCoder (Li et al., 2023), and DeepSeekCoder (DeepSeek, 2023). Many efforts have been performed (Zhang et al., 2023b; Luo et al., 2023; Zheng et al., 2023) and shown impressive code generation abilities.
Despite achieving satisfactory performances, these studies mainly focus on simple generation scenarios including statement-level and functionlevel code generation. Statement-level code generation (Iyer et al., 2018; Athiwaratkun et al., 2022) aims to output statement-specific source codes. Function-level code generation (Chen et al., 2021; Austin et al., 2021; Hendrycks et al., 2021) predicts independent code that only invokes built-in functions and APIs from third-party libraries. For both scenarios, the length of the generated code is rather short, and they only generate standalone code units. However, more than 70% functions in the open-source projects are non-standalone (Yu et al., 2023). Developers typically write programs based on specific code environments, generally referring to code repositories. These repo-level code snippets usually have intricate contextual dependencies, which is too complex for existing LLMs to handle and generate (Li et al., 2024).
To enhance the efficacy of LLMs in repo-level code generation tasks, we draw inspiration from human programming practices. Developers typically employ a variety of tools to aid in complex programming. For instance, they might utilize search engines to explore key concepts or static analysis tools to identify pre-existing functions or classes. These tools are instrumental in the development of code projects. Embracing this idea, we propose a novel LLM-based agent framework CODEAGENT that leverages external tools to help LLMs in repo-level code generation. With five programming tools, CODEAGENT is capable of interacting with the software artifacts, including retrieving useful information, finding existing code symbols in the repository, and handling essential
13643
code testing. To guide LLMs to efficiently use tools, we draw on four agent strategies covering ReAct, Tool-Planning, OpenAIFunc, and Rule-based form. Based on agent strategies, LLMs can automatically select suitable tools for each repo-level task, finally providing a comprehensive response.
In order to measure the effectiveness of our method at the code repository, we manually construct CODEAGENTBENCH, a benchmark specifically for repo-level code generation with a total of 101 functions and classes sourced from real code projects. It provides rich information about the repository, such as documentation and contextual dependency, to help LLMs better understand it. We further conduct extensive experiments for evaluation. We apply CODEAGENT to nine powerful open-source and closed-source LLMs with parameter sizes ranging from 13B to 175B to show the universality. Compared to directly generating from LLMs, experimental results on CODEAGENTBENCH reveal that CODEAGENT achieves significant improvements ranging from 2.0 to an extraordinary 15.8 across various LLMs. Further evaluations on well-known function-level benchmark HumanEval (Chen et al., 2021) confirm CODEAGENT’s versatility in diverse code generation tasks. Remarkably, when compared to commercial products like GitHub Copilot (Dakhel et al., 2023), CODEAGENT stands out, demonstrating superior accuracy. These findings highlight the robust practical capabilities of CODEAGENT in the code generation community, underscoring its potential to evolve real-world repo-level coding challenges. We summarize our main contributions:
• We make an attempt to investigate repo-level code generation, which has crucial worth for understanding LLMs’ performance in practical code generation scenarios.
• We propose CODEAGENT, an LLM-based agent framework for repo-level code generation. It develops five external programming tools to help LLMs complete the whole generation process and draw on four agent strategies to automatically optimize tools’ usage.
• We construct CODEAGENTBENCH, a repolevel code generation benchmark, which has high-quality code repositories and covers diverse topics.
• Experimental results on nine LLMs show
CODEAGENT’s versatility and effectiveness in diverse code generation tasks, highlighting its potential for resolving real-world repolevel coding challenges.

heading: 2 Background

heading: 2.1 LLMs and Agents for Code Generation
text: LLMs have shown impressive capabilities in code generation since they have billions of parameters trained on a large amount of corpus with different training objectives. Recently, OpenAI 1 proposes GPT-3.5 and GPT-4 series models (e.g., ChatGPT (Chat, 2022)), which have shown strong generation abilities in coding. There are also various opensoured work, such as CodeGen (Nijkamp et al., 2022), StarCoder (Li et al., 2023), Code Llama (Rozière et al., 2023), WizardCoder (Luo et al., 2023) and DeepSeekCoder (DeepSeek, 2023).
Recent research has also increasingly shown that LLMs can be instrumental in developing AI agents (Palo et al., 2023; Wang et al., 2023a; Xi et al., 2023; Shen et al., 2023; Patil et al., 2023; Qin et al., 2023). Examples such as ToolFormer (Schick et al., 2023), Auto-GPT (AutoGPT, 2023), BabyAGI (BabyAGI, 2023), KwaiAgents (Pan et al., 2023) and ToolCoder (Zhang et al., 2023a) demonstrate LLMs’ proficiency in tool utilization for complex tasks. Some studies such as self-edit (Zhang et al., 2023b) and self-debug (Chen et al., 2023) have demonstrated that code models possess the capability for multi-round interaction and repair. Nowadays, some work has also demonstrated the effectiveness of agent systems in complex code programming tasks, such as OpenDevin (OpenDevin, 2024), SWE-Agent (Yang et al., 2024). In this paper, we select GPT-4 (GPT-4, 2023), GPT-3.5 (GPT-3.5, 2023), and other powerful LLMs to design coding agent systems for real-world repo-level code generation.

heading: 2.2 Code Generation Tasks
text: Existing code generation tasks mainly focus on generating standalone code units, including statement-level (Yin et al., 2018) and function-level generation (Hendrycks et al., 2021; Chen et al., 2021). The generated programs are usually short and are independent of other codes. However, in software development, programmers mainly work within a code environment. They extend their functionalities based on the foundational code frame-
1https://openai.com/
work. Inspired by this, some studies (Yu et al., 2023; Liao et al., 2023) introduce intricate programming tasks that are based on particular code environments such as projects and code repositories. Nevertheless, these studies only provide limited constraint information to LLMs, containing the requirements, signature information, and restricted code dependencies, leading to a difference in programming information needs from humans. Some work targets real-world GitHub issues for code model to resolve, such as SWE-bench (Jimenez et al., 2023). To get closer to realistic programming scenarios, we formalize the repo-level code generation task and propose CODEAGENT to help LLMs handle this complex task. We construct a repo-level code generation benchmark CODEAGENTBENCH to evaluate our method and provide an analysis of benchmarks commonly used for these generation tasks in Table 7. Compared with existing code generation tasks, repo-level code generation is more consistent in real-world programming scenarios, fostering the evolvement of the code generation community.

heading: 3 Repo-level Code Generation Task
text: To fill the gap between existing code generation tasks and practical coding scenarios, we formalize the repo-level code generation task. Since a code repository generally contains intricate invocation relationships, only with a deep understanding of the code repository can LLMs generate satisfying programs that not only adhere to requirements but also seamlessly integrate with the current repository. Given a code repository, the repo-level code generation task aims to generate code based on all the software artifacts included in the repository, encompassing the documentation, code dependency, runtime environment, which form the task input. Here we give a detailed description of its composition format. Figure 1 shows an illustration of the repo-level code generation task.
Documentation It describes the generation targets and is the main input component of repo-level code generation. The documentation provides additional supporting information beyond the NL requirements. It contains class-level (class name, signature, and member function) and function-level (functional description, and params description) information of targets. Typically, the correctness of generated programs is verified with the test suite. The generated programs must conform to the inter-
face (e.g., the input parameters). Thus, the documentation also provides the type and interpretation of input parameters and output values. In addition, considering that requirements usually contain domain-specific terminologies, the documentation explains these terms as well, such as mathematical theorems. As shown in Figure 1, documentation of the project contains rich information, where different elements are highlighted with diverse colors.
Contextual Dependency A key distinction of our new task from other independent code generation tasks is its inclusion of contextual dependencies. This aspect is crucial, as classes or functions typically interact with other code segments within the repository, such as import statements or other user-defined classes and functions. These interactions may occur within the same file or across multiple files. For instance, to implement the RandomForest class in Figure 1, it is necessary to utilize the bootstrap_sample function from rf.py and the DecisionTree class from dt.py, demonstrating the intricate code contextual dependencies involved.
Runtime Environment Different from natural language, program language is executable. Whether programs return target results after execution is a crucial manner to verify the correctness of generated programs. Developers typically depend on the execution feedback to correct errors in programs. The runtime environment provides all configurations needed to run the code repository and offers convenient interaction to ensure an all-sided evaluation of LLMs’ performance on repo-level code generation.

heading: 4 CODEAGENT Method
text: We introduce a novel LLM-based agent framework CODEAGENT that leverages external tools to enhance the problem-solving abilities of LLMs in intricate repo-level code generation. CODEAGENT seamlessly pauses generation whenever tools are called and resumes generation by integrating their outputs. These tools can assist LLMs with the entire code generation process, including information retrieval, code implementation, and code testing as shown in Table 1, thus interacting with the software artifacts (Section 4.1). Providing LLMs with access to tools, CODEAGENT explores four agent strategies to optimize these tools’ usage (Section 4.2). Figure 2 illustrates the overview of our CODEAGENT.

heading: 4.1 Designed Programming Tools
text: Given a requirement, developers usually first gather relevant knowledge, then find and modify existing programs to meet the requirement, and finally verify programs with the assistance of tools. To mimic this process, we develop several programming tools that are specifically designed for LLMs. CODEAGENT incorporates these external tools from three perspectives: information retrieval, code implementation, and code testing, which are commonly used by programmers in their daily work.

heading: 4.1.1 Information Retrieval Tools
text: Information retrieval tools are responsible for analyzing repositories and collecting resources, which is pivotal in understanding the problem domain. We develop popular website search and documentation reading as information retrieval tools.
Website Search Programmers often share solutions for various programming problems on websites where search engines consider them as knowledge resources. When encountering similar problems, developers only submit a question query to a search engine. The engine can provide useful programming suggestions. Inspired by this, CODEAGENT uses a popular search engine DuckDuckGo2 to choose the most relevant websites, and then apply LLMs to summarize the website content as the final tool output 3. In the process, we block websites that may lead to data leakage. The usage pattern of this tool is formatted as: WebSearch(input_query), which will return the formatted content searched from websites.
2https://duckduckgo.com/ 3We choose DuckDuckGo because it provides a cheaper and more convenient API than other search engines such as Google and Bing.
Documentation Reading Besides gathering information from websites, we also retrieve relevant knowledge from the documentation of the repository. To achieve this, CODEAGENT leverages BM25 (Robertson et al., 2009) as the documentation reading tool. Given a class name or function name, it can retrieve correlative content from the documentation as its output. If the result is too long, the tool will use the LLM to summarize it and then provide it to LLMs for code generation. This tool is designed in the format: DocSearch(input_name).

heading: 4.1.2 Code Implementation Tools
text: Code implementation tools aim to provide relevant code items (i.e., pre-defined symbol names and code snippets) in the code repository. LLMs modify and integrate these items into the generation process. It not only expedites the development process but also encourages code reuse. We build a code symbol navigation tool to help LLMs implement code snippets.
Code Symbol Navigation We use tree-sitter 4 to design the code symbol navigation tool. This tool explores code items from two types. The first type is oriented to the file or module-oriented parsing, where the tool performs static analysis of a file or module and provides symbol names defined in it, encompassing global variables, function names, and class names. The other type is the class or function symbol navigation. Given a class or function name, the tool finds its definition from the code repository. Combining the two types, this tool can traverse predefined source code within a repository, empowering LLMs to understand intricate dependencies and reuse codes. This tool is designed in the format: SymbolSearch(module_path or input_name). The tool will detect what the input is and return the corresponding results (e.g., all defined symbols in the given file path or the implementation code corresponding to the given symbol name). When no parameters are provided, the default value is the path of the current file.

heading: 4.1.3 Code Testing Tools
text: After acquiring generated codes, we design code testing tools to format and test them, enhancing their correctness and readability.
Format Checker The tool is built to check the format correctness of generated codes. Specifically,
4https://tree-sitter.github.io/tree-sitter/
we develop Black 5 as the format checker. It can check format errors such as indentation misalignment and missing keywords. Subsequently, it tries to rectify these errors and reorganizes code statements, enhancing the correctness and readability of generated codes. The usage pattern of this tool is: FormatCheck(), which will automatically format the most recently generated code and return the formatted version.
Code Interpreter The tool focuses on examining the syntax and function of programs. It furnishes a runtime environment so that LLMs can debug generated codes with execution feedback. The tool requires LLMs to provide a program to be executed, and then runs the code in the repository environment. Meanwhile, LLMs generate some test cases to verify whether the output of the generated code meets the expected results. When occurring errors, this tool will offer error information to facilitate LLMs to fix bugs until programs are error-free, which has been proven to be effective by many existing works (Chen et al., 2022; Zhang et al., 2023b) to correct output programs. The runtime environment is prepared for each task, as described in Section B.1.1. This tool is designed in the format: PythonREPL(input_code), and the tool will return the executed result of the input code.

heading: 4.2 Agent Strategy
text: To guide LLMs to leverage these powerful tools properly, we develop four agent strategies for repo-level code generation, including ReAct, ToolPlanning, OpenAIFunc, and Rule-based Tool Usage. The interaction between LLMs and external tools is based on LangChain 6.
ReAct This strategy (Yao et al., 2022) prompts LLMs to generate reasoning traces and task-related actions in an interlaced fashion. Based on actions, ReAct selects the proper external tools and invokes them by providing input. The strategy then treats the output of tools as additional knowledge and decides whether to generate a final code or invoke other tools for further processing.
Tool-Planning We propose a variant, i.e., ToolPlanning, of Planning strategy (Wang et al., 2023b) that makes a plan before solving problems and has shown effectiveness in many studies (Zhang et al., 2022; Jiang et al., 2023). Different from Planning,
5https://github.com/psf/black 6https://python.langchain.com
our strategy can invoke proper tools based on the plan. Specifically, Tool-Planning first makes a plan to divide an entire task into several subtasks and then performs subtasks according to the plan. For complex subtasks, it will automatically choose an appropriate tool to assist LLMs in code generation.
OpenAIFunc Recently, some models (e.g., GPT3.5 (GPT-3.5, 2023) and GPT-4 (GPT-4, 2023)) have the function-calling ability provided by OpenAI (OpenAIFunc, 2023). The interaction mode is similar to that of "ReAct", with some differences in the content generated by LLMs and the format of calling external tools.
Rule-based Tool Usage When faced with a complex problem, programmers often first learn related knowledge, then write programs, and check the function of programs. Inspired by the workflow, we propose a rule-based strategy.
This strategy defines the order of tool usage and interlinks these tools by prompts. I) LLMs leverage website search to gather useful online information; II) LLMs then use documentation reading tool to search relevant classes and functions; III) Code symbol navigation is required to select and view the source codes of related classes and functions. Based on the above information, LLMs generate programs; IV) Subsequently, LLMs invoke the format checker to check the syntax and format of generated programs; V) Finally, LLMs use the code interpreter to evaluate the functional correctness of programs. Based on the feedback information, LLMs fix errors within programs. For each part, LLMs will autonomously cycle through the use of tools until it decides to move on to the next part or the cycle reaches its limit number (e.g., 3).

heading: 5 Experiment
text: We perform extensive experiments to answer three research questions: (1) How much can CODEAGENT improve the advanced code generation LLMs on repo-level code generation (Section 5.2); (2) What is the improvement of our CODEAGENT on classical code generation such as HumanEval (Section 5.3); (3) To what extent do our selected tools in the agent system help for repo-level coding (Section 5.4).

heading: 5.1 Experimental Setup
text: Benchmarks To evaluate our method on repolevel code generation, we follow the format de-
scribed in Section 3 and construct a new benchmark CODEAGENTBENCH. To make CODEAGENTBENCH diverse, we select five prevalent topics judged by ten developers and choose repositories with high stars from GitHub. The selected topics contain machine learning, data structure, information extraction, database, and networking. To ensure the quality, we only select repositories that use pytest 7 and unittest8 as the test framework and its documentation is generated by Sphinx9 tool. For writing standards of these test cases, since we opted for projects utilizing the pytest and unittest frameworks, these frameworks ensure consistency in these testing codes. (for example, the pytest framework requires all test functions to have "test_" as a prefix in their function names and provides uniform guidelines for test assertions). We also filter out complex repositories that are hard to deploy and test. Then, we extract all functions and classes in code repositories and arrange two participants to sequentially execute them. Our construction costs approximately 600 person-hours. Each participant possesses 2-5 years of Python programming experience. Finally, we get 101 functions and classes collected from real code projects in Python. The statistics of CODEAGENTBENCH are shown in Table 2.
The final CODEAGENTBENCH contains 101 samples, and for each task, LLMs are provided with documentation containing the requirements needed to be implemented, along with a set of tools we designed, as well as full access permissions to code files in the repository. We use the self-contained test suite in each code repository to evaluate the correctness of generated programs.
In addition, to evaluate the generalization ability of CODEAGENT, we also perform experiments on function-level code generation. In this paper,
7https://docs.pytest.org/ 8https://docs.python.org/3/library/unittest.html 9https://www.sphinx-doc.org/
we use a widely-used function-level benchmark HumanEval (Chen et al., 2021). It contains 164 programming problems with the function signature, docstring, body, and unit tests. In Figure 3, we give an illustrative example of HumanEval.
Base LLMs We apply CODEAGENT to nine most powerful LLMs, including GPT-3-davinci (GPT3, 2022), GPT-3.5-turbo (GPT-3.5, 2023), GPT4-turbo (GPT-4, 2023), Claude-2 (Claude, 2023), Llama2-70B-chat (Llama, 2023), Code Llama-34B (Rozière et al., 2023), WizardCoder-34B (Luo et al., 2023), DeepSeek-33B (DeepSeek, 2023) and Vicuna-13B (Chiang et al., 2023). Additional descriptions are provided as a part of Table 3.
Metrics Following previous works (Zan et al., 2022; Zheng et al., 2023), we use the pass rate as the metric, where we treat the generated program correctly only if its output is consistent with all ground truths of the test suite. Specifically, we are mainly concerned with Pass@1 (Chen et al., 2021), which is a representative of the Pass@k family, because in real-world scenarios, we usually only consider the single generated code.

heading: 5.2 Repo-level Coding Performance
text: In our experiments, we utilized our specially designed repo-level benchmark, CODEAGENTBENCH, to assess the efficacy of CODEAGENT in enhancing the performance of nine prominent code LLMs. The results are presented in Table 3.
Our proposed CODEAGENTBENCH proves to be substantially more challenging than existing benchmarks, as evidenced by the relatively lower pass rates. On all base LLMs with various sizes, CODEAGENT consistently delivers significant performance improvements. Specifically, for GPT-4 model (GPT-4, 2023), we observe a maximum increase of 15.8, equating to a 72.7% relative enhancement over the baseline, i.e., NoAgent. The
improvements of other LLMs range from 2.0 to an impressive 15.8, underscoring the effectiveness of our proposed approach. This demonstrates that the tools integrated within CODEAGENT provide useful information, aiding LLMs in producing accurate code solutions and effectively tackling complex repo-level coding challenges.
Across different LLMs, a notable trend is that more advanced LLMs exhibit greater improvements with the application of CODEAGENT. However, for Vicuna-13B model (Chiang et al., 2023), performance on CODEAGENTBENCH is notably poor, showing no appreciable enhancement with the agent strategy. In contrast, the improvement is quite pronounced for other high-capacity LLMs. Furthermore, we find that different agent strategies yield varying levels of enhancement. Among these strategies, Rule-based and ReAct strategies are more effective, whereas Tool-Plannig strategy appears less suited for the task.

heading: 5.3 Function-level Coding Performance
text: We further apply our CODEAGENT to functionlevel code generation with the well-known HumanEval benchmark (Chen et al., 2021). We adapt our approach to this scenario by omitting the documentation reading tool and code symbol navigation. The adjustment is necessitated as these tools are not applicable to the standalone code generation task. For this task, we strategically selected a range of representative LLMs for evaluation, constrained by our available resources and computational capacity. The pass rate results are detailed in Table 4.
The results once again highlight the efficacy of CODEAGENT in enhancing the performance of code LLMs across all metrics. Notably, the maximum improvements observed for each model span from 6.1 to 9.7 on Pass@1. These findings underscore the versatility and effectiveness of our CODEAGENT in augmenting the capabilities of LLMs across a variety of code generation tasks.

heading: 5.4 Ablation Study
text: To investigate the influence of tools incorporated in CODEAGENT, we conduct an ablation study focusing on tool utilization in repo-level code generation. We choose GPT-3.5-turbo with ReAct as the base model, named GPT-3.5-ReAct. We meticulously track the usage frequency of each tool during code generation processes, with the statistics presented in Table 5 under the column # Usage. Subsequently, we exclude one tool at a time from our approach,
allowing us to isolate and understand the individual contribution of each tool. The performances of these ablation scenarios are shown in Table 5, categorized under the column Ablation Result.
Our findings reveal that the code symbol navigation tool is particularly pivotal in our agent system. On average, CODEAGENT utilizes this tool approximately 2.45 times per code generation, a frequency higher than the counterpart of other tools. Notably, the performance significantly declines when this tool is omitted, underscoring its critical role in enhancing the effectiveness of our approach. Furthermore, the ablation results confirm that each tool in our agent system contributes positively to the overall improvement. This evidence not only validates the effectiveness of our strategy design but also highlights the utility of programming tools in addressing the repo-level coding task.

heading: 6 Discussion

heading: 6.1 Compared with Commercial Products
text: Nowadays, a lot of mature commercial products are available to support complex code generation tasks. It is essential to compare CODEAGENT with these established products. We categorize them into two distinct groups: (1) IDE Products are AI-powered autocomplete-style suggestion tools integrated within IDE software. Notable examples are GitHub Copilot (Copilot, 2023) and Amazon CodeWhisperer (CodeWhisperer, 2023). (2) Agent Products encompass autonomous agents driven by GPT-4 (GPT-4, 2023). They are capable of executing a variety of tasks, including coding, such as well-known AutoGPT (AutoGPT, 2023).
Considering that IDE products are primarily designed as completion systems, we limit human interactions to less than three times per task to ensure a fair comparison. The evaluation is conducted on
the numpyml subset of CODEAGENTBENCH manually by an experienced Python developer. Table 6 shows the number of solved problems on different products and our CODEAGENT.
The results demonstrate that CODEAGENT works better than existing products on complex coding scenarios. In addition, despite both CODEAGENT and AutoGPT being agent-based approaches, CODEAGENT exhibits numerous optimizations tailored for repo-level coding tasks, thereby making it better than AutoGPT in the task. Compared to IDE products that can also analyze complex code dependencies, our method benefits from the flexibility inherent in the agent system, resulting in a substantial lead over IDE products.

heading: 6.2 Qualitative Analysis
text: We explore generated cases to assess CODEAGENT (e.g., GPT-3.5-ReAct) and the baseline model (e.g., GPT-3.5-NoAgent). The comparative analysis is shown in Figure 4 and Figure 5.
CODEAGENT typically begins with examining the code dependencies in the repository, subsequently refining its code generation strategy through a step-by-step process known as “chainof-thought”. As in Figure 4, the input documentation specifies the need for a class with member functions set_params and summary. CODEAGENT, assisting with the symbol navigation tool, finds the base class and identifies the member function _kernel as a key component for implementation. This is reflected in the generated thought process:
"The set_params and summary methods can be inherited from the base class without modifications ... The ‘_kernel’ method needs to be overridden ..."
(Generated by CODEAGENT-GPT-3.5-ReAct)
On the contrary, GPT-3.5-NoAgent lacks access to detailed information on code structures, resulting in incorrect code solutions, as depicted in Figure 5.

heading: 7 Conclusion
text: We formalize the repo-level code generation task to evolve real-world coding challenges. To enhance LLMs to handle repo-level code generation, we propose CODEAGENT, a novel LLM-based agent framework. CODEAGENT develops five programming tools, enabling LLMs to interact with software artifacts, and designs four agent strategies to optimize tools’ usage. To evaluate the effectiveness
of our CODEAGENT, we construct CODEAGENTBENCH, a new benchmark for repo-level code generation that includes rich information about the code repository. Experiments on nine LLMs show that CODEAGENT achieves a significant improvement on diverse programming tasks, highlighting its potential in real-world coding challenges.

heading: 8 Acknowledgments
text: This research is supported by the National Natural Science Foundation of China under Grant No.62192733, 61832009, 62192731, 62192730, 62072007, the Major Program (JD) of Hubei Province (No.2023BAA024).
Limitation
Although our work is a very early exploration of this area, there are several limitations on our work that we aim to address as quickly as possible:
Firstly, we propose a new task format for the repo-level code generation task and release CODEAGENTBENCH. Our preliminary experiments prove that the impact of LLMs’ memorization on pre-training data is slight for fair evaluation. However, it still needs further experiments to eliminate this hidden danger. We will follow the relevant research to further understand its influence on our proposed benchmark.
Secondly, we only incorporate simple tools to CODEAGENT. Some advanced programming tools are not explored. The limitation may restrict the agent’s ability in some challenging scenarios.
Thirdly, in Section 6.1, the comparison with commercial products is not rigorous since experiments are done manually. We will study how to evaluate IDE products more standardly.
Finally, since LLMs are very sensitive to input prompts, it is very important to optimize prompts in the agent system. We will continue to explore better agent strategies based on the current approach.
Ethics Consideration
CodeAgent and its benchmark are inspired and collected from real-world code repositories. We manually check all samples in our benchmark. We ensure all samples do not contain private information or offensive content. Throughout our experiments, we diligently annotated the sources of all used data, ensuring compliance with the respective license specifications.

heading: A Details of Case Study
text: Here we show the illustration of the case study for CODEAGENT (GPT-3.5-ReAct) and GPT-3.5NoAgent in Figures 4 and 5.
We can find a distinct operational pattern in CODEAGENT in Figure 4. Through meticulous analysis, CODEAGENT leverages code symbol navigation tool to scrutinize information within the ‘utils.kernels’ module, where the target class for implementation resides. Our custom-designed tool proficiently navigates to the module, offering insights into its contents, including package details, defined functions and classes, through a static analysis process. Importantly, CODEAGENT discovers a crucial class named ‘KernelBase’ and obtains detailed information about it with another use of the tool. Within ‘KernelBase’, there is an abstract method named ‘_kernel’ that needs to be implemented. CODEAGENT recognizes this method as essential for the development process, highlighting its importance. Compared with the NoAgent in Figure 5, our approach accurately captures this content hidden in the complex information in the code repository, and precisely implements the final code.
We also notice that during the third tool invocation, CODEAGENT calls the code interpreter tool and execute a piece of code that appears insignificant. We have observed similar situations in other cases as well. We attribute this to LLMs still lacking proficient mastery of some complex programming tools. This insight directs our future research towards enhancing LLMs’ ability to more effectively use complex programming tools.

heading: B Details of CODEAGENTBENCH
text: In this section, we introduce the details of our CODEAGENTBENCH benchmark. We describe its composition format (Section B.1), the construction process (Section 5.1), and provide a detailed comparison with existing benchmarks (Section B.2).
B.1 Benchmark Composition Code repository contains intricate invocation relationships. Only with a deep understanding of code repository can LLMs generate satisfying programs that not only adhere to requirements but also seamlessly integrate with the current repository. Inspired by this, each task of our benchmark provides rich information, encompassing the documentation, code dependency, runtime environment,
self-contained test suite, and canonical solution, which form the input and output.
B.1.1 Benchmark Input Documentation Documentations are the main input component of our benchmark and describe the generation targets. We follow the code documentation format used in a popular documentation creation tool Sphinx 10. Figure 1 illustrates an example of documentation in CODEAGENTBENCH, where different elements are highlighted with diverse colors. When accomplishing a new task, our prepared documentation can provide LLMs with all-sided details that need to be considered to ensure that the generation target has been well-defined and constrained.
Contextual Dependency Contextual dependency is an important role in our benchmark. To accurately identify these dependencies, we developed a static analysis tool using tree-sitter 11. Our designed tool allows us to extract all user-defined elements (such as class names, function names, constants, and global variables) and public library names from each file. These elements are then stored in a knowledge base. For any given function, we use this knowledge base to locate its source file, parse the file to identify all user-defined symbols and public libraries, and finally determine its contextual dependencies by exact matching of symbol names and scopes. On average, each sample in CODEAGENTBENCH involves around 3.1 code dependencies, thereby closely simulating real-world programming conditions. Detailed information is shown in Table 2.
Runtime Environment Developers often use feedback from running programs to find and fix mistakes. In CODEAGENTBENCH, we build a sandbox environment for each task. The sandbox environment provides all configurations needed to run the repository and offers convenient interaction to ensure an all-sided evaluation of LLMs’ performance on repo-level code generation.
B.1.2 Benchmark Ground-truth Output Canonical Solution We use the answers included in the repository as the initial solutions and invite three participants to manually refine them. The first participant checks surface errors of solutions based on the repository information. The second
10https://www.sphinx-doc.org/ 11https://tree-sitter.github.io/tree-sitter/
person runs the solutions to identify and fix execution bugs. The last participant is responsible for executing solutions with the test suite, aiming to ensure its functional correctness. Through the iterative process, we can ensure the robustness and reliability of solutions as much as possible.
B.1.3 Benchmark Evaluation
Self-Contained Test Suite To evaluate the correctness of generated programs, CODEAGENTBENCH furnishes a self-contained test suite for each task. We first analyze and extract test cases contained in the repository. We then invite two participants to manually add test cases to enhance
its coverage as much as possible. In CODEAGENTBENCH, each task has at least one unit test case. Whereafter, another participant manually checks the correctness of the test suite. Given a new task, we run the corresponding unit test code to verify the generated programs based on our sandbox environment. We treat the generated program correctly only if its output aligns with all ground truths of the test suite. For fairness, LLMs can not access the test suite during code generation.
B.2 Compared with Existing Benchmarks We perform a detailed analysis of existing code generation benchmarks in Table 7. Compared to the previous benchmarks, our CODEAGENTBENCH has two main advantages. On the one hand, it is closer to real-world code generation scenarios. On the other hand, CODEAGENTBENCH provides pretty complex information that is related to the code repository, including documentation, contextual dependency, runtime environments, and test suites.

heading: Future Work
text: This insight directs our future research towards enhancing LLMs’ ability to more effectively use complex programming tools