# openautocoder/agentless architecture

> Architecture diagram of the GitHub repository openautocoder/agentless, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-02-24). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/openautocoder/agentless
- Repository: https://github.com/openautocoder/agentless

## Overview

##### Project Type and Overview
- This is an open-source system engineering tool that automatically tackles software issues using hierarchical fault localization, candidate patch generation (repair), and patch selection/validation (testing). The README clearly describes these phases and emphasizes integration with external services (e.g., using an API key for OpenAI), plus it is used to benchmark against SWE-bench.
- Its design is modular, with distinct directories handling different aspects, which indicates a pipeline-like architecture where data flows sequentially through multiple processing stages.

##### Analyzing the File Structure
- The primary code is in the "agentless" directory:
- "agentless/fl": Contains the fault localization modules (files like FL.py, Index.py, combine.py, localize.py, retrieve.py).
- "agentless/repair": Contains the repair modules (repair.py, rerank.py) responsible for generating and ranking candidate patches.
- "agentless/test": Contains scripts for generating reproduction tests and running various regression/reproduction tests.
- "agentless/util": Provides utility functions (like API requests, file compression, model handling, data pre- and postprocessing).
- There are additional directories:
- "classification": Supports an analysis component for classifying SWE-bench Lite problems, suggesting an auxiliary module for filtering or evaluation.
- "dev" and "get_repo_structure": These serve development utilities and repository structure extraction, helpful for internal testing and analysis.
- Notice the presence of configuration files (like .gitignore, pre-commit config) and dependency lists (requirements.txt) which ensure adherence to code quality and environment consistency.

- Main Components:
a. Fault Localization Module (agentless/fl)
- Responsible for pinpointing code areas related to issues. It first identifies files, then specific classes/functions, and finally fine-grained edit locations.
b. Repair Module (agentless/repair)
- Takes the localized information and produces candidate patches, with a mechanism to re-rank patches based on test results.
c. Patch Validation / Testing Module (agentless/test)
- Executes regression tests and uses supplementary reproduction tests to verify patches. It then feeds back the results to the repair module for final patch selection.
d. Utility Functions (agentless/util)
- Support all major processes with common tasks like API handling (potentially involving OpenAI services), file processing, and data conversion.
e. Classification & Analysis Module (classification)
- Although separate from the main processing flow, this module assists with benchmarking and manual classification of test cases.
f. External Integrations and Environment Setup
- Includes external components such as OpenAI API integration (configured via an environment variable) and possibly dependency on external benchmarks (SWE-bench) as outlined in the README.

- Relationships and Data Flow:
- Data flows sequentially from the localization module to the repair module, and finally through the testing/patch validation stage.
- Utility functions support each phase by providing data processing, API communication, or file handling capabilities.
- The classification module, while not in the primary workflow, connects to the evaluation of outcomes.
- Pipeline nature: localization results feed into repair, and repair candidate patches are validated via tests.

##### Architectural Patterns and Design Principles
- Pipeline Architecture: The work is broken into distinct sequential phases with clear input-output relationships between localization, repair, and validation.
- Modularity: The separation into different directories shows a commitment to single-responsibility; each module can be updated separately or tested in isolation.
- Extensibility: The classification and utility components hint at the ability to integrate new techniques or benchmarking tools in the future.
- External API Integration: Note how external dependencies (e.g., OpenAI API) get integrated into the core system.

