Skip to content
Nguyen Thanh Tai
All projects

AI education · Full-stack

V-Game

A light-3D web game where learners build RAG agents from blocks, run them for real, and trace why they pass or fail.

V-Game's isometric 3D campus hub at dusk, with the Library, Watchtower and Model Market zones labelled.

The 3D campus hub. Each building is a zone; NPCs hand out measurable problems.

test cases defined (pytest, Vitest, Playwright)
1,800+
test cases defined (pytest, Vitest, Playwright)
precomputed chunking variants
24
precomputed chunking variants
CI workflows incl. security scans
3
CI workflows incl. security scans
merged pull requests
86
merged pull requests

Overview

V-Game teaches applied AI engineering by letting learners break and fix real agents. They walk a small 3D campus, meet characters who pose a measurable problem, and configure an agent on a workbench — retrieval, chunking, hybrid search, rerank, the LLM.

The backend compiles that configuration into a LangGraph state graph, runs it against the level's golden questions, and streams each step back. Stars and the diagnosis are computed deterministically from the trace — there is no LLM judge.

The problem

Students of applied AI usually meet RAG as diagrams. They rarely see an agent invent a citation, pick the wrong chunk size, or miss a keyword that semantic search can't find — on their own configuration, with real model calls.

Who it's for

  • Learners in VinUniversity's AI20K program, playing self-paced.
  • Instructors, through a projector mode and a 45-minute lesson plan.

What it does

  • Workbench → LangGraph compiler

    Slot-based blocks map to a graph JSON, which a validator checks and a compiler turns into a static LangGraph StateGraph with barrier fan-in. Guards stop a case by writing a halt flag, so output still runs exactly once.

  • Hybrid retrieval you can feel

    BM25, vector KNN, RRF and alpha fusion, and rerank — across 24 chunking variants (by article or fixed size, 128–1024 tokens, 0–20% overlap).

  • Live, replayable runs

    Runs stream over Server-Sent Events (run, step, case, score). A sequence-checked reducer means a reconnect never double-counts, and events replay by Last-Event-ID.

  • Learning mechanics

    Prediction slips with confidence bets, a three-rung hint ladder, variant cases after hints, cheap three-sample runs, run history, and a trace book that links failed cases to the block that caused them.

  • 3D campus hub

    react-three-fiber scene with Dijkstra click-to-walk, orbit camera, NPC dialogs, and a sky that follows Hanoi's real time and weather.

  • Prompt-injection zone

    The Watchtower level adds pattern guards, an injection classifier, a refund tool and human approval — learners defend an assistant instead of building one.

How it's built

A prerendered React SPA on Vercel proxies /api to a FastAPI engine on a free Render instance (512 MB, 0.1 CPU). No ML model is loaded at runtime: embeddings and rerank scores are precomputed offline and committed.

  1. 1

    Workbench (browser)

    Learner fills block slots; pure functions turn slots into graph JSON.

  2. 2

    Validate & compile

    FastAPI validates the graph (all errors at once, in Vietnamese) and compiles it to a LangGraph StateGraph.

  3. 3

    Retrieve

    BM25 + cosine KNN over precomputed e5 vectors, RRF/alpha fusion, rerank from a committed score table.

  4. 4

    Generate

    Gemini through a model fallback chain, per-model rate limiter, daily call cap and a SQLite replay cache.

  5. 5

    Grade & stream

    Deterministic per-case grading, star rules and a culprit diagnosis, streamed to the browser over SSE.

Engineering challenges

Real RAG on a 512 MB free instance

Problem

Embedding and reranker models don't fit in memory or CPU on a free host.

Solution

All model work runs offline: passage and question vectors and a rerank score for every legal pair are built once and committed. The server checks a corpus hash at start and refuses with 503 instead of silently serving a stale index.

Free-tier LLM limits

Problem

Gemini's free quota and occasional 429/503s can stall a classroom.

Solution

A model fallback chain, per-model rate limiting over a sliding window, cooldowns that respect retry hints, a server-wide daily cap, and a SQLite replay cache plus seeded answers so the most common runs cost zero calls.

Streaming that survives reconnects

Problem

Mobile networks drop SSE connections mid-run.

Solution

An in-memory run store replays events from Last-Event-ID, POST /runs is idempotent, and the client reducer ignores any event it has already seen.

Keeping 3D off the critical path

Problem

three.js is heavy and most pages don't need it.

Solution

CI fails the build if three.js leaks outside the /play chunk or bundles exceed their budgets; the scene renders on demand rather than every frame.

My role

  • Wrote the design spec and ADRs, then built the engine, frontend, content pipeline and deployment myself — 553 of 557 commits, 86 merged pull requests over four weeks.
  • Developed with AI coding agents (Claude Code); I owned the specs, architecture, review and release.
  • Set up CI with type checks, tests, bundle budgets, brand-isolation checks and security scans, plus a post-deploy smoke test against production.

Current scope

Library zone (3 levels) and Watchtower level 1 are playable. Watchtower 2–3 and the Model Market zone are on the roadmap.

Learning impact has not been measured yet; a classroom pilot is planned.

Real captures. Click to enlarge.

  • Campus hub — react-three-fiber scene, click-to-walk pathing, real Hanoi sky and weather.
  • Building an agent on the workbench, running it, and earning three stars.
  • Level 1 workbench — star goals on the right, the agent drawn as a machine of blocks.
  • Deterministic grading: per-case checks, token budget, and a trace-based diagnosis.
  • Watchtower — guard a refund assistant against prompt injection with pattern and classifier blocks.
  • Prerendered landing page with an interactive one-shift demo.
  • The hub follows Hanoi's real time of day and weather (Open-Meteo).
  • Mobile layout of the hub.