Phases 1 & 2 deployed live · Phase 3 built & validated · classroom study next

STACK Question Forge

An AI that authors mathematics questions it can prove correct — then learns to teach them.

A decoupled system for Moodle STACK: cloud AI proposes, a real computer-algebra engine verifies, a live Socratic tutor coaches, and a reinforcement-learning agent sequences what to teach next.

New to STACK? It's the open-source engine behind maths quizzes in Moodle, used by universities worldwide — it grades real algebra and calculus (an entered expression like 2*x+1), not multiple-choice. Authoring those questions correctly is hard and error-prone; this project automates it.

▶ Open the live forge Try the live tutor ★ StackForge plugin ★ STACK AI Hinter plugin
0
question types,
oracle-validated
0
faster to mastery
than the best baseline
0
of students
brought to mastery
0
automated tests,
all green
0
ML frameworks
(numpy only)

The core idea

The AI is never trusted to be right.

Language models hallucinate. So the AI is allowed to propose only a source expression — never the answer or the grading. A deterministic template then makes a real CAS compute the teacher's answer, and STACK's own engine proves the question grades correctly across many random variants. Wrong guesses simply fail validation and are retried.

1
PROPOSE

AI fills one slot

The model supplies a source expression + wording — nothing more.

2
GATE

Allow-list guard

An expression grammar blocks anything unsafe before it touches the CAS.

3
COMPUTE

Maxima derives the answer

The question itself computes ta1 : diff(expr,x).

4
PROVE

STACK /test all variants

Full marks across random seeds, or it's rejected.

5
EXPORT

Standard Moodle XML

Importable into any Moodle running STACK — nothing forked.

Correct by construction: the mathematics is computed by the same Maxima engine STACK uses, and independently verified before a human ever sees the question.

The arc

Three phases: author → tutor → teach

Each phase stands alone yet feeds the next — and "intelligence" always lives in an external service Moodle calls, never a fork of Moodle itself.

⚒️
Phase 1 · The Forge

Author & validate

Generate STACK questions with cloud AI, validate every one against a standalone STACK API (real Maxima on AWS), export Moodle XML. 8 question types; a 14-question validated seed bank.

● Deployed live
🎓
Phase 2 · Live Tutor

Coach in real time

A student answers; STACK grades it live; on a wrong answer an AI gives an escalating Socratic hint — never the answer. Shipped both as a web tutor and a real Moodle 4.5 plugin (server-side key, hints logged).

● Deployed live
🧠
Phase 3 · RL Agent

Learn to teach

A reinforcement-learning policy decides which question to set next (skill × difficulty) to reach mastery fastest — discovering a curriculum from reward alone. Served as an external recommend_next() API.

✓ Built & validated

Phase 3 spotlight

An agent that discovers a curriculum

Trained against a Bayesian-Knowledge-Tracing student simulator, a tabular Q-learner finds an easy → medium → hard progression and brings every student to all-skills-mastered in roughly half the questions of the best baseline — and the only baseline that finishes at all.

Questions to bring a student to all-8-skills mastered
↓ fewer is better · 2,000 students, paired seeds
139
RL policylearned
278
round-robinbest baseline
300
hardest-first6% solve
300
easiest-first0% solve
300
random0% solve
0

Offline RL from messy logs

Fitted-Q Iteration with pessimism learns a winning policy from a frozen log of sub-optimal play — exactly how real Moodle data will plug in.

0

Deep Knowledge Tracing

A from-scratch numpy GRU (hand-written, gradient-checked back-prop) recovers ~98% of the BKT oracle's predictive accuracy from raw answer streams.

✓

Learns prerequisites

With a prerequisite graph switched on, the agent front-loads foundational skills before dependents — and beats a prerequisite-blind policy.

Inside Moodle

Two plugins put it in teachers' hands

It all runs as standard Moodle plugins — install, switch on, go. Moodle is never forked; the plugins simply call the external "intelligence" and emit standard questions.

⚒️
local_stackforge

StackForge — the generator

Generates oracle-validated STACK questions straight into a course's question bank: pick a type and difficulty, or let the RL policy build a full curriculum-ordered quiz in one click.

🎓
local_stackhinter

STACK AI Hinter — the coach

Adds a fact-checked hint button to STACK questions in any quiz: hints are CAS-grounded, so they're accurate and never leak the answer — and can run entirely in the student's browser, with no API key at all.

Under the hood, three specialised "brains" each do one job — which is what keeps it trustworthy and easy to improve.

🧮

The maths-checker

A real CAS (Maxima) decides what's correct. It never guesses — and the AI is never allowed to.

💬

The writer

A language model drafts the questions and phrases the hints — suggestion and wording only.

🧭

The planner

The RL policy decides what each student should practise next, from their inferred mastery.

What's next

From validated to proven in a classroom

The system works in simulation. The next step is evidence with real students: does AI-sequenced practice actually help people learn more — and does it last?

🔬
The study

A real classroom trial

A within-student design on a live university maths module: each student gets AI-sequenced practice on some topics and standard practice on others, then a short topic-tagged test measures the difference — so every student is their own fair comparison.

🛡️
Ethics-first

Consent & privacy by design

Voluntary, informed consent; participation never affects grades; data are pseudonymised and GDPR-compliant. It goes through the University Research Ethics Committee — nothing starts until it is approved.

🔁
A learning flywheel

Smarter every term

Real, de-identified practice data refit the student model and retrain the teaching policy — so the recommender improves with use, with a human review gate before any update goes live.

In collaboration with mathematics teaching staff at ATU. The aim: move from "it works in theory" to measured learning gains for real students.

Why it's hard

Hard-won engineering

The interesting problems weren't the models — they were trust, safety, and getting the incentives exactly right.

🛡️ An oracle that catches CAS errors

STACK can score a self-matching test as "passed" even when a question threw a hidden runtime error. A dedicated checker inspects every variant's messages, so silently-broken questions are rejected — not shipped.

🎯 Incentives that can't be gamed

A naive design let a "spam easy questions" agent beat real teaching by riding lucky guesses. Mastery was redesigned to rise only from difficulty-matched learning — so adaptive difficulty became the only path to progress.

🔒 Decoupled & key-safe

AI keys never reach the browser; the tutor and policy are external services behind bearer-token auth + locked-down CORS. Moodle is never forked — it only emits and calls.

🧪 Provably-correct back-prop

The DKT network's hand-written BPTT is verified against finite-difference gradients. Offline RL uses pessimism (support constraints + lower-confidence bounds) to survive distribution shift. 96 tests gate it all.

🔁 A real sim-to-real bridge

A Baum-Welch EM fitter recovers student parameters from logged answers (validated by parameter recovery), so the simulator can be replaced by real learners the moment enough data exists.

⚙️ No magic, no bloat

Static site, no build step; the entire RL stack is pure numpy with no framework. Readable end-to-end — every result reproducible from one command.

Built with

Maxima CAS Moodle STACK numpy RL Q-learning BKT · DKT Offline RL Vanilla JS Docker · AWS Caddy + Cloudflare GitHub Pages