##### Detailed Elements
- “Agentless Localization (agentless/fl)”: with sub-components for file-level, function-level, and edit-level localization.
- “Agentless Repair (agentless/repair)”: generating and re-ranking patches.
- “Agentless Test Suite (agentless/test)”: including scripts for regression and reproduction tests.
- “Agentless Utilities (agentless/util)”: covering preprocessing, API requests, and other common tasks.
- “Classification & Benchmarking (classification)”: addressing manual classifications.
- Use annotations to briefly describe each module’s role (e.g., “Generates candidate patches based on localized faults” for repair; “Validates patches and feeds back results for re-ranking” for testing).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Fault Localization Subgraph
    subgraph "Fault Localization (agentless/fl)"
        FL1["FL.py"]:::core
        FL2["Index.py"]:::core
        FL3["combine.py"]:::core
        FL4["localize.py"]:::core
        FL5["retrieve.py"]:::core
    end

    %% Repair Module Subgraph
    subgraph "Repair Module (agentless/repair)"
        R1["repair.py"]:::core
        R2["rerank.py"]:::core
    end

    %% Test Suite Subgraph
    subgraph "Test Suite (agentless/test)"
        T1["generate_reproduction_tests.py"]:::core
        T2["run_regression_tests.py"]:::core
        T3["run_reproduction_tests.py"]:::core
        T4["run_tests.py"]:::core
        T5["select_regression_tests.py"]:::core
    end

    %% Utilities Subgraph
    subgraph "Agentless Utilities (agentless/util)"
        U1["api_requests.py"]:::utility
        U2["compress_file.py"]:::utility
        U3["index_skeleton.py"]:::utility
        U4["model.py"]:::utility
        U5["parse_global_var.py"]:::utility
        U6["postprocess_data.py"]:::utility
        U7["preprocess_data.py"]:::utility
        U8["utils.py"]:::utility
    end

    %% Classification Subgraph
    subgraph "Classification & Benchmarking (classification)"
        C1["graph_classification.py"]:::analysis
        C2["load_filtered_benchmark.py"]:::analysis
        C3["README.md"]:::analysis
        C4["swebench_lite_classifications.csv"]:::analysis
    end

    %% External Service Node
    EXT["External Service (OpenAI API)"]:::external

    %% Core Pipeline Flow (vertical orientation)
    FL1 -->|"to_repair"| R1
    R1 -->|"to_testing"| T1
    T5 -->|"feedback"| R2

    %% Utility Functions Support (using U1 as representative)
    U1 ---|"supports_localization"| FL1
    U1 ---|"supports_repair"| R1
    U1 ---|"supports_testing"| T1
    U1 -->|"calls"| EXT

    %% Testing Evaluation feeds to Classification
    T1 -->|"evaluates"| C1

    %% Click Events for Fault Localization Files
    click FL1 "https://github.com/openautocoder/agentless/blob/main/agentless/fl/FL.py"
    click FL2 "https://github.com/openautocoder/agentless/blob/main/agentless/fl/Index.py"
    click FL3 "https://github.com/openautocoder/agentless/blob/main/agentless/fl/combine.py"
    click FL4 "https://github.com/openautocoder/agentless/blob/main/agentless/fl/localize.py"
    click FL5 "https://github.com/openautocoder/agentless/blob/main/agentless/fl/retrieve.py"

    %% Click Events for Repair Module Files
    click R1 "https://github.com/openautocoder/agentless/blob/main/agentless/repair/repair.py"
    click R2 "https://github.com/openautocoder/agentless/blob/main/agentless/repair/rerank.py"

    %% Click Events for Test Suite Files
    click T1 "https://github.com/openautocoder/agentless/blob/main/agentless/test/generate_reproduction_tests.py"
    click T2 "https://github.com/openautocoder/agentless/blob/main/agentless/test/run_regression_tests.py"
    click T3 "https://github.com/openautocoder/agentless/blob/main/agentless/test/run_reproduction_tests.py"
    click T4 "https://github.com/openautocoder/agentless/blob/main/agentless/test/run_tests.py"
    click T5 "https://github.com/openautocoder/agentless/blob/main/agentless/test/select_regression_tests.py"

    %% Click Events for Utility Functions Files
    click U1 "https://github.com/openautocoder/agentless/blob/main/agentless/util/api_requests.py"
    click U2 "https://github.com/openautocoder/agentless/blob/main/agentless/util/compress_file.py"
    click U3 "https://github.com/openautocoder/agentless/blob/main/agentless/util/index_skeleton.py"
    click U4 "https://github.com/openautocoder/agentless/blob/main/agentless/util/model.py"
    click U5 "https://github.com/openautocoder/agentless/blob/main/agentless/util/parse_global_var.py"
    click U6 "https://github.com/openautocoder/agentless/blob/main/agentless/util/postprocess_data.py"
    click U7 "https://github.com/openautocoder/agentless/blob/main/agentless/util/preprocess_data.py"
    click U8 "https://github.com/openautocoder/agentless/blob/main/agentless/util/utils.py"

    %% Click Events for Classification Files
    click C1 "https://github.com/openautocoder/agentless/blob/main/classification/graph_classification.py"
    click C2 "https://github.com/openautocoder/agentless/blob/main/classification/load_filtered_benchmark.py"
    click C3 "https://github.com/openautocoder/agentless/blob/main/classification/README.md"
    click C4 "https://github.com/openautocoder/agentless/blob/main/classification/swebench_lite_classifications.csv"

    %% Classes Definitions for Colors
    classDef core fill:#D1E8FF,stroke:#1E88E5,stroke-width:2px;
    classDef utility fill:#FFF9C4,stroke:#FBC02D,stroke-width:2px;
    classDef analysis fill:#C8E6C9,stroke:#388E3C,stroke-width:2px;
    classDef external fill:#FFCCBC,stroke:#F4511E,stroke-width:2px;
```
