# samiullah07/fyp-llm architecture

> Architecture diagram of the GitHub repository samiullah07/fyp-llm, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-16). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/samiullah07/fyp-llm
- Repository: https://github.com/samiullah07/fyp-llm

## Overview

1. This repository is a Python system for multi-agent, retrieval-augmented literature analysis. The core runtime is not a generic web app; it is centered on an orchestration pipeline that searches a paper corpus, drafts content, verifies claims, and assembles final outputs.

2. The primary execution layer appears in `agents/`:
   - `planner_agent.py` decides what to do next.
   - `search_agent.py` retrieves supporting material.
   - `summariser_agent.py` condenses retrieved evidence.
   - `verifier_agent.py` checks factual consistency or citation quality.
   - `assembler_agent.py` combines intermediate outputs into the final response.
   This is the main “brain” of the system and is the most important boundary for an architecture diagram.

3. Workflow composition is separated from the agents themselves in `graph/`:
   - `workflow_graph.py` likely defines the end-to-end agent workflow.
   - `baseline_graph.py` likely encodes a simpler comparison pipeline.
   This suggests the project compares different orchestration strategies rather than only serving one fixed flow.

4. The retrieval and data-access core lives in `src/`:
   - `document_reader.py` handles source document ingestion/parsing.
   - `retrieval.py` performs search over indexed content.
   - `models.py` holds shared domain structures.
   - `api_clients.py` abstracts calls to external model or service APIs.
   - `mab_selector.py` implements a multi-armed bandit selector for choosing strategies.
   - `config.py` centralizes runtime configuration.
   This package is the main boundary between orchestration logic and the underlying knowledge/retrieval layer.

5. Corpus creation and indexing are explicitly versioned under `data/corpus/` and `data/processed/`:
   - `data/corpus/builder.py` builds corpus artifacts.
   - `corpus_*.json` and `corpus_combined.json` are prepared knowledge sources.
   - `data/processed/papers_index.faiss` and `papers_index.pkl` indicate a local FAISS vector index plus metadata.
   The system therefore uses an offline preprocessing step to build a searchable corpus, then serves retrieval from the precomputed index at runtime.

6. `tools/` contains external-data and vector infrastructure helpers:
   - `openalex_client.py` suggests integration with the OpenAlex scholarly metadata API.
   - `vector_store.py` likely wraps vector indexing/search operations.
   These are support modules for populating and querying the literature corpus, not the main orchestration path.

7. Evaluation is a major first-class subsystem in `evaluation/`:
   - `evaluator.py`, `metrics.py`, and `cost_tracker.py` measure quality and cost.
   - `baseline.py` compares against baseline behavior.
   - `ablation_study.py` runs variant comparisons.
   - `annotation_tool.ipynb` and the kappa/statistics tests indicate manual labeling and inter-annotator agreement analysis.
   This repo is built not only to run the agent pipeline, but also to experimentally measure it.

8. The `data/eval/` tree stores experiment outputs, logs, and reports:
   - result CSV/JSON files for evaluations and MAB runs.
   - baseline and experimental text outputs.
   - verifier and assembler logs.
   - statistical summaries and annotation artifacts.
   For an architecture diagram, this is the persistence layer for experiments and traceability, not user content storage.

9. The top-level entrypoints suggest multiple ways to run or demo the system:
   - `main.py` is likely the primary CLI or orchestration entrypoint.
   - `app.py` and `demo_app.py` are likely UI-facing launch points.
   - `app_styles.py` supports the presentation layer.
   The repository therefore has a separation between core agent execution and a lightweight front-end/demo layer.

10. `configs/` and `config.py` indicate prompt- and runtime-configuration management:
   - `configs/prompts.py` centralizes LLM prompts or agent instructions.
   This is important because the behavior of planner/search/summarizer/verifier agents is driven by prompt configuration rather than hardcoded logic alone.

11. `utils/logger.py` and the extensive logs under `data/eval/logs/` and `data/eval/verifier_logs/` show that observability is built into the workflow. The system records intermediate agent behavior, which supports debugging, reproducibility, and evaluation.

12. In terms of data flow, the likely high-level path is:
   curated papers and metadata -> corpus builder -> FAISS index -> retrieval/search agent -> summarization and verification agents -> assembler -> evaluation/logging.
   The alternate path is the baseline workflow, which is kept separate for comparison experiments.

13. The repository is organized more like an experimental agentic research platform than a production service. The most important architectural boundaries are:
   - orchestration vs retrieval/indexing,
   - runtime inference vs offline corpus building,
   - experimental evaluation vs baseline comparison,
   - core logic vs UI/demo entrypoints.

