# landing-ai/vision-agent-tools architecture

> Architecture diagram of the GitHub repository landing-ai/vision-agent-tools, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-06-16). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/landing-ai/vision-agent-tools
- Repository: https://github.com/landing-ai/vision-agent-tools

## Overview

##### Project type and purpose
- This is an open-source Python library (not a deployed web or mobile app) providing a suite of computer-vision “tools” and underlying ML “models.”
- Its primary use case is to let downstream applications (like the Vision Agent web app or your own scripts/notebooks) call high-level tools (e.g., `TextToObjectDetection`) which in turn dispatch to one of many model implementations (e.g., Florence2, Owlv2).

##### File structure
- Top-level: configuration files (`pyproject.toml`, `mkdocs.yml`, CI workflows), docs, assets, notebooks, scripts, tests.
- Core code in `vision_agent_tools/`:
- `models/`: each file wraps a specific ML model class inheriting `BaseMLModel`.
- `tools/`: each file implements a high-level task inheriting `BaseTool`.
- `model_registry.py`: a dictionary that maps model names to lazy-loader lambdas.
- `helpers/`: shared utilities and filters.
- `shared_types.py`: base classes and pydantic types.
- Tests mirror the code structure under `tests/` with fixtures, model data, and tool/model unit tests.

##### README for additional insights
- High-level usage examples show how users load an image, instantiate a model or tool, and call it.
- Sections on “Adding new model code” and “Adding new tool code” emphasize the plugin-style architecture via registration and inheritance.

