Skip to content

ahmadrazacdx/Sage

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

171 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Sage

An Offline-First Academic Assistant Using Retrieval Augmented Generation with Tool-Integrated Workflows

Poster | Report | Slides | Data

CI Codecov Release Apache 2.0 License Python 3.12 Windows


Overview

Sage is a desktop application that runs quantized LLMs locally via llama.cpp and orchestrates multiple specialized agentic workflows through LangGraph to handle academic tasks such as explanation, quiz generation, diagram creation, study planning, research, code diagnosis, and extended reasoning.

Everything runs on-device. No API keys, no cloud dependencies, no data leaves the machine.

How It Works

The system manages two concurrent llama-server instances:

Role Model Purpose
Primary Qwen3.5-2B (CPU) / Qwen3.5-4B (CUDA) Generation, reasoning, structured output
Utility Qwen3.5-0.8B Memory extraction, history compression, auxiliary tasks

User queries enter a LangGraph state graph where a router classifies intent and dispatches to the appropriate agent node. Each node has access to a hybrid RAG pipeline (dense retrieval via BGE-small-en-v1.5 + sparse BM25, fused with Reciprocal Rank Fusion), a long-term semantic memory store, and a set of tools including sandboxed Python execution, web/arXiv/Wikipedia search, Mermaid diagram rendering, and PDF/Markdown export via Typst.

Agent Modes

Mode Agent What It Does
Explain reasoning Chain-of-thought explanation with RAG context
Quiz Me quiz Generates and evaluates quizzes from course material
Diagram diagram Produces Mermaid diagrams with validation and SVG rendering
Study Plan planner Builds structured study roadmaps
Research research Multi-source wikipedia style research through (arXiv, web, Wikipedia) search with citations
Fix Code code_fix Code diagnosis and repair
Thinking reasoning Extended reasoning with configurable token budget
General general Open-ended conversation with memory

Preview

First Run
First Run
Loading Screen
Loading Screen
Home
Home Screen
Quiz Mode
Quiz Mode
Explain Mode
Explain Mode
Code Fix Mode
Code Fix Mode
Diagram Mode
Diagram Mode
Research Mode
Research Mode

Architecture

Sage Architecture

Tech Stack

Layer Technology
LLM Inference llama.cpp (llama-server), Qwen3.5 GGUF models
Orchestration LangGraph, LangChain
Backend FastAPI, Uvicorn, Pydantic, SQLite (WAL), ChromaDB
Embeddings BGE-small-en-v1.5 (ONNX via FastEmbed)
Frontend React 18, TypeScript, Vite, Tailwind CSS
Desktop Shell pywebview, pystray
Code Sandbox Subprocess isolation with NumPy, Pandas, SciPy, SymPy, Matplotlib, scikit-learn
Export Typst (PDF), Markdown
Search DuckDuckGo, arXiv, Wikipedia
Build & CI uv, pnpm, Ruff, Mypy, pytest, GitHub Actions
Installer NSIS, PowerShell (build.ps1)
Release GitHub Releases, Cloudflare R2 CDN

Getting Started

Prerequisites

  • Python 3.12
  • Node.js 18+ and pnpm
  • Windows 10/11
  • 8 GB RAM minimum (16 GB recommended)

Install

git clone https://github.com/ahmadrazacdx/Sage.git
cd Sage

# Python dependencies
uv sync --all-extras

# Frontend
cd frontend/artifacts/sage
pnpm install
pnpm dev
pnpm build

Run

# Desktop mode (pywebview window)
python -m sage

# API/headless mode (for development)
python -m sage --dev

Repository Structure

๐Ÿ“Sage/
โ”œโ”€โ”€ ๐Ÿ“‚src/sage/               # Core Python package
โ”‚   โ”œโ”€โ”€ ๐Ÿ“‚agents/             # LangGraph agent nodes (router, reasoning, quiz, diagram, ...)
โ”‚   โ”œโ”€โ”€ ๐Ÿ“‚rag/                # Hybrid retrieval pipeline (ChromaDB + BM25 + RRF)
โ”‚   โ”œโ”€โ”€ ๐Ÿ“‚routers/            # FastAPI route handlers (chat, sessions, documents, system)
โ”‚   โ”œโ”€โ”€ ๐Ÿ“‚tools/              # Sandboxed execution, search, export, calculator
โ”‚   โ”œโ”€โ”€ ๐Ÿ“„llm.py              # llama-server subprocess management
โ”‚   โ”œโ”€โ”€ ๐Ÿ“„memory.py           # Semantic memory extraction and retrieval
โ”‚   โ”œโ”€โ”€ ๐Ÿ“„database.py         # SQLite persistence layer
โ”‚   โ”œโ”€โ”€ ๐Ÿ“„config.py           # Pydantic settings + TOML loader
โ”‚   โ”œโ”€โ”€ ๐Ÿ“„app.py              # FastAPI application factory
โ”‚   โ””โ”€โ”€ ๐Ÿ“„desktop.py          # pywebview + system tray integration
โ”œโ”€โ”€ ๐Ÿ“‚frontend/               # pnpm monorepo
โ”‚   โ””โ”€โ”€ ๐Ÿ“‚artifacts/sage/     # React SPA (Vite, TypeScript, Tailwind)
โ”œโ”€โ”€ ๐Ÿ“‚config/                 # TOML configuration files
โ”œโ”€โ”€ ๐Ÿ“‚docs/                   # Technical documentation
โ”œโ”€โ”€ ๐Ÿ“‚tests/                  # pytest suite (30 modules, 80%+ coverage)
โ”œโ”€โ”€ ๐Ÿ“‚scripts/                # Model download, ingestion, benchmarking
โ”œโ”€โ”€ ๐Ÿ“‚installer/              # NSIS scripts, build manifest, staging
โ”œโ”€โ”€ ๐Ÿ“‚assets/                 # Logo and static assets
โ”œโ”€โ”€ ๐Ÿ“‚.github/workflows/      # CI, release, build-test, security
โ”œโ”€โ”€ ๐Ÿ“„pyproject.toml          # Project metadata and tool configuration
โ””โ”€โ”€ ๐Ÿ“„build.ps1               # End-to-end installer build script

Documentation

Document Description
Architecture System layers, agent nodes, data flow, inference strategy
Setup Guide Environment setup, model downloads, server binaries
API Reference REST endpoints and SSE streaming contract
Deployment Build pipeline, NSIS packaging, CI/CD
Institution Guide Customizing Sage for a specific institution/ department
Final Year Project ยท BS Software Engineering
Department of Computer Science & Information Technology ยท Thal University Bhakkar
Built by Ahmad Raza and Abdullah Khan

About

An Offline-First Academic Assistant Using Retrieval Augmented Generation with Tool-Integrated Workflows

Topics

Resources

License

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Packages

 
 
 

Contributors