# jihe520/mathmodelagent architecture

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

- Interactive diagram: https://gitdiagram.com/jihe520/mathmodelagent
- Repository: https://github.com/jihe520/mathmodelagent

## Overview

##### Main Components
- User Interfaces: Represent the different entry points where users interact. These include:
- Web UI (webui.py)
- Terminal interface (terminal.py)
- (Indirectly) Jupyter interface support (tools/jupyter_backend.py)
- Core Processing Layer: This is where the agent orchestration happens. Key components include:
- Agents (core/Agents.py) that encapsulate the different roles (modeling, code execution, paper writing).
- LLM management (core/LLM.py) for interacting with various models.
- WorkFlow coordination (core/WorkFlow.py) which orchestrates the sequence of tasks.
- Data Models and Structures:
- Models in models/ (e.g., task, user_input, user_output) underpin the system’s logic and data representations.
- Configuration and Templates:
- Config directory (config/) holding configuration files (TOML and MD templates) that customize agent behavior and output formatting.
- Support and Utility Functions:
- Tools (tools/) that include the code interpreter and Jupyter backend components.
- Utils (utils/) offering logging, CLI parsing, data recording, and common utility functions.
- Project Data and Artifacts:
- The project directory stores examples, sample data, and work directories where output papers and intermediate artifacts are saved.
- Testing and Documentation:
- Tests (tests/) ensure that individual components perform as expected.
- Docs (docs/) along with example files provide further guidance and visuals (e.g., webui.png) relevant for understanding the UI.

##### Out Relationships & Interactions
- Data flowing from the configuration files (in config/) into the core agents, highlighting how the system is highly configurable.
- That the models (data structures in the models/ folder) are used throughout to represent tasks, inputs, and outputs.
- Support utilities (tools/ and utils/) that assist core operations: for instance, the code interpreter in tools/code_interpreter.py supports on-the-fly code execution and troubleshooting.

##### Architectural Patterns & Design Principles
- Modular & Decoupled: Emphasize the separation between presentation (UI), core orchestration (agent management and workflow), model definitions, configuration, and utility support.
- Multi-Agent Orchestration: Clearly illustrate that various specialized agents operate concurrently, each possibly powered by different LLMs, and work together seamlessly.
- Configuration Driven: The use of config files for model settings and template management indicates a design that favors flexibility and ease of updates.
- Extensibility: The presence of a tests directory and modular utilities implies that the project is designed for iterative development and incorporation of new features.

