Togmal-demo / ARCHITECTURE.md
HeTalksInMaths
Initial commit: ToGMAL Prompt Difficulty Analyzer with real MMLU data
f9b1ad5
|
raw
history blame
19.1 kB

ToGMAL Architecture

System Overview

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                         Claude Desktop                          β”‚
β”‚                    (or other MCP Client)                        β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                             β”‚ stdio/MCP Protocol
                             β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                     ToGMAL MCP Server                           β”‚
β”‚                    (togmal_mcp.py)                             β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
β”‚  β”‚                   MCP Tools Layer                         β”‚  β”‚
β”‚  β”‚  - togmal_analyze_prompt                                 β”‚  β”‚
β”‚  β”‚  - togmal_analyze_response                               β”‚  β”‚
β”‚  β”‚  - togmal_submit_evidence                                β”‚  β”‚
β”‚  β”‚  - togmal_get_taxonomy                                   β”‚  β”‚
β”‚  β”‚  - togmal_get_statistics                                 β”‚  β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
β”‚                     β”‚                                           β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
β”‚  β”‚              Detection Heuristics                         β”‚  β”‚
β”‚  β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚  β”‚
β”‚  β”‚  β”‚  Math/Physics Speculation Detector                 β”‚  β”‚  β”‚
β”‚  β”‚  β”‚  - Pattern: "theory of everything"                 β”‚  β”‚  β”‚
β”‚  β”‚  β”‚  - Pattern: "new equation"                         β”‚  β”‚  β”‚
β”‚  β”‚  β”‚  - Pattern: excessive notation                     β”‚  β”‚  β”‚
β”‚  β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚  β”‚
β”‚  β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚  β”‚
β”‚  β”‚  β”‚  Ungrounded Medical Advice Detector                β”‚  β”‚  β”‚
β”‚  β”‚  β”‚  - Pattern: "you probably have"                    β”‚  β”‚  β”‚
β”‚  β”‚  β”‚  - Pattern: "take Xmg"                            β”‚  β”‚  β”‚
β”‚  β”‚  β”‚  - Check: has_sources                              β”‚  β”‚  β”‚
β”‚  β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚  β”‚
β”‚  β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚  β”‚
β”‚  β”‚  β”‚  Dangerous File Operations Detector                β”‚  β”‚  β”‚
β”‚  β”‚  β”‚  - Pattern: "rm -rf"                              β”‚  β”‚  β”‚
β”‚  β”‚  β”‚  - Pattern: recursive deletion                     β”‚  β”‚  β”‚
β”‚  β”‚  β”‚  - Check: has_safeguards                          β”‚  β”‚  β”‚
β”‚  β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚  β”‚
β”‚  β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚  β”‚
β”‚  β”‚  β”‚  Vibe Coding Overreach Detector                   β”‚  β”‚  β”‚
β”‚  β”‚  β”‚  - Pattern: "complete app"                         β”‚  β”‚  β”‚
β”‚  β”‚  β”‚  - Pattern: large line counts                      β”‚  β”‚  β”‚
β”‚  β”‚  β”‚  - Check: has_planning                            β”‚  β”‚  β”‚
β”‚  β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚  β”‚
β”‚  β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚  β”‚
β”‚  β”‚  β”‚  Unsupported Claims Detector                       β”‚  β”‚  β”‚
β”‚  β”‚  β”‚  - Pattern: "always/never"                         β”‚  β”‚  β”‚
β”‚  β”‚  β”‚  - Pattern: statistics without source              β”‚  β”‚  β”‚
β”‚  β”‚  β”‚  - Check: has_hedging                             β”‚  β”‚  β”‚
β”‚  β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚  β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
β”‚                     β”‚                                           β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
β”‚  β”‚           Risk Assessment & Interventions                 β”‚  β”‚
β”‚  β”‚  - Calculate weighted risk score                         β”‚  β”‚
β”‚  β”‚  - Map to risk levels (LOW β†’ CRITICAL)                  β”‚  β”‚
β”‚  β”‚  - Recommend interventions                               β”‚  β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
β”‚                     β”‚                                           β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
β”‚  β”‚              Taxonomy Database                            β”‚  β”‚
β”‚  β”‚  - In-memory storage (extendable to persistent)          β”‚  β”‚
β”‚  β”‚  - Evidence entries with metadata                        β”‚  β”‚
β”‚  β”‚  - Filtering and pagination                              β”‚  β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Data Flow - Prompt Analysis

User Prompt
    β”‚
    β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
    β”‚                                             β”‚
    β–Ό                                             β”‚
