# microsoft/debug-gym architecture

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

- Interactive diagram: https://gitdiagram.com/microsoft/debug-gym
- Repository: https://github.com/microsoft/debug-gym

## Overview

Step 1. Identify the Main Project Components:
- Environment (debug_gym/gym):
– Contains submodules such as envs (with specific environments like aider, mini_nightmare, and swe_bench), terminal, and tools (e.g., pdb, listdir, eval, rewrite).
– Represents the simulation side that takes code repositories and allows iterative interactions (reset/step) with agents.
- Agents (debug_gym/agents):
– Includes various agent implementations (debug_agent, rewrite_agent, debug_5_agent) that interact with the environment.
– Leverages different tools for executing actions and interpreting observations.
- Analysis & Data:
– The “analysis” directory holds scripts (figure_*.py and gather_results.py) for processing or visualizing experimental results.
– The “data” directory stores benchmark repositories and configurations (mini_nightmare, pytorch, etc.) used for illustration and testing.
- Auxiliary and Support Components:
– “scripts” directory for YAML configuration files and the run.py entrypoint for launching agents with specific benchmarks.
– “tests” directory contains unit and integration tests, ensuring each component (agents, gym environment, and tools) works correctly.
– CI/CD setups are visible via the “.github/workflows” directory, which manage code formatting, testing, and code analysis.
– Configuration management (pyproject.toml, requirements.txt) and tool config files (e.g., pre-commit configuration) support development and deployment.

Step 2. Outline Relationships and Interactions:
- Under “Gym Environment”, further subdivide into:
– Env’s “envs” module (with key environments like RepoEnv, mini_nightmare, swe_bench).
– “Terminal” module responsible for executing code and returning test results.
– “Tools” module containing separate tools (pdb, listdir, view, eval, rewrite) that extend the environment’s capabilities.
- Under “Agents”, list the distinct agent types (e.g., debug_agent, rewrite_agent) and note that these rely on the environment to receive observations and issue commands.
- Auxiliary components such as “Scripts/Configs” (scripts) and “Tests” (tests) connected to the main modules to highlight development and quality assurance practices.

Step 3. Emphasize Architectural Patterns and Design Principles:
- That the environment follows the Gymnasium paradigm (with reset/step interactions).
- Modular design: dynamic tool integration allows new modules to be imported, which augments the agent’s action and observation spaces.
- Denote the loose coupling between agents and environment, as agents query for information and then issue commands based on the evolving state.
- Point out extensibility; for instance, new tools or agents can be added without major changes to the existing framework.

Step 4. Include Relevant Technologies and Frameworks:
- That the project runs on Python≥3.12.
- Use of Gymnasium concepts within the simulation environment.
- Integration of CI/CD tools (GitHub workflows: codeql, formatter, tests) which ensure quality.
- Mention configuration management via YAML files and the use of PyPI for package management.
- Optionally, annotate where LLM-based interactions occur, since agents rely on large language models via llm_api and external services.

- Use clear labels and consistent naming for each major module:
– Label “Gym Environment”, “Agents”, “Data/Benchmarks”, “Scripts/Configs”, “Tests”, and “CI/CD”.
– From Agents → Gym Environment (command/response cycle).
– From Environment → Tools (invocation of discrete functionalities).
– From Environment → Benchmarks (to simulate code repositories) and vice versa.
- Be detailed:
– Break down each module into sub-components if possible.
- Configuration points (e.g., wherein the LLM setup is defined via llm.yaml) and interact with the CLI entry point (scripts/run.py) which ties the system together.

