An Offline-First Academic Assistant Using Retrieval Augmented Generation with Tool-Integrated Workflows
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.
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.
| 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 |
First Run |
Loading Screen |
Home Screen |
Quiz Mode |
Explain Mode |
Code Fix Mode |
Diagram Mode |
Research Mode |
| 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 |
- Python 3.12
- Node.js 18+ and
pnpm - Windows 10/11
- 8 GB RAM minimum (16 GB recommended)
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# Desktop mode (pywebview window)
python -m sage
# API/headless mode (for development)
python -m sage --dev๐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
| 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 |
Department of Computer Science & Information Technology ยท Thal University Bhakkar
Built by Ahmad Raza and Abdullah Khan