14. Tests in `test_evaluation.py`, `test_kappa.py`, `test_mab.py`, `test_mab_quick.py`, and `test_statistics.py` reinforce that the project’s main technical concerns are experimental correctness, selection strategy behavior, and evaluation methodology rather than generic application CRUD or serving.

Main entry points: [`graph/workflow_graph.py`](https://github.com/samiullah07/fyp-llm/blob/main/graph/workflow_graph.py) (Workflow graph), [`agents/search_agent.py`](https://github.com/samiullah07/fyp-llm/blob/main/agents/search_agent.py) (Search), [`configs/prompts.py`](https://github.com/samiullah07/fyp-llm/blob/main/configs/prompts.py) (Prompts), [`evaluation/evaluator.py`](https://github.com/samiullah07/fyp-llm/blob/main/evaluation/evaluator.py) (Evaluator)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_group_runtime["Runtime agents"]
  node_node_planner(("Planner<br/>agent<br/>[planner_agent.py]"))
  node_node_search(("Search<br/>agent<br/>[search_agent.py]"))
  node_node_summariser(("Summariser<br/>agent"))
  node_node_verifier(("Verifier<br/>agent<br/>[verifier_agent.py]"))
  node_node_assembler(("Assembler<br/>agent<br/>[assembler_agent.py]"))
end

subgraph group_group_workflow["Workflow graphs"]
  node_node_workflow_graph["Workflow graph<br/>orchestration graph<br/>[workflow_graph.py]"]
  node_node_baseline_graph["Baseline graph<br/>comparison graph<br/>[baseline_graph.py]"]
end

subgraph group_group_knowledge["Retrieval stack"]
  node_node_document_reader["Reader<br/>ingestion<br/>[document_reader.py]"]
  node_node_retrieval["Retrieval<br/>search<br/>[retrieval.py]"]
  node_node_models["Models<br/>domain schema<br/>[models.py]"]
  node_node_api_clients["API clients<br/>integration<br/>[api_clients.py]"]
  node_node_mab_selector{{"MAB selector<br/>strategy selection<br/>[mab_selector.py]"}}
  node_node_config["Runtime config<br/>configuration<br/>[config.py]"]
  node_node_prompts["Prompts<br/>prompt config<br/>[prompts.py]"]
  node_node_corpus_builder["Corpus builder<br/>offline pipeline<br/>[builder.py]"]
  node_node_faiss_index[("FAISS index<br/>vector index<br/>[papers_index.faiss]")]
  node_node_openalex["OpenAlex client<br/>external metadata<br/>[openalex_client.py]"]
  node_node_vector_store[("Vector store<br/>index wrapper<br/>[vector_store.py]")]
  node_node_logger["Logger<br/>observability<br/>[logger.py]"]
end

subgraph group_group_eval["Evaluation"]
  node_node_evaluator["Evaluator<br/>evaluation<br/>[evaluator.py]"]
  node_node_metrics["Metrics<br/>scoring<br/>[metrics.py]"]
  node_node_cost_tracker["Cost tracker<br/>observability<br/>[cost_tracker.py]"]
  node_node_baseline_eval["Baseline eval<br/>comparison<br/>[baseline.py]"]
  node_node_ablation["Ablation study<br/>experiment<br/>[ablation_study.py]"]
  node_node_data_eval[("Eval artifacts<br/>results store")]
end

subgraph group_group_entry["Entrypoints"]
  node_node_main["Main CLI<br/>entrypoint<br/>[main.py]"]
  node_node_app["App<br/>ui entrypoint<br/>[app.py]"]
  node_node_demo_app["Demo app<br/>demo entrypoint<br/>[demo_app.py]"]
  node_node_styles["Styles<br/>presentation<br/>[app_styles.py]"]
end

node_node_workflow_graph -->|"orchestrates"| node_node_planner
node_node_workflow_graph -->|"routes to"| node_node_search
node_node_workflow_graph -->|"routes to"| node_node_summariser
node_node_workflow_graph -->|"routes to"| node_node_verifier
node_node_workflow_graph -->|"routes to"| node_node_assembler
node_node_baseline_graph -->|"uses"| node_node_search
node_node_baseline_graph -->|"finishes with"| node_node_assembler
node_node_document_reader -->|"feeds"| node_node_corpus_builder
node_node_openalex -->|"enriches"| node_node_corpus_builder
node_node_corpus_builder -->|"indexes"| node_node_vector_store
node_node_vector_store -->|"persists"| node_node_faiss_index
node_node_faiss_index -->|"powers"| node_node_retrieval
node_node_retrieval -->|"serves"| node_node_search
node_node_prompts -->|"guides"| node_node_planner
node_node_prompts -->|"guides"| node_node_search
node_node_prompts -->|"guides"| node_node_summariser
node_node_prompts -->|"guides"| node_node_verifier
node_node_api_clients -->|"connects"| node_node_planner
node_node_config -->|"configures"| node_node_workflow_graph
node_node_config -->|"configures"| node_node_mab_selector
node_node_mab_selector -->|"adapts"| node_node_workflow_graph
node_node_evaluator -->|"computes"| node_node_metrics
node_node_evaluator -->|"tracks"| node_node_cost_tracker
node_node_baseline_eval -->|"writes"| node_node_data_eval
node_node_ablation -->|"writes"| node_node_data_eval
node_node_evaluator -->|"stores"| node_node_data_eval
node_node_logger -->|"logs"| node_node_data_eval
node_node_main -->|"runs"| node_node_workflow_graph
node_node_app -->|"launches"| node_node_workflow_graph
node_node_demo_app -->|"reuses"| node_node_app
node_node_app -->|"uses"| node_node_styles
node_node_main -->|"invokes"| node_node_evaluator
node_node_search -->|"reads/writes"| node_node_models
node_node_assembler -->|"emits"| node_node_logger
node_node_verifier -->|"emits"| node_node_logger

click node_node_planner "https://github.com/samiullah07/fyp-llm/blob/main/agents/planner_agent.py"
click node_node_search "https://github.com/samiullah07/fyp-llm/blob/main/agents/search_agent.py"
click node_node_summariser "https://github.com/samiullah07/fyp-llm/blob/main/agents/summariser_agent.py"
click node_node_verifier "https://github.com/samiullah07/fyp-llm/blob/main/agents/verifier_agent.py"
click node_node_assembler "https://github.com/samiullah07/fyp-llm/blob/main/agents/assembler_agent.py"
click node_node_workflow_graph "https://github.com/samiullah07/fyp-llm/blob/main/graph/workflow_graph.py"
click node_node_baseline_graph "https://github.com/samiullah07/fyp-llm/blob/main/graph/baseline_graph.py"
click node_node_document_reader "https://github.com/samiullah07/fyp-llm/blob/main/src/document_reader.py"
click node_node_retrieval "https://github.com/samiullah07/fyp-llm/blob/main/src/retrieval.py"
click node_node_models "https://github.com/samiullah07/fyp-llm/blob/main/src/models.py"
click node_node_api_clients "https://github.com/samiullah07/fyp-llm/blob/main/src/api_clients.py"
click node_node_mab_selector "https://github.com/samiullah07/fyp-llm/blob/main/src/mab_selector.py"
click node_node_config "https://github.com/samiullah07/fyp-llm/blob/main/src/config.py"
click node_node_prompts "https://github.com/samiullah07/fyp-llm/blob/main/configs/prompts.py"
click node_node_corpus_builder "https://github.com/samiullah07/fyp-llm/blob/main/data/corpus/builder.py"
click node_node_faiss_index "https://github.com/samiullah07/fyp-llm/blob/main/data/processed/papers_index.faiss"
click node_node_openalex "https://github.com/samiullah07/fyp-llm/blob/main/tools/openalex_client.py"
click node_node_vector_store "https://github.com/samiullah07/fyp-llm/blob/main/tools/vector_store.py"
click node_node_evaluator "https://github.com/samiullah07/fyp-llm/blob/main/evaluation/evaluator.py"
click node_node_metrics "https://github.com/samiullah07/fyp-llm/blob/main/evaluation/metrics.py"
click node_node_cost_tracker "https://github.com/samiullah07/fyp-llm/blob/main/evaluation/cost_tracker.py"
click node_node_baseline_eval "https://github.com/samiullah07/fyp-llm/blob/main/evaluation/baseline.py"
click node_node_ablation "https://github.com/samiullah07/fyp-llm/blob/main/evaluation/ablation_study.py"
click node_node_data_eval "https://github.com/samiullah07/fyp-llm/tree/main/data/eval"
click node_node_main "https://github.com/samiullah07/fyp-llm/blob/main/main.py"
click node_node_app "https://github.com/samiullah07/fyp-llm/blob/main/app.py"
click node_node_demo_app "https://github.com/samiullah07/fyp-llm/blob/main/demo_app.py"
click node_node_styles "https://github.com/samiullah07/fyp-llm/blob/main/app_styles.py"
click node_node_logger "https://github.com/samiullah07/fyp-llm/blob/main/utils/logger.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_node_planner,node_node_search,node_node_summariser,node_node_verifier,node_node_assembler toneBlue
class node_node_workflow_graph,node_node_baseline_graph toneAmber
class node_node_document_reader,node_node_retrieval,node_node_models,node_node_api_clients,node_node_mab_selector,node_node_config,node_node_prompts,node_node_corpus_builder,node_node_faiss_index,node_node_openalex,node_node_vector_store,node_node_logger toneMint
class node_node_evaluator,node_node_metrics,node_node_cost_tracker,node_node_baseline_eval,node_node_ablation,node_node_data_eval toneRose
class node_node_main,node_node_app,node_node_demo_app,node_node_styles toneIndigo
```

## Components

### Runtime agents

Core multi-agent execution path for literature analysis.

- [Planner](https://github.com/samiullah07/fyp-llm/blob/main/agents/planner_agent.py): agent · Decides the next action in the agent loop. · `agents/planner_agent.py`
- [Search](https://github.com/samiullah07/fyp-llm/blob/main/agents/search_agent.py): agent · Retrieves supporting evidence from the corpus. · `agents/search_agent.py`
- [Summariser](https://github.com/samiullah07/fyp-llm/blob/main/agents/summariser_agent.py): agent · Condenses retrieved evidence into usable summaries. · `agents/summariser_agent.py`
- [Verifier](https://github.com/samiullah07/fyp-llm/blob/main/agents/verifier_agent.py): agent · Checks factual consistency and citation quality. · `agents/verifier_agent.py`
- [Assembler](https://github.com/samiullah07/fyp-llm/blob/main/agents/assembler_agent.py): agent · Combines intermediate outputs into a final response. · `agents/assembler_agent.py`

### Workflow graphs

Composition layer that wires agents into end-to-end flows.

- [Workflow graph](https://github.com/samiullah07/fyp-llm/blob/main/graph/workflow_graph.py): orchestration graph · Defines the main multi-agent workflow. · `graph/workflow_graph.py`
- [Baseline graph](https://github.com/samiullah07/fyp-llm/blob/main/graph/baseline_graph.py): comparison graph · Defines a simpler reference pipeline for experiments. · `graph/baseline_graph.py`

### Retrieval stack

Corpus building, indexing, retrieval, and shared domain/data support.

- [Reader](https://github.com/samiullah07/fyp-llm/blob/main/src/document_reader.py): ingestion · Parses and ingests source documents. · `src/document_reader.py`
- [Retrieval](https://github.com/samiullah07/fyp-llm/blob/main/src/retrieval.py): search · Searches indexed content for supporting material. · `src/retrieval.py`
- [Models](https://github.com/samiullah07/fyp-llm/blob/main/src/models.py): domain schema · Shared domain objects used across the system. · `src/models.py`
- [API clients](https://github.com/samiullah07/fyp-llm/blob/main/src/api_clients.py): integration · Wraps external model and service API calls. · `src/api_clients.py`
- [MAB selector](https://github.com/samiullah07/fyp-llm/blob/main/src/mab_selector.py): strategy selection · Chooses among strategies using a multi-armed bandit. · `src/mab_selector.py`
- [Runtime config](https://github.com/samiullah07/fyp-llm/blob/main/src/config.py): configuration · Centralizes runtime settings and environment-driven behavior. · `src/config.py`
- [Prompts](https://github.com/samiullah07/fyp-llm/blob/main/configs/prompts.py): prompt config · Central prompt and instruction templates for agents. · `configs/prompts.py`
- [Corpus builder](https://github.com/samiullah07/fyp-llm/blob/main/data/corpus/builder.py): offline pipeline · Builds corpus artifacts from curated papers and metadata. · `data/corpus/builder.py`
- [FAISS index](https://github.com/samiullah07/fyp-llm/blob/main/data/processed/papers_index.faiss): vector index · Precomputed local vector index for retrieval. · `data/processed/papers_index.faiss`
- [OpenAlex client](https://github.com/samiullah07/fyp-llm/blob/main/tools/openalex_client.py): external metadata · Fetches scholarly metadata for corpus population. · `tools/openalex_client.py`
- [Vector store](https://github.com/samiullah07/fyp-llm/blob/main/tools/vector_store.py): index wrapper · Handles vector indexing and lookup support. · `tools/vector_store.py`
- [Logger](https://github.com/samiullah07/fyp-llm/blob/main/utils/logger.py): observability · Shared logging utilities used across runtime and evaluation. · `utils/logger.py`

### Evaluation

Experimentation, metrics, baselines, and persisted run artifacts.

- [Evaluator](https://github.com/samiullah07/fyp-llm/blob/main/evaluation/evaluator.py): evaluation · Runs quality evaluation over outputs and runs. · `evaluation/evaluator.py`
- [Metrics](https://github.com/samiullah07/fyp-llm/blob/main/evaluation/metrics.py): scoring · Computes quality metrics for experiments. · `evaluation/metrics.py`
- [Cost tracker](https://github.com/samiullah07/fyp-llm/blob/main/evaluation/cost_tracker.py): observability · Tracks inference and experiment cost. · `evaluation/cost_tracker.py`
- [Baseline eval](https://github.com/samiullah07/fyp-llm/blob/main/evaluation/baseline.py): comparison · Evaluates baseline behavior against the experimental pipeline. · `evaluation/baseline.py`
- [Ablation study](https://github.com/samiullah07/fyp-llm/blob/main/evaluation/ablation_study.py): experiment · Runs variant comparisons across system configurations. · `evaluation/ablation_study.py`
- [Eval artifacts](https://github.com/samiullah07/fyp-llm/tree/main/data/eval): results store · Persisted outputs, logs, annotations, and reports for experiments. · `data/eval`

### Entrypoints

CLI and lightweight UI/demo launch paths.

- [Main CLI](https://github.com/samiullah07/fyp-llm/blob/main/main.py): entrypoint · Primary execution entrypoint for running the system. · `main.py`
- [App](https://github.com/samiullah07/fyp-llm/blob/main/app.py): ui entrypoint · Primary UI-facing launch path. · `app.py`
- [Demo app](https://github.com/samiullah07/fyp-llm/blob/main/demo_app.py): demo entrypoint · Lightweight demo or showcase launch path. · `demo_app.py`
- [Styles](https://github.com/samiullah07/fyp-llm/blob/main/app_styles.py): presentation · UI styling support for the demo/application layer. · `app_styles.py`

## Connections

- Workflow graph → Planner: orchestrates · The workflow graph coordinates planner-driven execution.
- Workflow graph → Search: routes to · Workflow sends retrieval steps to the search agent.
- Workflow graph → Summariser: routes to · Workflow sends evidence condensation to the summariser.
- Workflow graph → Verifier: routes to · Workflow sends claims to verification.
- Workflow graph → Assembler: routes to · Workflow sends intermediate outputs to assembly.
- Baseline graph → Search: uses · Baseline pipeline still depends on retrieval.
- Baseline graph → Assembler: finishes with · Baseline pipeline assembles a final response.
- Reader → Corpus builder: feeds · Document ingestion contributes to corpus construction.
- OpenAlex client → Corpus builder: enriches · External metadata helps populate corpus artifacts.
- Corpus builder → Vector store: indexes · Built corpus data is prepared for vector storage.
- Vector store → FAISS index: persists · Vector store writes to the FAISS-backed index.
- FAISS index → Retrieval: powers · The precomputed index is queried at runtime.
- Retrieval → Search: serves · Search agent depends on retrieval over indexed corpus.
- Prompts → Planner: guides · Prompt configuration influences planner behavior.
- Prompts → Search: guides · Prompt configuration influences search behavior.
- Prompts → Summariser: guides · Prompt configuration influences summarisation behavior.
- Prompts → Verifier: guides · Prompt configuration influences verification behavior.
- API clients → Planner: connects · Agents rely on external API calls through shared clients.
- Runtime config → Workflow graph: configures · Runtime settings shape workflow execution.
- Runtime config → MAB selector: configures · Strategy selection depends on runtime config.
- MAB selector → Workflow graph: adapts · Bandit selection can influence orchestration strategy.
- Evaluator → Metrics: computes · Evaluation uses metric definitions.
- Evaluator → Cost tracker: tracks · Evaluation records runtime cost.
- Baseline eval → Eval artifacts: writes · Baseline comparisons persist experiment outputs.
- Ablation study → Eval artifacts: writes · Ablation runs persist reports and results.
- Evaluator → Eval artifacts: stores · Evaluation artifacts are written to the eval data tree.
- Logger → Eval artifacts: logs · Workflow and verifier logs are stored with evaluation artifacts.
- Main CLI → Workflow graph: runs · Main entrypoint executes the primary workflow.
- App → Workflow graph: launches · App entrypoint launches the core workflow through a UI.
- Demo app → App: reuses · Demo application likely reuses the same presentation layer.
- App → Styles: uses · UI launch path depends on presentation styles.
- Main CLI → Evaluator: invokes · Primary execution can feed into evaluation runs.
- Search → Models: reads/writes · Retrieval results use shared domain structures.
- Assembler → Logger: emits · Final assembly is traced through logs.
- Verifier → Logger: emits · Verification activity is logged for traceability.
