页面简介
Agentic Setup, Build, and Testing of Repositories.
正文摘录
As we enter the era of software engineering agents, the ability to automatically set up, build, and test repositories will greatly enhance AI-based code-generation experiences. To achieve this, we developed Discovery Agent, an AI system that autonomously sets up, builds, and tests GitHub repositories in containerized environments. It uses a react-style loop, tool-based execution, and a structured system prompt to reason through projects without relying on hardcoded heuristics or web searches. Evaluated across three datasets, the agent showed strong performance with low runtimes, even on complex or manually configured builds. This capability paves the way for smarter AI-assisted development and better tooling for code generation, validation, and cloud IDE adoption. Generative AI tools are increasingly becoming valuable partners to developers, enabling them to deliver functionality at a velocity previously thought to be out of reach. These partnerships range from developers passively accepting incremental code suggestions directly in their IDEs to explicitly delegating tasks to AI agents capable of autonomously rewriting partial or entire sets of files across a repository. Regardless of how extensive the AI’s involvement is, developers ultimately rely on the trusty build-test-run validation loop to ensure code quality and correctness. While not an absolute guarantee of correctness, an uneventful build-test-run loop is a pretty good indicator that no net new problems have been introduced by the changes — or, ideally, changes have resolved existing issues. In contrast, if this validation loop fails, at a minimum, the output of these commands provides enough information for developers to plan the next remedial steps. Thus, we believe as helpful this loop is to developers, having the capability of automatically setting up, building, and testing a repository will also provide a better perspective for AI-assisted workflows as it pertains to code generation. However, enabling the build-test-run loop requires an often manual setup process that blocks AI from delivering functionality until it is implemented or fixed, greatly slowing down the velocity that can be achieved, especially for new and rapidly evolving repositories. The goal of this exploration is to prototype an AI agent that can automatically figure out the setup, build, and test commands of a GitHub repository using a containerized environment. Eventually, we would like to build towards a system where the AI agent could augment existing LLM-based code generation capabilities by performing an iterative validation of successive code changes, similar to how a typical developer would. Approach To achieve this goal, we built “Discovery Agent”, an AI Agent that can iteratively determine the setup, build, and test commands of a given repository. Our approach is based on Bouzenia and Pradel’s recent paper, “You Name It, I Run It: An LLM Agent to Execute Tests of Arbitrary Projects”, particularly leveraging iterative refinement based on execution feedback. The figure below shows the high-level components of the discovery agent. Overview of Discovery Agent architecture. Discovery Agent is essentially a react-loop style agent with chain-of-thought reasoning. At each step, it selects and executes a tool from a predefined set of tools. For instance, Shell tool allows the agent to execute shell commands and capture the output of those commands to be fed back to the react loop to identify the next steps. Read File and Write File tools allow the agent to read and update the files in the repository. While we can use shell commands to achieve file handling, we observed that having explicit tools improves the overall performance of the agent, especially for file writes. We also provide the agent with a special “exit” tool, which the agent can use to exit the react loop when it determines that the exploration is complete. Discovery Agent always interprets tool invocations in a virtual environment, either based on Docker or Codespaces. In both cases, the agent has access to the cloned repository and can execute arbitrary shell commands in the container. Initially, we experimented with a tool that utilized heuristic-based strategies to populate the prompt with relevant context and attempt to infer the build and test commands in one shot. For example, we can detect the primary programming language of a repository and programmatically extract key files related to setup and build. For a TypeScript project, package.json is critical; for a typical Java project, pom.xml is important. README files like README.md or README.txt also frequently contain setup instructions. The idea behind providing this approach as a tool for the agent was that, even if the one-shot approach did not yield the final command, it would give the agent enough initial context to build upon and refine in the following react loop. However, we noticed that even when we pre-filled the prompt with relevant context, the agentic loop often re-read those files to confirm the information, effectively duplicating the work. As a result, we shifted to providing these heuristics as suggestions in the system prompt rather than injecting them directly into the prompt. This approach improves efficiency by avoiding unnecessary confirmations. It also allows the model to use its internal worldview encoding to prioritize relevant heuristics over less useful ones, making the exploration process more effective overall. While the react loop and chain-of-thought reasoning effectively handle the step-by-step operations by selecting the appropriate tools, the system prompt establishes the overall guiding strategy, ensuring that tool invocations contribute meaningfully to the repository-building process. In effect, the system prompt provides high-level guidance on how the model should go about problem-solving and how to leverage the collection of provided tools along the way. Here is a simplified high-level system prompt for our discovery agent. In particular, we chose a structured approach to the system prompt, delineating the objective and a list of higher-level suggestions to approach the problem. In addition, we also outlined the constraints that the agent must adhere to while making tool selections in the course of its react-loop. # Objective: You are an autonomous coding assistant tasked with validating developer changes by setting up, building, and testing projects automatically in a non-interactive, virtualized environment. # Steps: 1. Look for devontainer.json, CI script, and README to get ideas about setup/build and test the project. 2. Consider exploring the contents of the repository to some degree because there can be script files specifically for building and testing the project, and so it may be a good idea to reuse them. 3. The repository may be implemented in a variety of programming languages, so you may need to explore building and testing for multiple languages. 4. Given that your ultimate goal is to execute tests in the project, you must first ensure that the project is setup and built successfully. 5. It is not enough to build a subsystem of the project. Your goal is to build the entire project or provide reasonable evidence on why focusing on a subsystem is enough. 6. It is okay if there are no tests in the project, so that the testing step can be skipped, but you must verify this. 7. It is not enough to execute tests only for a subsystem in the project. Ultimately, your goal is to run all tests or provide clear evidence on why this is not necessary or possible. 8. It is not sufficient to just stop with the test exploration when _some_ test command is found but that fails due to e.g., missing dependencies. You must make a reasonable effort to actually kick off a test run successfully. # Constraints: 1. Do not execute interactive commands 2. If a command fails, analyze the error output and attempt corrective actions before retrying. 3. If a tool/dependency is missing, install it and continue. Technical Challenges Handling interactive and stuck terminal commands The model should avoid suggesting interactive terminal commands, such as vi or nano, since these require user input during execution. Such commands can lead to scenarios where manual intervention is needed, disrupting automated processes and complicating the overall workflow. By steering clear of interactive commands, the model ensures that instructions remain clear, non-blocking, and better suited for automated or scripted operations. To address this, we include a system prompt constraint that discourages the use of interactive commands. However, we found that suggestions alone aren’t always sufficient. Due to the inherent randomness in model outputs, these suggestions are sometimes ignored. Moreover, interactivity may arise unexpectedly—for example, from a poorly written unit test that prompts for user input or a dependency installation that requires confirmation. To handle these cases, we implemented an AI-based monitor that periodically samples the standard output and standard error of the running command. Based on the deltas between samples, the monitor determines whether the command is making progress or if it’s stuck, potentially waiting for user input. This approach allows us to effectively distinguish between long-running commands and those blocked on user interaction. Summarizing command output to preserve context It’s important to summarize the output of terminal commands before feeding it back to the model. This serves two main purposes. First, large outputs can quickly consume the model’s context window, preventing further instruction processing. Second, verbose or unfiltered outputs may distract or mislead the model from its intended task. Summarization helps maintain clarity, relevance, and efficiency in interactions. That said, not all outputs require summarization—especially if they’re small. We implemented a simple strategy based on a size thr