# fareedkhan-dev/autonomous-agentic-rag architecture

> Architecture diagram of the GitHub repository fareedkhan-dev/autonomous-agentic-rag, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-11-17). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/fareedkhan-dev/autonomous-agentic-rag
- Repository: https://github.com/fareedkhan-dev/autonomous-agentic-rag

## Overview

##### Project Type and Purpose
- This is a research‐prototype Jupyter Notebook implementing a self-improving, agentic RAG (Retrieval-Augmented Generation) pipeline for clinical trial design.
- It orchestrates multiple LLM roles (planner, researcher, SQL coder, director), builds vector stores, runs a multi-agent “Guild,” evaluates outputs on five dimensions, and evolves its own SOP (Standard Operating Procedure).

##### File Structure Analysis
- Top-level:
- LICENSE
- README.md (detailed tutorial and architecture description)
- code.ipynb (the implementation in notebook form)
- No separate “src” or “frontend/backend” directories – everything lives in the notebook, but logically the notebook contains modules for:
- Environment & config (.env, API keys)
- LLM model registry (“foundry” via Ollama)
- Knowledge ingestion (PubMed, FDA PDF, ethics text, MIMIC-III → DuckDB)
- Vector store creation (FAISS + Embeddings)
- Inner-loop RAG graph (LangGraph)
- Multi-dimensional evaluation suite
- Outer-loop evolution engine (diagnostician, architect, gene pool)

##### Key Architecture Components
A. Knowledge Infrastructure
- Data sources: PubMed abstracts, FDA guidelines (PDF→text), ethics summary (text), MIMIC-III CSVs → DuckDB.
- Vector stores: FAISS indexes for unstructured text (PubMed, FDA, ethics).
- Database: DuckDB file for structured clinical data.
B. Model Registry (“LLM Foundry”)
- Ollama clients for different model roles: planner (Llama 8B–json), drafter (Qwen 7B), SQL coder (Qwen 7B), director (Llama 70B–json), embedding model.
C. Inner-Loop Agentic Workflow (LangGraph)
1. Planner Agent: high-level JSON plan → tasks for specialists
2. Specialist Agents (parallelizable):
- Regulatory Specialist (FDA retriever)
- Medical Researcher (PubMed retriever)
- Ethics Specialist (ethics retriever)
- Patient Cohort Analyst (Text→SQL → DuckDB query)
3. Criteria Synthesizer: collates all agent outputs → final inclusion/exclusion document
D. Evaluation Gauntlet
- LLM-as-judge evaluators (director model) for Scientific Rigor, Regulatory Compliance, Ethical Soundness
- Programmatic evaluators for Recruitment Feasibility (SQL count normalized) and Operational Simplicity (keyword penalty)
- Aggregator: produces 5-dimensional score vector
E. Outer-Loop Evolution Engine
1. GenePool: stores SOP versions + their evaluation vectors + lineage
2. Performance Diagnostician: identifies primary weakness from 5D vector → structured Diagnosis
3. SOP Architect: mutates current SOP (prompts, flags, retriever k, model choices) → 2–3 candidate SOPs
4. Loop: each candidate runs inner-loop + evaluation → added to GenePool

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Knowledge Layer"
        INGEST["Knowledge Ingestion"]:::data
        PUB["PubMed Store (unstructured)"]:::data
        FDA["FDA Store (unstructured)"]:::data
        ETH["Ethics Store (unstructured)"]:::data
        DB["DuckDB Clinical DB"]:::data
    end

    INGEST --> PUB
    INGEST --> FDA
    INGEST --> ETH
    INGEST --> DB

    VECTOR["Vector Store Service (FAISS + Embeddings)"]:::data
    PUB --> VECTOR
    FDA --> VECTOR
    ETH --> VECTOR

    subgraph "Model Layer"
        FOUNDRY["LLM Foundry (Ollama Client)"]:::model
    end

    VECTOR --> FOUNDRY

    subgraph "Processing Layer"
        subgraph "Agentic Pipeline"
            PLAN["Planner Agent"]:::pipeline
            subgraph "Specialist Agents"
                REG["Regulatory Specialist"]:::pipeline
                MED["Medical Researcher"]:::pipeline
                ETHAG["Ethics Specialist"]:::pipeline
                PAT["Patient Cohort Analyst"]:::pipeline
            end
            SYN["Criteria Synthesizer"]:::pipeline
        end
    end

    FOUNDRY --> PLAN
    PLAN -->|"TASK PLAN"| REG
    PLAN -->|"TASK PLAN"| MED
    PLAN -->|"TASK PLAN"| ETHAG
    PLAN -->|"TASK PLAN"| PAT
    REG --> SYN
    MED --> SYN
    ETHAG --> SYN
    PAT --> SYN

    subgraph "Evaluation Layer"
        EVAL["Evaluation Gauntlet"]:::evaluation
    end

    SYN -->|"Final Document"| EVAL

    subgraph "Evolution Layer"
        DIAG["Performance Diagnostician"]:::evolution
        ARCH["SOP Architect"]:::evolution
        GENE["GenePool (SOP Versions)"]:::evolution
    end

    EVAL -->|"5D Scores"| DIAG
    DIAG -->|"Diagnosis"| ARCH
    ARCH -->|"New SOPs"| PLAN
    ARCH --> GENE
    GENE --> DIAG

    click INGEST "https://github.com/fareedkhan-dev/autonomous-agentic-rag/blob/main/code.ipynb"
    click VECTOR "https://github.com/fareedkhan-dev/autonomous-agentic-rag/blob/main/code.ipynb"
    click DB "https://github.com/fareedkhan-dev/autonomous-agentic-rag/blob/main/code.ipynb"
    click FOUNDRY "https://github.com/fareedkhan-dev/autonomous-agentic-rag/blob/main/code.ipynb"
    click PLAN "https://github.com/fareedkhan-dev/autonomous-agentic-rag/blob/main/code.ipynb"
    click EVAL "https://github.com/fareedkhan-dev/autonomous-agentic-rag/blob/main/code.ipynb"
    click DIAG "https://github.com/fareedkhan-dev/autonomous-agentic-rag/blob/main/code.ipynb"

    classDef data fill:#a8ddb5,stroke:#00441b,color:#000;
    classDef model fill:#9e9ac8,stroke:#3f007d,color:#fff;
    classDef pipeline fill:#2b8cbe,stroke:#08519c,color:#fff;
    classDef evaluation fill:#fdae6b,stroke:#e6550d,color:#000;
    classDef evolution fill:#fc9272,stroke:#de2d26,color:#000;
```
