# primengine/prime architecture

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

- Interactive diagram: https://gitdiagram.com/primengine/prime
- Repository: https://github.com/primengine/prime

## Overview

##### Main Components

a) Core Framework Layer:
- Main modules from src/prime/:
- agents.py (Agent System)
- tools.py (Tools Management)
- models.py (Model Interfaces)
- monitoring.py (Monitoring System)

b) Execution Environments:
- Two parallel execution systems:
- e2b_executor.py
- local_python_executor.py

c) External Integrations:
- LLM Models Interface (via models.py)
- Tool Integration System
- Solana Blockchain Connection
- DuckDuckGo Search Integration

##### Component Relationships

- User Input → Agent System
- Agent System ↔ Tool Management
- Agent System ↔ Model Interface
- Execution Environment ↔ Tool Management
- Monitoring System → All Components

##### Specific Implementation Details

Create sections showing:
a) Tool Integration Layer:
- Default Tools (default_tools.py)
- Custom Tool Integration
- Tool Validation System (tool_validation.py)

b) Agent Architecture:
- CodeAgent Implementation
- Prompt Management (prompts.py)
- Type System (types.py)

##### Additional Elements

- Documentation System (docs structure)
- Testing Framework (tests directory)
- CI/CD Pipeline (.github/workflows)

##### Key Design Principles to Highlight

- Modular Architecture
- Extensible Tool System
- Secure Execution Environment
- Blockchain Integration Points

**[External Services Layer]**
- ↕
**[Integration Layer]**
- ↕
**[Core Framework Layer]**
- ↕
**[Execution Layer]**
- ↕
**[Infrastructure Layer]**

Important Considerations:

- Double lines: Data flow

##### Grouping: Use containers or bounded contexts to group related components
- Agent System Components
- Tool Management System
- Execution Environments
- External Integrations

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Core["Core System Components"]
        direction TB
        AE["Agent Engine<br/>(Core agent logic & orchestration)"]:::core
        TMS["Tool Management System<br/>(Tool interface & built-ins)"]:::core
        MIL["Model Interface Layer<br/>(LLM integrations)"]:::core
        EE["Execution Environments<br/>(Code execution & sandbox)"]:::core
        ML["Monitoring & Logging<br/>(Performance tracking)"]:::core
        TS["Type System<br/>(Data structures)"]:::core
        PT["Prompt Templates<br/>(Agent interaction templates)"]:::core
    end

    subgraph UI["User Interfaces"]
        direction TB
        WI["Web Interface<br/>(Gradio-based UI)"]:::ui
        API["Python API<br/>(Direct integration)"]:::ui
    end

    subgraph EXT["External Integrations"]
        direction TB
        HF["HuggingFace<br/>(LLM provider)"]:::external
        DDG["DuckDuckGo<br/>(Search tool)"]:::external
        E2B["E2B<br/>(Remote execution)"]:::external
    end

    subgraph EXAMPLES["Example Implementations"]
        direction TB
        RAG["RAG Example<br/>(Retrieval-Augmented Generation)"]:::example
        SQL["Text-to-SQL<br/>(Query generation)"]:::example
        TC["Tool Calling<br/>(LLM integration examples)"]:::example
    end

    subgraph DOCS["Documentation"]
        direction TB
        CG["Conceptual Guides"]:::doc
        AR["API Reference"]:::doc
        TUT["Tutorials"]:::doc
    end

    %% Relationships
    AE --> TMS
    AE --> MIL
    AE --> EE
    AE --> ML
    TMS --> DDG
    MIL --> HF
    EE --> E2B
    AE --> PT
    AE --> TS

    WI --> AE
    API --> AE

    RAG --> AE
    SQL --> AE
    TC --> AE

    %% Click events
    click AE "https://github.com/primengine/prime/blob/main/src/prime/agents.py"
    click TMS "https://github.com/primengine/prime/blob/main/src/prime/tools.py"
    click MIL "https://github.com/primengine/prime/blob/main/src/prime/models.py"
    click EE "https://github.com/primengine/prime/blob/main/src/prime/e2b_executor.py"
    click ML "https://github.com/primengine/prime/blob/main/src/prime/monitoring.py"
    click WI "https://github.com/primengine/prime/blob/main/src/prime/gradio_ui.py"
    click TS "https://github.com/primengine/prime/blob/main/src/prime/types.py"
    click PT "https://github.com/primengine/prime/blob/main/src/prime/prompts.py"
    click RAG "https://github.com/primengine/prime/blob/main/examples/rag.py"
    click SQL "https://github.com/primengine/prime/blob/main/examples/text_to_sql.py"
    click TC "https://github.com/primengine/prime/blob/main/examples/tool_calling_agent_from_any_llm.py"
    click CG "https://github.com/primengine/prime/tree/main/docs/source/en/conceptual_guides/"
    click AR "https://github.com/primengine/prime/tree/main/docs/source/en/reference/"
    click TUT "https://github.com/primengine/prime/tree/main/docs/source/en/tutorials/"

    %% Styling
    classDef core fill:#f9f,stroke:#333,stroke-width:2px
    classDef ui fill:#bbf,stroke:#333,stroke-width:2px
    classDef external fill:#dfd,stroke:#333,stroke-width:2px
    classDef example fill:#ffd,stroke:#333,stroke-width:2px
    classDef doc fill:#ddd,stroke:#333,stroke-width:2px

    %% Legend
    subgraph Legend
        direction TB
        L1["Core Components"]:::core
        L2["User Interfaces"]:::ui
        L3["External Services"]:::external
        L4["Examples"]:::example
        L5["Documentation"]:::doc
    end
```
