### Install Go, Zoekt, and ctags Source: https://context7.com/fsoft-ai4code/hyperagent/llms.txt Installs Go, Zoekt for code search, and universal-ctags for semantic code search. Follow external instructions for Go and ctags installation. ```bash # Install Go (required for Zoekt) # Follow instructions at https://www.linuxedo.com/2021/10/install-latest-golang-on-linux.html # Install Zoekt for code search go get github.com/sourcegraph/zoekt/ go install github.com/sourcegraph/zoekt/cmd/zoekt-index go install github.com/sourcegraph/zoekt/cmd/zoekt-webserver # Install universal-ctags for semantic code search # Follow instructions at https://github.com/sourcegraph/sourcegraph/blob/main/doc/dev/how-to/zoekt_local_dev.md#install-ctags export CTAGS_COMMAND=universal-ctags ``` -------------------------------- ### CLI Setup Command for Local and Remote Repositories Source: https://context7.com/fsoft-ai4code/hyperagent/llms.txt Sets up a local or remote GitHub repository for HyperAgent's code search capabilities. Requires repository name, language, and optionally a commit hash or GitHub token. ```bash # Setup a local repository hyperagent setup /path/to/local/repo \ --repository-name my-project \ --language python \ --commit abc123 # Setup a remote GitHub repository hyperagent setup https://github.com/owner/repo \ --repository-name owner-repo \ --language python \ --clone-dir data/repos \ --gh-token $GITHUB_TOKEN ``` -------------------------------- ### Install Zoekt dependencies Source: https://github.com/fsoft-ai4code/hyperagent/blob/main/README.md Commands to install the Zoekt code search tool and its associated indexer and web server components. ```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 ``` -------------------------------- ### Test HyperAgent Installation Source: https://context7.com/fsoft-ai4code/hyperagent/llms.txt Perform a command-line test of HyperAgent by specifying a repository, commit, language, and a custom prompt for querying. ```bash # Test HyperAgent with a general prompt python3 main.py \ --repo "https://github.com/owner/repo" \ --commit "abc123def" \ --language "python" \ --prompt "How can I add a new API endpoint to handle user authentication?" ``` -------------------------------- ### Install HyperAgent environment Source: https://github.com/fsoft-ai4code/hyperagent/blob/main/README.md Commands to create the required conda environment and install the HyperAgent package. ```bash conda create -n hyperagent python=3.10 pip3 install -e . ``` -------------------------------- ### CLI Query Command for Interactive Sessions Source: https://context7.com/fsoft-ai4code/hyperagent/llms.txt Starts an interactive session to query a previously indexed repository using natural language. Allows specifying planner type and agent type. ```bash # Start interactive query session hyperagent query my-project \ --planner-type adaptive \ --type-agent gpt-4 \ --verbose 1 # Example interactive session: # > Your query: How does the authentication system work? # > Your query: Find all usages of the UserSession class # > Your query: exit ``` -------------------------------- ### Install HyperAgent and Dependencies Source: https://context7.com/fsoft-ai4code/hyperagent/llms.txt Creates a conda environment for the Jupyter kernel and installs HyperAgent using pip. ```bash # Create conda environment (required for Jupyter kernel) conda create -n hyperagent python=3.10 conda activate hyperagent # Install HyperAgent pip3 install -e . ``` -------------------------------- ### Initialize HyperAgent Source: https://github.com/fsoft-ai4code/hyperagent/blob/main/README.md Instantiate the HyperAgent with repository details and optional configuration. Ensure `repo`, `commit`, and `language` are provided. The `clone_dir` specifies where the repository will be stored. ```python from hyperagent import HyperAgent pilot = HyperAgent(repo, commit=commit, language=language, clone_dir="data/repos") ``` -------------------------------- ### Initialize and Query HyperAgent Programmatically Source: https://context7.com/fsoft-ai4code/hyperagent/llms.txt Initializes the HyperAgent class with repository details and LLM configurations, then queries the codebase with a natural language prompt. ```python import os from hyperagent import HyperAgent # Configure LLM settings for each agent 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_key": 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_key": os.environ.get("ANTHROPIC_API_KEY"), "price": [0.003, 0.015], "base_url": "https://api.anthropic.com", "api_type": "anthropic", }], "type": "patch" # Use "patch" for code generation, "pred" for predictions } # Initialize HyperAgent with a GitHub repository pilot = HyperAgent( repo_path="https://github.com/astropy/astropy", commit="a5917978be39d13cd90b517e1de4e7a539ffaa48", language="python", clone_dir="data/repos", llm_configs=config, verbose=1 ) # Query the codebase with a natural language prompt response = pilot.query_codebase( "How do I add a new memory efficient fine-tuning technique to this project?" ) print(response) ``` -------------------------------- ### Run SWE-Bench Evaluation Source: https://github.com/fsoft-ai4code/hyperagent/blob/main/README.md Execute the script to reproduce SWE-Bench evaluation results. This command-line interface allows specifying the dataset split for testing. ```bash python3 scripts/run_swe_bench.py --split "test" ``` -------------------------------- ### Initialize and Run SWE-Bench Task Source: https://context7.com/fsoft-ai4code/hyperagent/llms.txt Initializes the SWEBench task for resolving GitHub issues. It requires LLM configurations and processes instances to generate patches. Ensure ANTHROPIC_API_KEY is set in the environment. ```python from hyperagent import HyperAgent from hyperagent.tasks.github_issue_resolve import SWEBench import os # Configure LLM settings config = { "name": "claude", "nav": [{"model": "claude-3-haiku-20240307", "api_key": os.environ.get("ANTHROPIC_API_KEY"), "api_type": "anthropic", "base_url": "https://api.anthropic.com", "stop_sequences": ["\nObservation:"]}], "edit": [{"model": "claude-3-5-sonnet-20240620", "api_key": os.environ.get("ANTHROPIC_API_KEY"), "api_type": "anthropic", "base_url": "https://api.anthropic.com", "stop_sequences": ["\nObservation:"], "price": [0.003, 0.015]}], "exec": [{"model": "claude-3-5-sonnet-20240620", "api_key": os.environ.get("ANTHROPIC_API_KEY"), "api_type": "anthropic", "base_url": "https://api.anthropic.com", "stop_sequences": ["\nObservation:"], "price": [0.003, 0.015]}], "plan": [{"model": "claude-3-5-sonnet-20240620", "api_key": os.environ.get("ANTHROPIC_API_KEY"), "api_type": "anthropic", "base_url": "https://api.anthropic.com", "price": [0.003, 0.015]}], "type": "patch" } # Initialize the SWE-Bench task task = SWEBench(logdir="results/swe_bench", split="verified") # Process each instance for idx in range(len(task)): repo_link, commit, instance_id, image_name = task[idx] # Initialize HyperAgent for this instance pilot = HyperAgent( repo_path=repo_link, commit=commit, language="python", clone_dir="data/repos", llm_configs=config, image_name=image_name, verbose=1 ) # Run the task and get the patch patch = task.run(pilot, idx) print(f"Instance {instance_id}: Generated patch of {len(patch)} characters") ``` -------------------------------- ### Run SWE-Bench Evaluation Source: https://context7.com/fsoft-ai4code/hyperagent/llms.txt Execute the SWE-Bench evaluation script. Specify the split (e.g., 'verified', 'test'), an output folder, and optionally a model nickname. ```bash # Run SWE-Bench evaluation on verified split python3 scripts/run_swe_bench.py --split verified --output_folder outputs/ --model_nick_name hyperagent # Run on test split python3 scripts/run_swe_bench.py --split test --output_folder outputs/ ``` -------------------------------- ### Run HyperAgent quick test Source: https://github.com/fsoft-ai4code/hyperagent/blob/main/README.md Command to execute a test run of HyperAgent with a specific repository, commit, language, and prompt. ```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" ``` -------------------------------- ### CLI List Command for Indexed Repositories Source: https://context7.com/fsoft-ai4code/hyperagent/llms.txt Lists all repositories that have been indexed and are available for querying via the HyperAgent CLI. ```bash hyperagent list # Output: # my-project # owner-repo # another-project ``` -------------------------------- ### Initialize and Use SemanticCodeSearchTool Source: https://context7.com/fsoft-ai4code/hyperagent/llms.txt Initializes the SemanticCodeSearchTool for natural language code searching. Requires a database path and can build the index on first use. Set build to False if the database already exists. ```python from hyperagent.tools.nav_tools import SemanticCodeSearchTool # Initialize with index building (first time) semantic_search = SemanticCodeSearchTool( path="/path/to/repository", language="python", db_path="/tmp/semantic_db/my_project", build=True # Set to False if database already exists ) # Search using natural language result = semantic_search._run( "function that handles user authentication and session management" ) print(result) ``` -------------------------------- ### Initialize and Use GetAllSymbolsTool Source: https://context7.com/fsoft-ai4code/hyperagent/llms.txt Initializes the GetAllSymbolsTool to extract all symbols from a source file. Can filter symbols by a keyword. ```python from hyperagent.tools.nav_tools import GetAllSymbolsTool # Initialize the tool get_symbols = GetAllSymbolsTool( path="/path/to/repository", language="python" ) # Get all symbols from a file result = get_symbols._run( path_to_file="core/models.py" ) print(result) # Output: List of all functions, classes, and methods in the file # Filter symbols by keyword result = get_symbols._run( path_to_file="core/models.py", keyword="User" # Only show symbols containing "User" ) print(result) # Output: UserModel, UserSerializer, create_user, etc. ``` -------------------------------- ### Initialize and Use OpenFileTool Source: https://context7.com/fsoft-ai4code/hyperagent/llms.txt Initializes the OpenFileTool for opening and searching within files. Supports keyword search, line range viewing, and semantic queries. ```python from hyperagent.tools.nav_tools import OpenFileTool # Initialize the tool open_file = OpenFileTool( path="/path/to/repository", language="python" ) # Search for keywords in a file result = open_file._run( relative_file_path="core/processor.py", keywords=["process_data", "transform"] ) print(result) # Output: Code snippets containing the keywords with line numbers # View specific line range (max 90 lines) result = open_file._run( relative_file_path="core/processor.py", start_line=100, end_line=150 ) print(result) # Output: Lines 100-150 with line numbers # Semantic search (requires embedding model) result = open_file._run( relative_file_path="core/processor.py", keywords=["process"], semantic_query="code that handles data validation and error checking" ) print(result) ``` -------------------------------- ### Initialize and Use CodeSearchTool Source: https://context7.com/fsoft-ai4code/hyperagent/llms.txt Initializes the CodeSearchTool for searching identifiers in a repository. Set build to True if the index does not exist. ```python from hyperagent.tools.nav_tools import CodeSearchTool # Initialize code search with a repository code_search = CodeSearchTool( path="/path/to/repository", language="python", index_path="/tmp/zoekt_index/my_project", build=True # Set to False if index already exists ) # Search for function or class names result = code_search._run(names=["some_function", "MyClass"]) print(result) # Output: List of files and locations where these symbols are defined # Note: Use single identifiers, not dotted paths # Correct: ["some_function"] # Incorrect: ["module.something"] ``` -------------------------------- ### Initialize and Use FindAllReferencesTool Source: https://context7.com/fsoft-ai4code/hyperagent/llms.txt Initializes the FindAllReferencesTool to locate all references to a target symbol across the project using LSP. Specify the symbol, its location, and optionally the number of results. ```python from hyperagent.tools.nav_tools import FindAllReferencesTool # Initialize the tool find_refs = FindAllReferencesTool( path="/path/to/repository", language="python" ) # Find all references to a symbol result = find_refs._run( word="process_data", relative_file_path="core/processor.py", line=25, num_results=10 # Limit number of results ) print(result) # Output: List of file paths and line numbers where the symbol is referenced ``` -------------------------------- ### Initialize and Use FindFileTool Source: https://context7.com/fsoft-ai4code/hyperagent/llms.txt Initializes the FindFileTool to locate files within a repository by name. Supports exact and partial name matching. ```python from hyperagent.tools.nav_tools import FindFileTool # Initialize the tool find_file = FindFileTool( path="/path/to/repository", language="python" ) # Find a file by name result = find_file._run(file_name="config.py") print(result) # Find partial matches result = find_file._run(file_name="test_user") print(result) ``` -------------------------------- ### Initialize and Use GoToDefinitionTool Source: https://context7.com/fsoft-ai4code/hyperagent/llms.txt Initializes the GoToDefinitionTool to find the definition of a symbol within a code snippet using LSP. Requires the word, relative path, and line number of the symbol's usage. ```python from hyperagent.tools.nav_tools import GoToDefinitionTool # Initialize the tool with repository path go_to_def = GoToDefinitionTool( path="/path/to/repository", language="python" ) # Find definition of a symbol result = go_to_def._run( word="some_function", relative_path="module/file.py", line=42 # Line number where the symbol is used ) print(result) # Output: Definition location with file path and line number ``` -------------------------------- ### Initialize and Use GetTreeStructureTool Source: https://context7.com/fsoft-ai4code/hyperagent/llms.txt Initializes the GetTreeStructureTool to explore the directory tree structure of a folder. Specify the relative path and the desired depth of exploration. ```python from hyperagent.tools.nav_tools import GetTreeStructureTool # Initialize the tool tree_tool = GetTreeStructureTool( path="/path/to/repository", language="python" ) # Explore folder structure result = tree_tool._run( relative_path="src/", depth=2 # Depth of tree exploration ) print(result) # Output: # The tree structure of src/ is: # src/ # ├── core/ # │ ├── models.py # │ └── views.py # ├── utils/ # │ └── helpers.py # └── main.py ``` -------------------------------- ### Run Defects4J Fault Localization Source: https://github.com/fsoft-ai4code/hyperagent/blob/main/README.md Execute the script to reproduce fault localization results on the Defects4J dataset. This is a command-line operation. ```bash python3 scripts/run_defects4j_fl.py ``` -------------------------------- ### Initialize EditorTool Source: https://context7.com/fsoft-ai4code/hyperagent/llms.txt Initializes the EditorTool for modifying files in a repository. Includes automatic syntax validation for Python code. ```python from hyperagent.tools.gen_tools import EditorTool ``` -------------------------------- ### Initialize and Run Fault Localization Task Source: https://context7.com/fsoft-ai4code/hyperagent/llms.txt Initialize a FaultLocalization task with specified parameters and then process each bug in the dataset using a HyperAgent instance. This includes checking out the buggy version, running the agent, and collecting results. ```python # Initialize fault localization task task = FaultLocalization( logdir="results/defects4j_fl", split="test", max_repetitions=1, max_num_tests=2, defects4j="/path/to/defects4j" ) # Process each bug result_list = [] for idx in range(len(task)): repo_dir = task[idx] # Checks out the buggy version pilot = HyperAgent( repo_path=repo_dir, commit="", language="java", llm_configs=config, verbose=2 ) result = task.run(pilot, idx) result_list.append(result) # Print running performance metrics performance = task.report(result_list) print(f"Correct: {performance['correct']}/{performance['total']}") ``` -------------------------------- ### Run Defects4J Program Repair Source: https://github.com/fsoft-ai4code/hyperagent/blob/main/README.md Execute the script to reproduce program repair results on the Defects4J dataset. This is a command-line operation. ```bash python3 scripts/run_defects4j_apr.py ``` -------------------------------- ### Run Defects4J Program Repair Source: https://context7.com/fsoft-ai4code/hyperagent/llms.txt Execute the script for running automated program repair on the Defects4J dataset. ```bash # Run automated program repair on Defects4J python3 scripts/run_defects4j_apr.py ``` -------------------------------- ### Initialize and Use EditorTool for File Editing Source: https://context7.com/fsoft-ai4code/hyperagent/llms.txt Initializes the EditorTool to modify a specified file within a repository. Use this to programmatically replace sections of code with new content and provide a context message for the change. ```python editor = EditorTool( path="/path/to/repository", language="python" ) # Edit a file by replacing lines result = editor._run( relative_file_path="core/processor.py", start_line=42, end_line=50, patch=""" def process_data(self, data): # Improved implementation with validation if not data: raise ValueError("Data cannot be empty") return self._transform(data)""", context="Fixing bug in data processing - adding validation" ) print(result) ``` -------------------------------- ### Implement Task Run Method Source: https://github.com/fsoft-ai4code/hyperagent/blob/main/README.md Implement the `run` method within a custom task class to define how HyperAgent processes a task. This method should construct a prompt, query the codebase, and return the task's result, such as a prediction patch. ```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 ``` -------------------------------- ### Configure HyperAgent Source: https://github.com/fsoft-ai4code/hyperagent/blob/main/README.md Define the configuration for HyperAgent, specifying models, API keys, and other parameters for different operational modes like navigation, editing, execution, and planning. The `type` parameter sets the agent's primary mode. ```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" } ``` -------------------------------- ### Initialize FaultLocalization Task Source: https://context7.com/fsoft-ai4code/hyperagent/llms.txt Initializes the FaultLocalization task for identifying buggy methods in Java projects using the Defects4J benchmark. This task analyzes failed test cases and stack traces to pinpoint bug sources. ```python from hyperagent import HyperAgent from hyperagent.tasks.fault_localization import FaultLocalization import os ``` -------------------------------- ### Configure HyperAgent for Prediction Mode Source: https://context7.com/fsoft-ai4code/hyperagent/llms.txt Configure HyperAgent with specific LLM settings for prediction mode, including model names, API keys, base URLs, and stop sequences. This configuration is used for tasks like fault localization. ```python config = { "name": "claude", "nav": [{"model": "claude-3-haiku-20240307", "api_key": os.environ.get("ANTHROPIC_API_KEY"), "api_type": "anthropic", "base_url": "https://api.anthropic.com", "stop_sequences": ["\nObservation:"]}], "edit": [{"model": "claude-3-5-sonnet-20240620", "api_key": os.environ.get("ANTHROPIC_API_KEY"), "api_type": "anthropic", "base_url": "https://api.anthropic.com", "stop_sequences": ["\nObservation:"], "price": [0.003, 0.015]}], "exec": [{"model": "claude-3-haiku-20240307", "api_key": os.environ.get("ANTHROPIC_API_KEY"), "api_type": "anthropic", "base_url": "https://api.anthropic.com", "stop_sequences": ["\nObservation:"], "price": [0.003, 0.015]}], "plan": [{"model": "claude-3-5-sonnet-20240620", "api_key": os.environ.get("ANTHROPIC_API_KEY"), "api_type": "anthropic", "base_url": "https://api.anthropic.com", "price": [0.003, 0.015]}], "type": "pred" # Prediction mode for fault localization } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.