togmal_analyze_prompt                             β”‚
    β”‚                                             β”‚
    β”œβ”€β”€β–Ί Math/Physics Detector ──► Result 1      β”‚
    β”‚                                             β”‚
    β”œβ”€β”€β–Ί Medical Advice Detector ──► Result 2    β”‚
    β”‚                                             β”‚
    β”œβ”€β”€β–Ί File Ops Detector ──► Result 3          β”‚
    β”‚                                             β”‚
    β”œβ”€β”€β–Ί Vibe Coding Detector ──► Result 4       β”‚
    β”‚                                             β”‚
    └──► Unsupported Claims Detector ──► Result 5β”‚
                                                  β”‚
    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
    β”‚
    β–Ό
Risk Calculation
    β”‚
    β”œβ”€β–Ί Weight results
    β”œβ”€β–Ί Calculate score
    └─► Map to risk level
        β”‚
        β–Ό
Intervention Recommendation
    β”‚
    β”œβ”€β–Ί Step breakdown?
    β”œβ”€β–Ί Human-in-loop?
    β”œβ”€β–Ί Web search?
    └─► Simplified scope?
        β”‚
        β–Ό
Format Response (Markdown/JSON)
    β”‚
    └──► Return to Client

Detection Pipeline

Input Text
    β”‚
    β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Preprocessing           β”‚
β”‚   - Lowercase             β”‚
β”‚   - Strip whitespace      β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
            β”‚
            β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Pattern Matching        β”‚
β”‚   - Regex patterns        β”‚
β”‚   - Keyword detection     β”‚
β”‚   - Structural analysis   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
            β”‚
            β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Confidence Scoring      β”‚
β”‚   - Count matches         β”‚
β”‚   - Weight by type        β”‚
β”‚   - Normalize to [0,1]    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
            β”‚
            β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Context Checks          β”‚
β”‚   - has_sources?          β”‚
β”‚   - has_hedging?          β”‚
β”‚   - has_safeguards?       β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
            β”‚
            β–Ό
Detection Result
{
  detected: bool,
  categories: list,
  confidence: float,
  metadata: dict
}

Risk Calculation Algorithm

For each detection category:
    
    Math/Physics:
        risk += confidence Γ— 0.5
    
    Medical Advice:
        risk += confidence Γ— 1.5  # Highest weight
    
    File Operations:
        risk += confidence Γ— 2.0  # Critical actions
    
    Vibe Coding:
        risk += confidence Γ— 0.4
    
    Unsupported Claims:
        risk += confidence Γ— 0.3

Total Risk Score:
    
    β‰₯ 1.5 β†’ CRITICAL
    β‰₯ 1.0 β†’ HIGH
    β‰₯ 0.5 β†’ MODERATE
    < 0.5 β†’ LOW

Intervention Decision Tree

                    Detection Results
                          β”‚
        β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
        β”‚                 β”‚                 β”‚
        β–Ό                 β–Ό                 β–Ό
  Math/Physics?     Medical Advice?   File Operations?
        β”‚                 β”‚                 β”‚
        β”œβ”€β–Ί Yes           β”œβ”€β–Ί Yes           β”œβ”€β–Ί Yes
        β”‚   β”‚             β”‚   β”‚             β”‚   β”‚
        β”‚   β”œβ”€β–Ί Step      β”‚   β”œβ”€β–Ί Human    β”‚   β”œβ”€β–Ί Human
        β”‚   β”‚   Breakdown β”‚   β”‚   in Loop   β”‚   β”‚   in Loop
        β”‚   β”‚             β”‚   β”‚             β”‚   β”‚
        β”‚   └─► Web       β”‚   └─► Web       β”‚   └─► Step
        β”‚       Search    β”‚       Search    β”‚       Breakdown
        β”‚                 β”‚                 β”‚
        └─► No            └─► No            └─► No
            β”‚                 β”‚                 β”‚
            β–Ό                 β–Ό                 β–Ό
      Continue          Continue          Continue

                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                    β”‚  Combine  β”‚
                    β”‚  Results  β”‚
                    β””β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜
                          β”‚
                          β–Ό
              Intervention List
              (deduplicated)

Taxonomy Database Schema

TAXONOMY_DB = {
    "category_name": [
        {
            "id": "abc123def456",
            "category": "math_physics_speculation",
            "prompt": "User's prompt text...",
            "response": "LLM's response text...",
            "description": "Why problematic...",
            "severity": "high",
            "timestamp": "2025-10-18T00:00:00",
            "prompt_hash": "a1b2c3d4"
        },
        { ... more entries ... }
    ],
    "another_category": [ ... ]
}

Indices:
- By category (dict key)
- By severity (filter)
- By timestamp (sort)
- By hash (deduplication)

Component Responsibilities

MCP Tools Layer

Responsibilities:

  • Input validation (Pydantic models)
  • Parameter extraction
  • Tool orchestration
  • Response formatting
  • Character limit enforcement

Does NOT:

  • Perform detection logic
  • Calculate risk scores
  • Store data directly

Detection Heuristics Layer

Responsibilities:

  • Pattern matching
  • Confidence scoring
  • Context analysis
  • Detection result generation

