## Installation and Usage HyperAgent uses Zoekt for code search. Please install Zoekt before installing HyperAgent. Zoekt requires latest Go installation, please follow the instructions [here](https://www.linuxedo.com/2021/10/install-latest-golang-on-linux.html) to install Go. ```bash go get github.com/sourcegraph/zoekt/ # Install Zoekt Index go install github.com/sourcegraph/zoekt/cmd/zoekt-index # Install Zoekt Web Server go install github.com/sourcegraph/zoekt/cmd/zoekt-webserver ``` We also need to install universal-ctags for semantic code search. Please follow the instructions [here](https://github.com/sourcegraph/sourcegraph/blob/main/doc/dev/how-to/zoekt_local_dev.md#install-ctags). Remember to set the environment variable of CTAGS `CTAGS_COMMAND=universal-ctags`. After installing Zoekt and universal-ctags, we can install HyperAgent by running the following commands, notes that it's a must to create a new conda environment before installing HyperAgent named hyperagent, since the Executor uses jupyter kernel named hyperagent to execute the code: ```bash conda create -n hyperagent python=3.10 pip3 install -e . ``` ### Quick Test To test the hyperagent with general prompt, you can run the following command: ```bash python3 main.py --repo "your/path/to/repo" --commit "commit_hash" --language "python" --clone_dir "data/repos" --prompt "I want to create an FastAPI app to handle GET request from OpenAI API" ``` ### General usage ```python from hyperagent import HyperAgent pilot = HyperAgent(repo, commit=commit, language=language, clone_dir="data/repos") ``` with `repo` is the repository URL, `commit` is the commit hash, `language` is the programming language of the repository, and `clone_dir` is the directory to store the cloned repository. You also can configure the agents by setting the `config` parameter. Hyperagent supports 2 modes: patch and predict. In the patch mode, the agent will generate a patch for the given task. In the predict mode, the agent will predict the next token for the given task (for example, repoQA or fault location). ```python config = { "name": "claude", "nav": [{ "model": "claude-3-haiku-20240307", "api_key": os.environ.get("ANTHROPIC_API_KEY"), "stop_sequences": ["\nObservation:"], "base_url": "https://api.anthropic.com", "api_type": "anthropic", }], "edit": [{ "model": "claude-3-5-sonnet-20240620", "api_key": os.environ.get("ANTHROPIC_API_KEY"), "stop_sequences": ["\nObservation:"], "price": [0.003, 0.015], "base_url": "https://api.anthropic.com", "api_type": "anthropic", }], "exec": [{ "model": "claude-3-5-sonnet-20240620", "api_type": os.environ.get("ANTHROPIC_API_KEY"), "stop_sequences": ["\nObservation:"], "price": [0.003, 0.015], "base_url": "https://api.anthropic.com", "api_type": "anthropic", }], "plan": [{ "model": "claude-3-5-sonnet-20240620", "api_type": os.environ.get("ANTHROPIC_API_KEY"), "price": [0.003, 0.015], "base_url": "https://api.anthropic.com", "api_type": "anthropic", }], "type": "patch" } ``` HyperAgent is a software generalist agent, therefore it can be used to solve various software engineering tasks. We provide a few examples of how to use HyperAgent to solve different tasks in the `scripts` folder. This is easily configured via an input template prompt for each task. For example, in `src/hyperagent/tasks/github_issue_resolution.py`, we provide a script to resolve GitHub issues using HyperAgent. The script will prompt the user to input the issue title and description, and then HyperAgent will generate a patch to resolve the issue. ```python def run(self, system, idx) -> Result: prompt = self.construct_prompt(idx) system.query_codebase(prompt) prediction_patch = extract_patch(system.repo_dir) return prediction_patch ``` If you want to use HyperAgent to solve other tasks and systematically evaluate the results, you can create a new task class and implement the `run` method. The `run` method should return the result of the task. ## Reproduce Evaluation Results To reproduce the results, please follow the instructions in the `scripts` folder. We provide the scripts to reproduce the results on SWE-Bench, RepoExec, and Defects4J datasets. ### SWE-Bench ```bash python3 scripts/run_swe_bench.py --split "test" ``` ### Fault Localization ```bash python3 scripts/run_defects4j_fl.py ``` ### Program Repair ```bash python3 scripts/run_defects4j_apr.py ``` ### # Citing HyperAgent If you're using HyperAgent in your research or applications, please cite using this BibTeX: ```bibtex @article{huy2024hyperagent, title={HyperAgent: Generalist Software Engineering Agents to Solve Coding Tasks at Scale}, author={Phan, Huy Nhat and Nguyen, Phong X and Bui, Nghi DQ}, journal={arXiv preprint arXiv:2406.11912}, year={2024} } ``` # Contact us If you have any questions, comments or suggestions, please do not hesitate to contact us. - Website: [fpt-aicenter](https://www.fpt-aicenter.com/ai-residency/) - Email: bdqnghi@gmail.com # License [MIT License](LICENSE)