Multimodal Math Mentor
A 13-node LangGraph tutor for JEE maths: multimodal input, hybrid retrieval, sandboxed SymPy and three human checkpoints.

What it is
What it does
A tutoring agent that takes maths problems as text, photo or voice and walks students to JEE-level solutions. The interesting part isn't the solving, it's the supervision around it: a LangGraph state machine routes every problem through extraction, guardrails, retrieval, symbolic computation, verification and explanation, pausing for a human at exactly the moments the system doesn't trust itself.
Why it exists
I watched LLMs confidently botch 3-step JEE maths. In a classroom that costs trust. I didn't want a bigger model. I wanted a checker, a calculator that can't lie, and a system that knows when to stop and ask a human.
Repo Amit-kr26/Multimodal_Math_MentorDemo huggingface.co/spaces/Amit-kr26/Multimodal_Math_MentorStack LangGraph · Gradio · FAISS · BM25 · EasyOCR · Whisper · SymPy
Runs on a free Hugging Face Space, so it may need to restart on first load, which can take a minute or two.
How it is built
13-node graph
agents/graph.py wires extract → guardrail → parse → route → retrieve_context/retrieve_memory → solve → verify → explain → save_memory, branching on the extraction review, the guardrail, the parser and the verifier, and compiled with MemorySaver so threads resume mid-solution.
Three human checkpoints
interrupt_before fires on hitl_extraction / hitl_clarification / hitl_verification, triggered when OCR or ASR confidence < 0.6, parsing stays ambiguous, or the verifier scores < 0.7.
Retry with feedback
The verifier can bounce the work back to the solver up to twice, passing its issues and suggestion straight into the next solver prompt.
Hybrid retrieval with RRF
FAISS (all-MiniLM-L6-v2) and BM25Okapi each return 10 candidates over 20 markdown knowledge-base docs (chunked 500/50 along headings), fused with reciprocal rank fusion k=60 down to the top 5.
Sandboxed SymPy
COMPUTE: lines emitted by the solver run in an isolated subprocess (timeout 10s) that replies with JSON {result, latex, error}. The verifier's checks go through the same box.
Voice that speaks maths
Whisper base on CPU post-processes phrases like 'square root of' → sqrt() and Greek names → symbols, balancing parentheses before parsing.
Guardrail against injection
A dedicated agent rejects role-play and prompt-injection attempts, including attacks smuggled in through OCR'd images, base64 or leetspeak obfuscation.
Self-learning memory
Problem and solution pairs append to JSONL; retrieval is cosine similarity over a cached embedding matrix (top 3, minimum similarity 0.3), rebuilt only when the record count changes.
Eval harness
eval/run_eval.py pushes 25 curated problems (algebra 7, calculus 7, probability 6, linear algebra 5) through the whole graph and emits timestamped JSON + Markdown reports with per-topic accuracy, confidence and timing.
How the pieces connect
Drawing is wider than the frame. Drag to pan.
Also filed under LLM / RAG