Does NOT:

  • Make intervention decisions
  • Format responses
  • Handle I/O

Risk Assessment Layer

Responsibilities:

  • Aggregate detection results
  • Calculate weighted risk scores
  • Map scores to risk levels
  • Generate intervention recommendations

Does NOT:

  • Perform detection
  • Format responses
  • Store data

Taxonomy Database

Responsibilities:

  • Store evidence entries
  • Support filtering/pagination
  • Provide statistics
  • Maintain capacity limits

Does NOT:

  • Perform analysis
  • Make decisions
  • Format responses

Extension Points

Adding New Detection Categories

# 1. Add enum value
class CategoryType(str, Enum):
    NEW_CATEGORY = "new_category"

# 2. Create detector function
def detect_new_category(text: str) -> Dict[str, Any]:
    patterns = { ... }
    # Detection logic
    return {
        'detected': bool,
        'categories': list,
        'confidence': float
    }

# 3. Update analysis functions
def analyze_prompt(params):
    results['new_category'] = detect_new_category(params.prompt)
    # ... rest of logic

# 4. Update risk calculation
def calculate_risk_level(results):
    if results['new_category']['detected']:
        risk_score += results['new_category']['confidence'] * WEIGHT

# 5. Add intervention logic
def recommend_interventions(results):
    if results['new_category']['detected']:
        interventions.append({ ... })

Adding Persistent Storage

# 1. Define storage backend
class TaxonomyStorage:
    def save(self, category, entry): ...
    def load(self, category, filters): ...
    def get_stats(self): ...

# 2. Replace in-memory dict
storage = TaxonomyStorage(backend="sqlite")  # or "postgres", "mongodb"

# 3. Update tool functions
@mcp.tool()
async def submit_evidence(params):
    # Instead of: TAXONOMY_DB[category].append(entry)
    await storage.save(params.category, entry)

Adding ML Models

# 1. Define model interface
class AnomalyDetector:
    def fit(self, X): ...
    def predict(self, x) -> float: ...

# 2. Train from taxonomy
detector = AnomalyDetector()
training_data = get_training_data_from_taxonomy()
detector.fit(training_data)

# 3. Use in detection
def detect_with_ml(text: str) -> float:
    features = extract_features(text)
    anomaly_score = detector.predict(features)
    return anomaly_score

Performance Characteristics

Time Complexity

  • Pattern Matching: O(n) where n = text length
  • All Detectors: O(n) (parallel constant time)
  • Risk Calculation: O(1) (fixed number of categories)
  • Taxonomy Query: O(mΒ·log m) where m = matching entries
  • Overall: O(n + mΒ·log m)

Space Complexity

  • Server Base: ~50 MB
  • Per Request: ~1 KB (temporary)
  • Per Taxonomy Entry: ~1 KB
  • Total with 1000 entries: ~51 MB

Latency

  • Single Detection: ~10-50 ms
  • All Detections: ~50-100 ms
  • Format Response: ~1-10 ms
  • Total Per Request: ~100-150 ms

Security Considerations

Input Validation

User Input
    β”‚
    β–Ό
Pydantic Model
    β”‚
    β”œβ”€β–Ί Type checking
    β”œβ”€β–Ί Length limits
    β”œβ”€β–Ί Pattern validation
    └─► Field constraints
        β”‚
        β–Ό
    Valid Input

Privacy Protection

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  NO External API Calls             β”‚
β”‚  NO Data Transmission              β”‚
β”‚  NO Logging Sensitive Info         β”‚
β”‚  YES Local Processing Only         β”‚
β”‚  YES User Consent Required         β”‚
β”‚  YES Data Stays on Device          β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Human-in-the-Loop

Sensitive Operation Detected
    β”‚
    β–Ό
Request User Confirmation
    β”‚
    β”œβ”€β–Ί Yes β†’ Proceed
    β”‚
    └─► No β†’ Cancel

Scalability Path

Current: Single Instance

Client β†’ stdio β†’ ToGMAL Server β†’ Response

Future: HTTP Transport

Multiple Clients β†’ HTTP β†’ ToGMAL Server β†’ Response
                          ↓
                    Shared Database

Advanced: Distributed

Clients β†’ Load Balancer β†’ ToGMAL Servers (N)
                              ↓
                        Shared Database
                              ↓
                        ML Model Cache

Monitoring Points

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Metrics to Track                   β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚  - Tool call frequency              β”‚
β”‚  - Detection rates by category      β”‚
β”‚  - Risk level distribution          β”‚
β”‚  - Intervention effectiveness       β”‚
β”‚  - False positive rate              β”‚
β”‚  - Response latency                 β”‚
β”‚  - Taxonomy growth rate             β”‚
β”‚  - User feedback submissions        β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

This architecture supports:

  • βœ… Privacy-preserving analysis
  • βœ… Low-latency detection
  • βœ… Extensible design
  • βœ… Production readiness
  • βœ… Future ML integration