# aianytime/ai-agents-from-scratch-using-ollama architecture

> Architecture diagram of the GitHub repository aianytime/ai-agents-from-scratch-using-ollama, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-10). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/aianytime/ai-agents-from-scratch-using-ollama
- Repository: https://github.com/aianytime/ai-agents-from-scratch-using-ollama

## Overview

##### Project Type and Purpose
- This is a Python-based multi-agent system designed to work as a full-stack application with a web-based user interface (using Streamlit). Its purpose is to process and transform medical data by summarizing texts, generating and refining research articles, and sanitizing PHI from datasets. The project leverages the LLaMA 3.2:3b model via Ollama and incorporates dedicated validator agents to ensure overall quality.

##### Analyzing the File Structure
- Notice the top-level files like app.py (which serves as the entry point for the Streamlit web application) and test.py.
- The “agents” directory contains the various agent implementations including:
- Main agents (e.g., agent_base.py, summarize_tool.py, write_article_tool.py, sanitize_data_tool.py) that process the core tasks.
- Validator agents (e.g., sanitize_data_validator_agent.py, summarize_validator_agent.py, write_article_validator_agent.py, and also refiner_agent.py which supports drafting refinements).
- The “utils” directory houses support utilities such as logger.py for managing robust logging.
- Presence of the requirements.txt file indicates dependencies management and the existence of the LICENSE and README files provide context and instructions.

##### Extracting Insights from the README
- The README explicitly outlines a layered architecture. It starts with the User interacting through a Streamlit app, which delegates tasks to an “Agent Manager” that then routes tasks to three main processing modules (summarizing, writing, and sanitizing) along with their paired validator agents.
- It also hints at comprehensive logging via a dedicated Logger component managed by the loguru library.

a. Main Components to Include:
- User – Represents the external end-user.
- Streamlit Web App – The frontend interface that captures user interactions and displays the outcomes.
- Agent Manager – A central coordinator (likely within app.py) that handles task routing.
- Main Agents – Three distinct components:
- Summarize Agent (for generating summaries).
- Write Article Agent (for drafting articles).
- Sanitize Data Agent (for PHI removal).
- Validator Agents – Associated with each main agent:
- Summarize Validator Agent.
- Refiner Agent (for article enhancement).
- Sanitize Validator Agent.
- Logger – A dedicated logging component (implemented in utils/logger.py) that records system events.

b. Relationships and Interactions:
- User interacts with the Streamlit app.
- The Streamlit app passes requests to the Agent Manager.
- The Agent Manager distributes tasks to the appropriate main agent.
- Each main agent’s output is validated by its corresponding validator agent.
- Both processing pipelines report outcomes and errors to the Logger.

c. Architectural Patterns and Design Principles:
- Modular Design: Separate agents encapsulate distinct functionalities. This promotes separation of concerns.
- Microservice-like Interaction within a Single Process: Although all agents reside within the same codebase, think of them as distinct “services” that communicate serially.
- Validation Pipeline: Each major processing unit has a paired validator to ensure quality – an important quality assurance mechanism.
- Logging and Monitoring as a Cross-Cutting Concern.

d. Relevant Technologies:
- Python – The primary language.
- Streamlit – For building the interactive web UI.
- Ollama & LLaMA 3.2:3b model – Underlying AI model integration.
- loguru – For robust logging.

##### Final Assembly
- Keep the design clean and readable for stakeholders like fellow engineers who need a clear view of data flow and system composition.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Global Entities
    U["User"]:::frontend

    %% Frontend
    SAAM["Streamlit App & Agent Manager (Streamlit, Python)"]:::frontend

    %% Main Agents Subgraph
    subgraph "Main Agents"
        SM["Summarize Agent"]:::backend
        WA["Write Article Agent"]:::backend
        SD["Sanitize Data Agent"]:::backend
    end

    %% Validator Agents Subgraph
    subgraph "Validator Agents"
        SV["Summarize Validator Agent"]:::validator
        WV["Write Article Validator Agent"]:::validator
        RF["Refiner Agent"]:::validator
        DV["Sanitize Validator Agent"]:::validator
    end

    %% Logger Component
    LG["Logger (loguru)"]:::logger

    %% Connections
    U -->|"interacts"| SAAM
    SAAM -->|"routesTo"| SM
    SAAM -->|"routesTo"| WA
    SAAM -->|"routesTo"| SD

    SM -->|"validates"| SV
    WA -->|"validates"| WV
    WA -->|"enhances"| RF
    SD -->|"validates"| DV

    SM -->|"logs"| LG
    WA -->|"logs"| LG
    SD -->|"logs"| LG
    SV -->|"logs"| LG
    WV -->|"logs"| LG
    RF -->|"logs"| LG
    DV -->|"logs"| LG

    %% Click Events
    click SAAM "https://github.com/aianytime/ai-agents-from-scratch-using-ollama/blob/main/app.py"
    click SM "https://github.com/aianytime/ai-agents-from-scratch-using-ollama/blob/main/agents/summarize_tool.py"
    click WA "https://github.com/aianytime/ai-agents-from-scratch-using-ollama/blob/main/agents/write_article_tool.py"
    click SD "https://github.com/aianytime/ai-agents-from-scratch-using-ollama/blob/main/agents/sanitize_data_tool.py"
    click SV "https://github.com/aianytime/ai-agents-from-scratch-using-ollama/blob/main/agents/summarize_validator_agent.py"
    click WV "https://github.com/aianytime/ai-agents-from-scratch-using-ollama/blob/main/agents/write_article_validator_agent.py"
    click DV "https://github.com/aianytime/ai-agents-from-scratch-using-ollama/blob/main/agents/sanitize_data_validator_agent.py"
    click RF "https://github.com/aianytime/ai-agents-from-scratch-using-ollama/blob/main/agents/refiner_agent.py"
    click LG "https://github.com/aianytime/ai-agents-from-scratch-using-ollama/blob/main/utils/logger.py"

    %% Styles
    classDef frontend fill:#ffcc00,stroke:#333,stroke-width:2px;
    classDef backend fill:#99ccff,stroke:#333,stroke-width:2px;
    classDef validator fill:#aaffaa,stroke:#333,stroke-width:2px;
    classDef logger fill:#ff9999,stroke:#333,stroke-width:2px;
```