a. Main components:
- Client code (scripts / notebooks / Vision Agent web app)
- Tools layer (`vision_agent_tools.tools`)
- Model registry (`vision_agent_tools.models.model_registry`)
- Models layer (`vision_agent_tools.models`)
- Helpers/utilities (`vision_agent_tools.helpers`, `vision_agent_tools.shared_types`)
- External ML frameworks & runtime (PyTorch / Transformers / PIL)
- Documentation and CI (MkDocs, GitHub Actions)
b. Relationships and interactions:
1. Client calls a Tool class (e.g., `TextToObjectDetection`).
2. Tool uses `get_model_class` from the model registry to instantiate the correct `BaseMLModel`.
3. Model class wraps calls to external frameworks (loads checkpoint, processes image, returns results).
4. Tool post-processes model output into tool-specific output schema.
5. Helpers (filters, utilities) can be invoked by either models or tools.
6. CI pipelines run tests and publish docs from the same repo.
c. Architectural patterns & principles:
- Plugin / registry pattern for dynamic model loading
- Separation of concerns: Tools (high-level tasks) vs. Models (raw ML inference) vs. Helpers
- Lazy import to reduce startup overhead and manage dependencies
- Pydantic for data validation in I/O types
d. Key technologies/frameworks:
- Python 3, Poetry (build & dependency management)
- MkDocs for documentation
- PyTorch & HuggingFace Transformers under the hood in ML model implementations
- PIL for image loading and processing
- pytest for unit testing
- GitHub Actions for CI

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Client Code Layer
    subgraph "Client Code" 
        direction TB
        InstallScript["install.sh"]:::code
        NBImage["run_florence2sam2_image.ipynb"]:::code
        NBVideo["run_florence2sam2_video.ipynb"]:::code
    end

    %% Tools Layer
    subgraph "Tools Layer" 
        direction TB
        DepthEstimation["depth_estimation.py"]:::code
        OCR["ocr.py"]:::code
        QRReaderTool["qr_reader.py"]:::code
        SharedModelManager["shared_model_manager.py"]:::code
        TextToClass["text_to_classification.py"]:::code
        TextToInstanceSeg["text_to_instance_segmentation.py"]:::code
        TextToObjDet["text_to_object_detection.py"]:::code
    end

    %% Model Registry
    ModelRegistry["model_registry.py"]:::code

    %% Models Layer
    subgraph "Models Layer"
        direction TB
        ClipMediaSim["clip_media_sim.py"]:::code
        ControlNetAux["controlnet_aux.py"]:::code
        DepthAnythingV2["depth_anything_v2.py"]:::code
        Florence2["florence2.py"]:::code
        Florence2QA["florence2_qa.py"]:::code
        Florence2SAM2["florence2_sam2.py"]:::code
        Flux1["flux1.py"]:::code
        InternLMX2["internlm_xcomposer2.py"]:::code
        NSFWClass["nsfw_classification.py"]:::code
        NShotCount["nshot_counting.py"]:::code
        OwlV2["owlv2.py"]:::code
        QRReaderModel["qr_reader.py"]:::code
        Qwen2VL["qwen2_vl.py"]:::code
        RobertaQA["roberta_qa.py"]:::code
        SAM2["sam2.py"]:::code
        SigLIP["siglip.py"]:::code
        UtilsModel["utils.py"]:::code
    end

    %% Helpers & Shared Types
    subgraph "Helpers & Shared Types"
        direction TB
        Filters["filters.py"]:::code
        IxcUtils["ixc_utils.py"]:::code
        SharedTypes["shared_types.py"]:::code
    end

    %% External Frameworks
    subgraph "External ML Frameworks" 
        direction TB
        PyTorch["PyTorch"]:::external
        Transformers["Transformers"]:::external
        PIL["PIL"]:::external
    end

    %% CI & Documentation
    subgraph "CI & Docs"
        direction TB
        CIUnit["unit-tests.yml"]:::repo
        CIDocs["publish_docs.yml"]:::repo
        MkdocsFile["mkdocs.yml"]:::repo
        DocsIndex["docs/index.md"]:::repo
        DocsOthers["docs/*.md"]:::repo
    end

    %% Connections
    InstallScript -->|calls| DepthEstimation
    NBImage -->|calls| TextToObjDet
    NBVideo -->|calls| TextToObjDet

    DepthEstimation -->|uses registry| ModelRegistry
    OCR -->|uses registry| ModelRegistry
    QRReaderTool -->|uses registry| ModelRegistry
    SharedModelManager -->|uses registry| ModelRegistry
    TextToClass -->|uses registry| ModelRegistry
    TextToInstanceSeg -->|uses registry| ModelRegistry
    TextToObjDet -->|uses registry| ModelRegistry

    ModelRegistry -->|instantiates| ClipMediaSim
    ModelRegistry --> ControlNetAux
    ModelRegistry --> DepthAnythingV2
    ModelRegistry --> Florence2
    ModelRegistry --> Florence2QA
    ModelRegistry --> Florence2SAM2
    ModelRegistry --> Flux1
    ModelRegistry --> InternLMX2
    ModelRegistry --> NSFWClass
    ModelRegistry --> NShotCount
    ModelRegistry --> OwlV2
    ModelRegistry --> QRReaderModel
    ModelRegistry --> Qwen2VL
    ModelRegistry --> RobertaQA
    ModelRegistry --> SAM2
    ModelRegistry --> SigLIP
    ModelRegistry --> UtilsModel

    %% Helpers usage
    DepthEstimation -->|uses| Filters
    OCR -->|uses| IxcUtils
    QRReaderTool -->|uses| Filters
    TextToClass -->|uses| SharedTypes
    Florence2 -->|uses| IxcUtils
    OWlv2 -->|uses| Filters
    ClipMediaSim -->|uses| SharedTypes
    DepthAnythingV2 -->|uses| Filters
    Florence2SAM2 -->|uses| PIL
    Qwen2VL -->|uses| Transformers
    RobertaQA -->|uses| PyTorch

    %% Models to external
    Florence2 -->|runs on| PyTorch
    OWlv2 -->|runs on| Transformers
    SAM2 -->|runs on| PyTorch
    ControlNetAux -->|uses| PyTorch

    %% CI & Docs connections
    CIUnit -.->|runs tests on| DepthEstimation
    CIUnit -.->|runs tests on| Florence2
    CIDocs -.->|publishes| DocsIndex
    CIDocs -.->|publishes| DocsOthers
    CIDocs -.->|reads| MkdocsFile

    %% Click Events
    click InstallScript "https://github.com/landing-ai/vision-agent-tools/blob/main/scripts/install.sh"
    click NBImage "https://github.com/landing-ai/vision-agent-tools/blob/main/notebooks/run_florence2sam2_image.ipynb"
    click NBVideo "https://github.com/landing-ai/vision-agent-tools/blob/main/notebooks/run_florence2sam2_video.ipynb"

    click DepthEstimation "https://github.com/landing-ai/vision-agent-tools/blob/main/vision_agent_tools/tools/depth_estimation.py"
    click OCR "https://github.com/landing-ai/vision-agent-tools/blob/main/vision_agent_tools/tools/ocr.py"
    click QRReaderTool "https://github.com/landing-ai/vision-agent-tools/blob/main/vision_agent_tools/tools/qr_reader.py"
    click SharedModelManager "https://github.com/landing-ai/vision-agent-tools/blob/main/vision_agent_tools/tools/shared_model_manager.py"
    click TextToClass "https://github.com/landing-ai/vision-agent-tools/blob/main/vision_agent_tools/tools/text_to_classification.py"
    click TextToInstanceSeg "https://github.com/landing-ai/vision-agent-tools/blob/main/vision_agent_tools/tools/text_to_instance_segmentation.py"
    click TextToObjDet "https://github.com/landing-ai/vision-agent-tools/blob/main/vision_agent_tools/tools/text_to_object_detection.py"

    click ModelRegistry "https://github.com/landing-ai/vision-agent-tools/blob/main/vision_agent_tools/models/model_registry.py"

    click ClipMediaSim "https://github.com/landing-ai/vision-agent-tools/blob/main/vision_agent_tools/models/clip_media_sim.py"
    click ControlNetAux "https://github.com/landing-ai/vision-agent-tools/blob/main/vision_agent_tools/models/controlnet_aux.py"
    click DepthAnythingV2 "https://github.com/landing-ai/vision-agent-tools/blob/main/vision_agent_tools/models/depth_anything_v2.py"
    click Florence2 "https://github.com/landing-ai/vision-agent-tools/blob/main/vision_agent_tools/models/florence2.py"
    click Florence2QA "https://github.com/landing-ai/vision-agent-tools/blob/main/vision_agent_tools/models/florence2_qa.py"
    click Florence2SAM2 "https://github.com/landing-ai/vision-agent-tools/blob/main/vision_agent_tools/models/florence2_sam2.py"
    click Flux1 "https://github.com/landing-ai/vision-agent-tools/blob/main/vision_agent_tools/models/flux1.py"
    click InternLMX2 "https://github.com/landing-ai/vision-agent-tools/blob/main/vision_agent_tools/models/internlm_xcomposer2.py"
    click NSFWClass "https://github.com/landing-ai/vision-agent-tools/blob/main/vision_agent_tools/models/nsfw_classification.py"
    click NShotCount "https://github.com/landing-ai/vision-agent-tools/blob/main/vision_agent_tools/models/nshot_counting.py"
    click OwlV2 "https://github.com/landing-ai/vision-agent-tools/blob/main/vision_agent_tools/models/owlv2.py"
    click QRReaderModel "https://github.com/landing-ai/vision-agent-tools/blob/main/vision_agent_tools/models/qr_reader.py"
    click Qwen2VL "https://github.com/landing-ai/vision-agent-tools/blob/main/vision_agent_tools/models/qwen2_vl.py"
    click RobertaQA "https://github.com/landing-ai/vision-agent-tools/blob/main/vision_agent_tools/models/roberta_qa.py"
    click SAM2 "https://github.com/landing-ai/vision-agent-tools/blob/main/vision_agent_tools/models/sam2.py"
    click SigLIP "https://github.com/landing-ai/vision-agent-tools/blob/main/vision_agent_tools/models/siglip.py"
    click UtilsModel "https://github.com/landing-ai/vision-agent-tools/blob/main/vision_agent_tools/models/utils.py"

    click Filters "https://github.com/landing-ai/vision-agent-tools/blob/main/vision_agent_tools/helpers/filters.py"
    click IxcUtils "https://github.com/landing-ai/vision-agent-tools/blob/main/vision_agent_tools/helpers/ixc_utils.py"
    click SharedTypes "https://github.com/landing-ai/vision-agent-tools/blob/main/vision_agent_tools/shared_types.py"

    click DocsIndex "https://github.com/landing-ai/vision-agent-tools/blob/main/docs/index.md"
    click DocsOthers "https://github.com/landing-ai/vision-agent-tools/blob/main/docs/*.md"
    click MkdocsFile "https://github.com/landing-ai/vision-agent-tools/blob/main/mkdocs.yml"
    click CIUnit "https://github.com/landing-ai/vision-agent-tools/blob/main/.github/workflows/unit-tests.yml"
    click CIDocs "https://github.com/landing-ai/vision-agent-tools/blob/main/.github/workflows/publish_docs.yml"

    %% Styles
    classDef code fill:#e0f7fa,stroke:#006064,color:#004d40
    classDef external fill:#ffecb3,stroke:#ff6f00,color:#e65100
    classDef repo fill:#eceff1,stroke:#455a64,color:#263238
```