##### Technologies, Frameworks, and Tools to Annotate
- Python (core language of the project).
- 'uv' for environment and dependency management, which also runs commands (as seen in the README instructions).
- Integration with external libraries or tools for PDF and Excel processing (evident from the sample files in project/example).
- The inclusion of Jupyter backend suggests interactive notebook capabilities.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User Interfaces Layer
    subgraph "User Interfaces"
        UI1["Web UI"]:::ui
        UI2["Terminal Interface"]:::ui
        UI3["Jupyter Backend"]:::ui
    end

    %% Core Processing Layer
    subgraph "Core Processing Layer"
        CP1["Agent Orchestration"]:::core
        CP2["LLM Management"]:::core
        CP3["Workflow Coordination"]:::core
    end

    %% Data Models Layer
    subgraph "Data Models"
        DM1["Task Model"]:::data
        DM2["User Input Model"]:::data
        DM3["User Output Model"]:::data
    end

    %% Configuration & Templates Layer
    subgraph "Configuration & Templates"
        CT1["Config Module"]:::config
        CT2["Config TOML Example"]:::config
        CT3["MD Template TOML"]:::config
        CT4["Template MD"]:::config
    end

    %% Support & Utility Functions Layer
    subgraph "Support & Utility Functions"
        UT1["Code Interpreter"]:::util
        UT2["General Utilities"]:::util
    end

    %% Project Data & Artifacts Layer
    subgraph "Project Data & Artifacts"
        PD1["Work Directory"]:::artifact
        PD2["Sample Data"]:::artifact
    end

    %% Testing & Documentation Layer
    subgraph "Testing & Documentation"
        TD1["Tests"]:::test
        TD2["Documentation"]:::test
    end

    %% Connections from User Interfaces to Core Processing
    UI1 -->|"triggers"| CP3
    UI2 -->|"triggers"| CP3
    UI3 -->|"triggers"| CP3

    %% Core Processing interactions
    CP3 -->|"orchestrates"| CP1
    CP3 -->|"integrates"| CP2

    %% Data Models integration with Core Processing
    CP3 -->|"uses"| DM1
    CP3 -->|"uses"| DM2
    CP3 -->|"uses"| DM3

    %% Configuration influences Core Processing
    CT1 -->|"configures"| CP3
    CT2 -->|"configures"| CP3
    CT3 -->|"configures"| CP3
    CT4 -->|"configures"| CP3

    %% Support & Utilities assist Core Processing
    UT1 -->|"supports"| CP3
    UT2 -->|"supports"| CP3

    %% Final output from Core Processing to Data Artifacts
    CP3 -->|"saves outputs"| PD1
    CP3 -->|"saves outputs"| PD2

    %% Testing & Documentation relation (auxiliary)
    CP3 -->|"verified by"| TD1
    UI1 -->|"documented in"| TD2

    %% Click Events
    click UI1 "https://github.com/jihe520/mathmodelagent/blob/master/webui.py"
    click UI2 "https://github.com/jihe520/mathmodelagent/blob/master/terminal.py"
    click UI3 "https://github.com/jihe520/mathmodelagent/blob/master/tools/jupyter_backend.py"
    click CP1 "https://github.com/jihe520/mathmodelagent/blob/master/core/Agents.py"
    click CP2 "https://github.com/jihe520/mathmodelagent/blob/master/core/LLM.py"
    click CP3 "https://github.com/jihe520/mathmodelagent/blob/master/core/WorkFlow.py"
    click DM1 "https://github.com/jihe520/mathmodelagent/blob/master/models/task.py"
    click DM2 "https://github.com/jihe520/mathmodelagent/blob/master/models/user_input.py"
    click DM3 "https://github.com/jihe520/mathmodelagent/blob/master/models/user_output.py"
    click CT1 "https://github.com/jihe520/mathmodelagent/blob/master/config/config.py"
    click CT2 "https://github.com/jihe520/mathmodelagent/blob/master/config/config.toml.example"
    click CT3 "https://github.com/jihe520/mathmodelagent/blob/master/config/md_template.toml"
    click CT4 "https://github.com/jihe520/mathmodelagent/blob/master/config/template.md"
    click UT1 "https://github.com/jihe520/mathmodelagent/blob/master/tools/code_interpreter.py"
    click UT2 "https://github.com/jihe520/mathmodelagent/tree/master/utils/"
    click PD1 "https://github.com/jihe520/mathmodelagent/tree/master/project/work_dir"
    click PD2 "https://github.com/jihe520/mathmodelagent/tree/master/project/sample_data"
    click TD1 "https://github.com/jihe520/mathmodelagent/tree/master/tests/"
    click TD2 "https://github.com/jihe520/mathmodelagent/tree/master/docs/"

    %% Styles
    classDef ui fill:#f9d3c2,stroke:#333,stroke-width:2px;
    classDef core fill:#c2e1f9,stroke:#333,stroke-width:2px;
    classDef data fill:#d0f0c0,stroke:#333,stroke-width:2px;
    classDef config fill:#fceabb,stroke:#333,stroke-width:2px;
    classDef util fill:#e1d5e7,stroke:#333,stroke-width:2px;
    classDef artifact fill:#ffe0b5,stroke:#333,stroke-width:2px;
    classDef test fill:#ffc0cb,stroke:#333,stroke-width:2px;
```
