# samuelschmidgall/agentlaboratory architecture

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

- Interactive diagram: https://gitdiagram.com/samuelschmidgall/agentlaboratory
- Repository: https://github.com/samuelschmidgall/agentlaboratory

## Overview

##### Project Type and Purpose
- Agent Laboratory is an open-source Python CLI tool (no frontend/UI) that orchestrates multiple LLM-driven “agents” to automate a research workflow: literature review → experimentation → report writing. It also supports AgentRxiv for collaborative agent uploads.

##### File-Structure Analysis
- Top-level Python scripts:
- ai_lab_repo.py – main orchestrator/entrypoint
- app.py – auxiliary CLI entry (argument parsing)
- agents.py – definitions of specialized agent classes
- inference.py – abstraction over LLM backends (OpenAI, DeepSeek)
- mlesolver.py, papersolver.py – solver modules used by agents
- tools.py, utils.py, common_imports.py – utility and helper functions
- experiment_configs/*.yaml – pipeline configuration (which agents, resources, language, model flags, task notes, etc.)
- readme/ – translated documentation
- requirements.txt, LICENSE, README.md

##### README Insights
- Three phases of the research pipeline, each driven by specialized LLM agents.
- External integrations: arXiv API, Hugging Face datasets, Python execution, LaTeX (pdflatex).
- Checkpointing via state_saves for fault tolerance.
- Configurable LLM backends and resource flags via CLI and YAML.

a. Main Components
- User (CLI) – triggers the workflow via ai_lab_repo.py/app.py
- Orchestrator – core engine in ai_lab_repo.py that reads YAML, spins up agents
- Agent Modules – individual classes in agents.py corresponding to:
– LiteratureReviewAgent
– PlanFormulationAgent
– DataPreparationAgent
– ExperimentationAgent
– ReportWritingAgent
– (Optional) AgentRxivAgent for uploads
- Inference Layer – inference.py abstracts calls to OpenAI/DeepSeek
- Solver Libraries – mlesolver.py, papersolver.py for domain-specific tasks
- Utility Layer – tools.py, utils.py, common_imports.py (file I/O, logging, checkpointing)
- Configuration Store – YAML files in experiment_configs/
- Persistence – state_saves (local filesystem checkpoints)
- External Services –
– LLM backends (OpenAI, DeepSeek)
– arXiv API
– Hugging Face datasets
– pdflatex (optional)

b. Relationships & Data Flow
1. User issues CLI command → app.py parses args → ai_lab_repo.py reads config
2. Orchestrator loads YAML → initializes agents in sequence
3. Each Agent invokes the Inference Layer → sends prompts & receives responses
4. Agents call Solver Libraries or Utility functions as needed
5. Intermediate results are saved to state_saves → next agent picks up
6. ReportWritingAgent optionally invokes pdflatex → generates final PDF
7. (Optional) AgentRxivAgent interacts with AgentRxiv server via HTTP

c. Architectural Patterns & Principles
- Pipeline/Workflow Orchestration: clear separation of phases
- Modular Agent Pattern: each research task is encapsulated in its own class
- Inversion of Control for LLM backends: inference.py abstracts provider details
- Configuration-driven design: experiment_configs drive behavior without code changes
- Checkpointing for Fault Tolerance

d. Key Technologies
- Python 3.12
- YAML for configuration
- OpenAI & DeepSeek APIs via inference.py
- Hugging Face datasets
- pdflatex (system call)
- arXiv API
- Standard libs: pathlib, logging, subprocess

## Diagram (Mermaid)

```mermaid
flowchart TD
    User["User CLI"]:::external
    App["app.py"]:::core
    Orchestrator["ai_lab_repo.py"]:::core
    Config["experiment_configs/"]:::config
    subgraph "Agents" 
        direction TB
        LiAgent["LiteratureReviewAgent"]:::core
        PlanAgent["PlanFormulationAgent"]:::core
        DataAgent["DataPreparationAgent"]:::core
        ExpAgent["ExperimentationAgent"]:::core
        ReportAgent["ReportWritingAgent"]:::core
        RxivAgent["AgentRxivAgent"]:::core
    end
    Inference["inference.py"]:::core
    subgraph "Solvers"
        direction TB
        MLSolver["mlesolver.py"]:::core
        PaperSolver["papersolver.py"]:::core
    end
    subgraph "Utilities"
        direction TB
        Utils["utils.py"]:::core
        Tools["tools.py"]:::core
        Common["common_imports.py"]:::core
    end
    Persistence["state_saves"]:::config
    subgraph "External Services"
        direction TB
        OpenAI["OpenAI API"]:::external
        DeepSeek["DeepSeek API"]:::external
        arXiv["arXiv API"]:::external
        HF["Hugging Face Datasets"]:::external
        Pdflatex["pdflatex"]:::external
        AgentRxivServer["AgentRxiv Server"]:::external
    end

    User -->|"issues CLI command"| App
    App -->|"parses args"| Orchestrator
    Orchestrator -->|"reads config"| Config
    Orchestrator -->|"initializes agents"| LiAgent
    LiAgent -->|"then"| PlanAgent
    PlanAgent -->|"then"| DataAgent
    DataAgent -->|"then"| ExpAgent
    ExpAgent -->|"then"| ReportAgent
    ReportAgent -->|"optional upload"| RxivAgent

    LiAgent -->|"prompt→response"| Inference
    PlanAgent -->|"prompt→response"| Inference
    DataAgent -->|"prompt→response"| Inference
    ExpAgent -->|"prompt→response"| Inference
    ReportAgent -->|"prompt→response"| Inference

    Inference -->|"calls API"| OpenAI
    Inference -->|"calls API"| DeepSeek

    LiAgent -->|"uses"| PaperSolver
    ExpAgent -->|"uses"| MLSolver

    LiAgent -->|"uses"| Utils
    ExpAgent -->|"uses"| Tools
    Orchestrator -->|"imports"| Common

    LiAgent -->|"save checkpoint"| Persistence
    PlanAgent -->|"load checkpoint"| Persistence
    PlanAgent -->|"save checkpoint"| Persistence
    DataAgent -->|"load checkpoint"| Persistence
    DataAgent -->|"save checkpoint"| Persistence
    ExpAgent -->|"load checkpoint"| Persistence
    ExpAgent -->|"save checkpoint"| Persistence
    ReportAgent -->|"load checkpoint"| Persistence

    ReportAgent -->|"generates PDF"| Pdflatex
    RxivAgent -->|"HTTP upload"| AgentRxivServer

    classDef core fill:#add8e6,stroke:#333,stroke-width:1px
    classDef external fill:#90ee90,stroke:#333,stroke-width:1px
    classDef config fill:#ffa500,stroke:#333,stroke-width:1px

    click App "https://github.com/samuelschmidgall/agentlaboratory/blob/main/app.py"
    click Orchestrator "https://github.com/samuelschmidgall/agentlaboratory/blob/main/ai_lab_repo.py"
    click LiAgent "https://github.com/samuelschmidgall/agentlaboratory/blob/main/agents.py"
    click PlanAgent "https://github.com/samuelschmidgall/agentlaboratory/blob/main/agents.py"
    click DataAgent "https://github.com/samuelschmidgall/agentlaboratory/blob/main/agents.py"
    click ExpAgent "https://github.com/samuelschmidgall/agentlaboratory/blob/main/agents.py"
    click ReportAgent "https://github.com/samuelschmidgall/agentlaboratory/blob/main/agents.py"
    click RxivAgent "https://github.com/samuelschmidgall/agentlaboratory/blob/main/agents.py"
    click Inference "https://github.com/samuelschmidgall/agentlaboratory/blob/main/inference.py"
    click MLSolver "https://github.com/samuelschmidgall/agentlaboratory/blob/main/mlesolver.py"
    click PaperSolver "https://github.com/samuelschmidgall/agentlaboratory/blob/main/papersolver.py"
    click Utils "https://github.com/samuelschmidgall/agentlaboratory/blob/main/utils.py"
    click Tools "https://github.com/samuelschmidgall/agentlaboratory/blob/main/tools.py"
    click Common "https://github.com/samuelschmidgall/agentlaboratory/blob/main/common_imports.py"
    click Config "https://github.com/samuelschmidgall/agentlaboratory/tree/main/experiment_configs/"
    click Config "https://github.com/samuelschmidgall/agentlaboratory/blob/main/experiment_configs/MATH_agentlab.yaml"
    click Config "https://github.com/samuelschmidgall/agentlaboratory/blob/main/experiment_configs/MATH_agentrxiv.yaml"
    click Persistence "https://github.com/samuelschmidgall/agentlaboratory/tree/main/state_saves"
    click Pdflatex "https://github.com/samuelschmidgall/agentlaboratory/blob/main/requirements.txt"
    click AgentRxivServer "https://github.com/samuelschmidgall/agentlaboratory/blob/main/README.md"
```
