CodeAgent: Enhancing Code Generation with Tool-Integrated Agent Systems for Real-World Repo-level Coding Challenges

Kechi Zhang,Jia Li,Ge Li,Xianjie Shi,Zhi Jin
2024-08-09
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. Real-world software development, however, often involves complex code repositories (named repo) with complex dependencies and extensive documentation. To fill this gap, our research pivots towards evaluating LLMs in a more realistic setting -- real-world repo-level code generation. We introduce CodeAgentBench, a manually curated benchmark for repo-level code generation. This benchmark comprises five high-quality Python projects, encompassing a total of 101 samples. We assess nine leading LLMs on repo-level tasks and observe a decline in their performance. To tackle this, 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 symbol navigation, and code testing. We implement four agent strategies to optimize these tools' usage. Our experiments on CodeAgentBench show that CodeAgent enhances LLM performance significantly, with improvements ranging from 18.1\% to 250\%. 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.
Software Engineering
What problem does this paper attempt to address?
The paper aims to address the challenges faced by existing large language models (LLMs) when generating code snippets within complex codebases. Although current LLMs excel at generating simple code units (such as individual statements or functions), their performance is suboptimal when handling real-world software development tasks with complex dependencies and extensive documentation. To tackle this issue, the research team proposed CODEAGENT, an agent framework based on LLMs that enhances the capability to handle code generation tasks at the real-world codebase level by integrating external tools. Specifically, the main contributions of the paper include: 1. Proposing a new framework named CODEAGENT, which combines 5 programming tools to assist LLMs in the entire process from information retrieval to code implementation and code testing, and employs 4 agent strategies to optimize the use of these tools. 2. Constructing a benchmark test set specifically for evaluating codebase-level code generation capabilities—CODEAGENT BENCH, which includes 101 functions and classes from real projects. 3. Experimental results show that CODEAGENT significantly improves code generation performance across 9 different LLMs, particularly standing out in comparison with the commercial product GitHub Copilot, demonstrating higher accuracy and efficiency. 4. These findings highlight the strong practicality of CODEAGENT in the code generation community and its potential to address real-world codebase-level coding challenges in the future.