Step 6. Final Touches:
- That each component is clearly referenced from the file tree and the README’s provided system design section.
- To include both “internal” (agents and gym modules) and “external” (benchmarks, CI/CD pipelines) elements to cover all aspects of the system.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Main Project Container
    MAIN["debug-gym"]:::main

    subgraph "Main Modules"
        ENV["Gym Environment"]:::environment
        AGENTS["Agents"]:::agents
    end

    MAIN --> ENV
    MAIN --> AGENTS
    AGENTS -->|"interacts"| ENV

    %% Gym Environment Submodules
    subgraph "Gym Environment Modules"
        ENV_ENVS["Envs"]:::module
        TERMINAL["Terminal"]:::module
        TOOLS["Tools"]:::module
    end

    ENV --> ENV_ENVS
    ENV --> TERMINAL
    ENV --> TOOLS

    %% Environment Files (Envs)
    ENV_AIDER["aider.py"]:::module
    ENV_ENV["env.py"]:::module
    ENV_MINI["mini_nightmare.py"]:::module
    ENV_SWE["swe_bench.py"]:::module

    ENV_ENVS --> ENV_AIDER
    ENV_ENVS --> ENV_ENV
    ENV_ENVS --> ENV_MINI
    ENV_ENVS --> ENV_SWE

    %% Tools Files
    TOOLS_EVAL["eval.py"]:::module
    TOOLS_LISTDIR["listdir.py"]:::module
    TOOLS_PDB["pdb.py"]:::module
    TOOLS_REWRITE["rewrite.py"]:::module
    TOOLS_VIEW["view.py"]:::module
    TOOLS_TOOLBOX["toolbox.py"]:::module
    TOOLS_TOOL["tool.py"]:::module

    TOOLS --> TOOLS_EVAL
    TOOLS --> TOOLS_LISTDIR
    TOOLS --> TOOLS_PDB
    TOOLS --> TOOLS_REWRITE
    TOOLS --> TOOLS_VIEW
    TOOLS --> TOOLS_TOOLBOX
    TOOLS --> TOOLS_TOOL

    %% Agents Files
    subgraph "Agent Implementations"
        AGENTS_BASE["base_agent.py"]:::module
        AGENTS_DEBUG["debug_agent.py"]:::module
        AGENTS_REWRITE["rewrite_agent.py"]:::module
        AGENTS_HISTORY["history_tracker.py"]:::module
        AGENTS_LLM["llm_api.py"]:::module
        AGENTS_UTILS["utils.py"]:::module
    end

    AGENTS --> AGENTS_BASE
    AGENTS --> AGENTS_DEBUG
    AGENTS --> AGENTS_REWRITE
    AGENTS --> AGENTS_HISTORY
    AGENTS --> AGENTS_LLM
    AGENTS --> AGENTS_UTILS

    %% Supporting Components
    subgraph "Supporting Components"
        ANALYSIS["Analysis"]:::support
        DATA["Data/Benchmarks"]:::support
        SCRIPTS["Scripts/Configs"]:::support
        TESTS["Tests"]:::support
        CICD["CI/CD"]:::support
        CONFIG["Configurations"]:::support
    end

    MAIN --- ANALYSIS
    MAIN --- DATA
    MAIN --- SCRIPTS
    MAIN --- TESTS
    MAIN --- CICD
    MAIN --- CONFIG

    %% Click Events for Gym Environment
    click ENV "https://github.com/microsoft/debug-gym/tree/main/debug_gym/gym"
    click ENV_ENVS "https://github.com/microsoft/debug-gym/tree/main/debug_gym/gym/envs"
    click TERMINAL "https://github.com/microsoft/debug-gym/blob/main/debug_gym/gym/terminal.py"
    click TOOLS "https://github.com/microsoft/debug-gym/tree/main/debug_gym/gym/tools"
    click ENV_AIDER "https://github.com/microsoft/debug-gym/blob/main/debug_gym/gym/envs/aider.py"
    click ENV_ENV "https://github.com/microsoft/debug-gym/blob/main/debug_gym/gym/envs/env.py"
    click ENV_MINI "https://github.com/microsoft/debug-gym/blob/main/debug_gym/gym/envs/mini_nightmare.py"
    click ENV_SWE "https://github.com/microsoft/debug-gym/blob/main/debug_gym/gym/envs/swe_bench.py"

    click TOOLS_EVAL "https://github.com/microsoft/debug-gym/blob/main/debug_gym/gym/tools/eval.py"
    click TOOLS_LISTDIR "https://github.com/microsoft/debug-gym/blob/main/debug_gym/gym/tools/listdir.py"
    click TOOLS_PDB "https://github.com/microsoft/debug-gym/blob/main/debug_gym/gym/tools/pdb.py"
    click TOOLS_REWRITE "https://github.com/microsoft/debug-gym/blob/main/debug_gym/gym/tools/rewrite.py"
    click TOOLS_VIEW "https://github.com/microsoft/debug-gym/blob/main/debug_gym/gym/tools/view.py"
    click TOOLS_TOOLBOX "https://github.com/microsoft/debug-gym/blob/main/debug_gym/gym/tools/toolbox.py"
    click TOOLS_TOOL "https://github.com/microsoft/debug-gym/blob/main/debug_gym/gym/tools/tool.py"

    %% Click Events for Agents
    click AGENTS "https://github.com/microsoft/debug-gym/tree/main/debug_gym/agents"
    click AGENTS_BASE "https://github.com/microsoft/debug-gym/blob/main/debug_gym/agents/base_agent.py"
    click AGENTS_DEBUG "https://github.com/microsoft/debug-gym/blob/main/debug_gym/agents/debug_agent.py"
    click AGENTS_REWRITE "https://github.com/microsoft/debug-gym/blob/main/debug_gym/agents/rewrite_agent.py"
    click AGENTS_HISTORY "https://github.com/microsoft/debug-gym/blob/main/debug_gym/agents/history_tracker.py"
    click AGENTS_LLM "https://github.com/microsoft/debug-gym/blob/main/debug_gym/agents/llm_api.py"
    click AGENTS_UTILS "https://github.com/microsoft/debug-gym/blob/main/debug_gym/agents/utils.py"

    %% Click Events for Supporting Components
    click ANALYSIS "https://github.com/microsoft/debug-gym/tree/main/analysis"
    click DATA "https://github.com/microsoft/debug-gym/tree/main/data"
    click SCRIPTS "https://github.com/microsoft/debug-gym/tree/main/scripts"
    click TESTS "https://github.com/microsoft/debug-gym/tree/main/tests"
    click CICD "https://github.com/microsoft/debug-gym/tree/main/.github/workflows"
    click CONFIG "https://github.com/microsoft/debug-gym/blob/main/pyproject.toml"

    %% Styles
    classDef main fill:#f9c,stroke:#333,stroke-width:2px;
    classDef environment fill:#ccf,stroke:#333,stroke-width:2px;
    classDef agents fill:#cfc,stroke:#333,stroke-width:2px;
    classDef module fill:#eef,stroke:#333,stroke-width:1px;
    classDef support fill:#ffe,stroke:#333,stroke-width:1px;
```
