AutoCodeRover Documentation

repository·main·Indexed 25 days ago

https://github.com/autocoderoversg/auto-code-rover

AutoCodeRover is an autonomous program improvement tool designed to resolve GitHub issues, including bug fixes and feature additions. It combines Large Language Models (LLMs) with program-structure-aware code search and statistical fault localization. The tool supports multiple operation modes, including github-issue, local-issue, and SWE-bench tasks, and is compatible with models from OpenAI, Anthropic, Meta, AWS Bedrock, Groq, and local models via Ollama.

Tokens
5.7K
Snippets
15
Records
37
Agent score
84%

What's inside AutoCodeRover

  1. Configure parallel execution in AutoCodeRover

    main

    Do not attempt to run multiple independent processes of scripts/run.py in parallel, as different task instances may share the same local codebase, leading to conflicts.

    Instead, use the built-in parallelism support by setting the num_processes field in your configuration file. The script handles the internal parallelism safely. Note: setting num_processes too high may exceed OpenAI token limits and cause task failures.

  2. Run AutoCodeRover in GitHub issue mode

    main

    Use github-issue mode to run AutoCodeRover on a live GitHub issue. You must provide the project's clone link, a specific commit hash, and the link to the GitHub issue page. The tool will clone the repository, checkout the specified commit, and attempt to generate a patch.

    Successful patch generation writes the path to selected_patch.json in the specified --output-dir.

    cd /opt/auto-code-rover
    conda activate auto-code-rover
    PYTHONPATH=. python app/main.py github-issue --output-dir output --setup-dir setup --model gpt-4o-2024-05-13 --model-temperature 0.2 --task-id <task id> --clone-link <link for cloning the project> --commit-hash <any version that has the issue> --issue-link <link to issue page>
  3. Set up AutoCodeRover for SWE-bench-lite replication using Docker

    main

    To replicate results on SWE-bench-lite, use the provided Docker image which contains all task instance environments. It is recommended to run this on Ubuntu 20.04.

    1. Pull the latest experiment image:
      docker pull yuntongzhang/auto-code-rover:experiment
    2. Start the container:
      docker run -it yuntongzhang/auto-code-rover:experiment
    3. Inside the container, activate the conda environment:
      source activate base
      conda activate auto-code-rover
    4. Configure global git settings:
      git config --global user.email acr@nus.edu.sg
      git config --global user.name acr
    5. Set your OpenAI API key:
      export OPENAI_KEY=xx-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    docker pull yuntongzhang/auto-code-rover:experiment
    docker run -it yuntongzhang/auto-code-rover:experiment
  4. Set up the environment for local testing

    main

    To run tests locally, you must first create and activate the auto-code-rover environment using Conda, then install tox from the conda-forge channel.

    Required tools:

    • Tox: Configures the tests.
    • Pytest: Executes the tests.
    • Coverage.py: Measures code coverage.
    conda env create -f environment.yml
    conda activate auto-code-rover
    
    conda config --add channels conda-forge
    conda config --set channel_priority flexible
    conda install -y tox
  5. Configure local Llama 3 models via Ollama

    main

    To use local models like llama3 with AutoCodeRover:

    1. Install Ollama: Download and install Ollama.
    2. Pull Models: Run ollama pull llama3 to download the model.
    3. Network Configuration:
      • If running ACR in a Docker container and Ollama on the host machine, use Docker Desktop to simplify host access.
      • If using only Docker Engine, you must add either --net=host or --add-host host.docker.internal=host-gateway to your docker run command so the container can communicate with the Ollama server on the host.
  6. Set up and run SWE-bench tasks

    main

    To run AutoCodeRover on SWE-bench task instances, follow these steps:

    1. Install SWE-bench Docker

    Install the specialized SWE-bench docker fork used for regression tests:

    conda activate auto-code-rover
    git submodule update --init --recursive
    cd SWE-bench-docker
    pip install .

    2. Set up the Testbed

    It is recommended to set up SWE-bench on a host machine rather than inside a container.

    1. Clone the SWE-bench fork and install dependencies.
    2. Create a tasks.txt file containing one task ID per line (e.g., django__django-11133).
    3. Run the setup harness:
    cd <SWE-bench-path>
    conda activate swe-bench
    python harness/run_setup.py --log_dir logs --testbed testbed --result_dir setup_result --subset_file tasks.txt

    This creates a testbed directory with the source code and a conda environment for the task.

    3. Run Tasks

    Single Task:

    cd <AutoCodeRover-path>
    conda activate auto-code-rover
    PYTHONPATH=. python app/main.py swe-bench --model gpt-4o-2024-05-13 --setup-map <SWE-bench-path>/setup_result/setup_map.json --tasks-map <SWE-bench-path>/setup_result/tasks_map.json --output-dir output --task django__django-11133

    Multiple Tasks (via file):

    cd <AutoCodeRover-path>
    conda activate auto-code-rover
    PYTHONPATH=. python app/main.py swe-bench --model gpt-4o-2024-05-13 --setup-map <SWE-bench-path>/setup_result/setup_map.json --tasks-map <SWE-bench-path>/setup_result/tasks_map.json --output-dir output --task-list-file <SWE-bench-path>/tasks.txt
  7. Run AutoCodeRover in local issue mode

    main

    Use local-issue mode to run AutoCodeRover on a local codebase and a local issue description file. This is useful when you have already prepared the repository and the issue details manually.

    Successful patch generation writes the path to selected_patch.json in the specified --output-dir.

    cd /opt/auto-code-rover
    conda activate auto-code-rover
    PYTHONPATH=. python app/main.py local-issue --output-dir output --model gpt-4o-2024-05-13 --model-temperature 0.2 --task-id <task id> --local-repo <path to the local project repository> --issue-file <path to the file containing issue description>
  8. Set up AutoCodeRover in local mode

    main

    For running SWE-bench experiments or managing dependencies manually, use a local installation with Conda. This method uses an environment.yml file to manage Python dependencies.

    1. Create Environment: Use Conda to create the environment from the provided file.
    2. Configure Keys: Ensure OPENAI_KEY or ANTHROPIC_API_KEY is set in your shell before execution.
  9. Run AutoCodeRover experiments

    main

    Navigate to the /opt/auto-code-rover/ directory inside the container to start an experiment. By default, running the vanilla-lite configuration uses gpt-4-0125-preview on SWE-bench-lite instances.

    This command consolidates all generated patches into a single file named predictions_for_swebench.json. To evaluate correctness, you must copy this file out and use either the Containerized Evaluation Harness or Moatless EvalTools.

    python scripts/run.py conf/vanilla-lite.conf
  10. Manage experiment runs and overwriting results

    main

    When running multiple experiments sequentially, it is recommended to use a unique id in the configuration file for each run, as the output directory is named after this id.

    If you wish to use the same id and overwrite previous results, use the -f flag with scripts/run.py to remove the existing experiment results for that id before starting the new run.