All notable changes to the Advanced Mathematics Assistant will be documented in this file.
The format is based on Keep a Changelog.
- Documentation: Rewrote
README.mdfor the hackathon showcase and added a comprehensivedocs/ARCHITECTURE.mdfile featuring a Mermaid state machine diagram. - E2E Testing: Integrated Playwright into the frontend and added a baseline
login.spec.tsUI test. - Integration Tests: Added
tests/test_integration.pyto ensure core API contracts perform as expected with mocked dependencies. - CI/CD Security: Added
pip-auditto the.github/workflows/ci.ymlpipeline to scan for dependency vulnerabilities on every push. - Demo Script: Created a 3-minute hackathon demo storyboard to highlight the agentic features.
- Modern Architecture: Fully replaced legacy Streamlit frontend with a high-performance React 19 + TypeScript + Vite application.
- Premium UI/UX: Implemented a bespoke design system featuring glassmorphism, responsive grid layouts, and automatic dark/light mode switching based on
prefers-color-scheme. - Live Streaming & LaTeX: Integrated an SSE fetch consumer for the
/api/v1/chat/streamendpoint with real-timereact-latex-next(KaTeX) rendering of mathematical symbols. - NCERT Quiz Workflow: Recreated the interactive problem-solving experience with "Give Hint", "Show Steps", "Show Answer", and an intuitive "Stuck? Ask AI" contextual menu.
- Progress Tracking: Built a new
ProgressDashboardcomponent displaying the user's current streak, accuracy metrics, and an activity heatmap. - Firebase Deployment: Reconfigured
firebase.jsonto deploy the new React Single Page Application (SPA).
- MCP Integration: Created 6 new MCP server tools (
sympy-mcp,calculator-mcp,graph-plotter-mcp,pdf-reader-mcp,python-executor-mcp,image-solver-mcp) mapped via a local registry tomcp-servers/. - Python Sandbox: Integrated
RestrictedPythoninpython-executor-mcpto securely execute inline python code for complex math tasks, while successfully blocking imports likeosandsubprocess. - AgentExecutor Update: Refactored
SolverAgent(Google ADK) to dynamically usecreate_tool_calling_agentandAgentExecutorfrom LangChain whenUSE_MCP=trueis set. - Tools Verification: Added
test_mcp_servers.pyto end-to-end test the contract and logic of the 6 tools locally.
- Dockerization: Created a production-ready
Dockerfileto containerize the FastAPI backend for Cloud Run. - CI/CD Pipelines: Added GitHub Actions workflows:
ci.yml: Runs tests automatically on pull requests tomain.deploy.yml: Authenticates with Google Cloud, builds the Docker image, and deploys to Cloud Run on pushes tomain.
- Firebase Hosting: Scaffolded
firebase.jsonand a placeholderindex.htmlto serve static frontend assets. - DDoS Protection: Integrated
slowapito enforce a strict 20 requests/minute rate limit on all chat/vision API endpoints to protect the free tier from abuse. - Secret Management: Removed reliance on local
.envfiles for deployment by utilizing Google Cloud Secret Manager and GitHub Actions secrets.
- Firestore Prompt Versioning: Created
PromptServiceto dynamically load the system prompt template from Firestore (promptscollection). - A/B Testing & Active Versioning:
PromptServicesupports passing anab_test_groupstring to pull variations, and anactive_versionpointer inside the Firestore document to smoothly update prompts without code deployment. - Local Fallback: Designed to fail open — if Firestore is unreachable, the API instantly falls back to a hardcoded local template to ensure zero downtime.
- Safety Filters: Updated
GeminiServiceto use the newergoogle.genaiSDK and activatedSafetySettingfilters against Harassment, Hate Speech, Dangerous Content, and Sexually Explicit queries using the Gemini standard built-in thresholds. - Offline LLM-as-Judge Evaluation: Created
EvaluationServiceusinggemini-2.5-flashto evaluate RAG answer quality on a scale of 1-5 with deterministic reasoning output. - Cloud Logging: Appended
google-cloud-loggingto dependencies and integrated structured cloud logging insideconfig.pywhen a GCP environment or Application Default Credentials (ADC) are detected, while gracefully falling back to standard stdout logging locally.
- Qdrant Vector Database: Replaced ChromaDB and FAISS with Qdrant Cloud. Qdrant is natively supported in
:memory:mode for testing and local usage without an API key. - Hybrid Search: Configured
QdrantVectorStorewithRetrievalMode.HYBRID, fusing dense vectors (text-embedding-004via Gemini API) and sparse vectors (fastembedBM25). - Markdown Knowledge Base: Migrated the monolithic 6000-line
knowledge_base.pyinto 201 individual structured Markdown files in theknowledge-base/directory, allowing cleaner git tracking and easier manual updates. - Dynamic Metadata Filtering: Configured Qdrant's payload filters so RAG can accurately filter documents by
class_level,chapter, andtopic.
- Passed all existing RAG and Chunking tests.
- Added
test_qdrant.pymocking the newQdrantServiceinitialization and sparse/dense retrieval paths. - Total tests passed: 62.
- LangGraph StateGraph Integration: Added
langgraphandlangsmithto wrap the Phase 4 ADK agents into a formal state machine (math_graph.py). - Parallel Retrieval: The
retrieve_ragandretrieve_memorynodes now run concurrently, optimizing retrieval latency. - Verification Retry Loop: The
should_retryconditional edge enforces a self-correction loop, prompting the solver to fix its mistakes up to 2 times if the verifier detects an error. - Observable Tracing: LangSmith is fully supported. When
LANGCHAIN_API_KEYis provided, every state mutation and token generation is logged to the dashboard. - Configurable Pipeline: The API path is controlled by
USE_LANGGRAPH=True, allowing graceful fallback to the ADK orchestrator or the original single-agent pipeline.
- Added
tests/test_langgraph.pyto verify proper conditional edge routing (e.g. testing that failures loop back to the solver). - Total tests passed: 59.
- Multi-Agent Architecture: Replaced the monolithic
MathAIEnginewith a 5-agent pipeline orchestrated by Google ADK (google-adk==0.1.0). - Planner Agent: Classifies incoming queries by math topic and educational class level for targeted responses.
- Memory Agent: Interfaces directly with Firestore to fetch chat history and analyzes weak topics from the user's profile to adapt explanations.
- Solver Agent: Executes RAG retrieval and symbolic computation (SymPy) to construct the core mathematical solution.
- Verifier Agent: Automatically audits the Solver's output for mathematical or logical errors (e.g., catching
4+4=9), triggering an internal retry if verification fails. - Formatter Agent: Applies strict output templates, formatting solutions with teacher reactions, emojis, and LaTeX math mode.
- Human Feedback Loop: Added
save_user_feedbackAPI to Firestore for reinforcement learning data collection.
- Added
tests/test_adk_agents.pywith mock ADK environments to unit-test Planner classification, Verifier error detection, and Memory topic retrieval. - Total test count increased to 57 passing tests.
- Firebase Authentication: Protected all endpoints with
firebase_adminID token verification middleware. Added support for Google Sign-In backend verification. - Firestore Persistence: Completely removed MongoDB (
pymongo,motor) and migrated chat memory persistent storage to Google Cloud Firestore. - User Isolation: Chat history is now tightly scoped to authenticated user IDs to prevent data leakage across sessions.
- Progress Tracking API: Added
/api/v1/progressendpoints to track and persist daily streaks and total problems solved per user. - Security Rules: Deployed
firestore.rulesto ensure strict row-level security for user data.
- Added
tests/test_firebase.pyto verify authentication middleware logic and mock Firestore queries. - Total test count increased to 54 passing tests.
- Gemini Primary Engine: Migrated from Groq (LLaMA) to Google Gemini (
gemini-2.0-flash). Groq remains as an optional fallback whenUSE_GEMINI=false. - SSE Streaming Support: Added
POST /api/v1/chat/streamfor real-time token-by-token response delivery using FastAPIStreamingResponse. - Gemini Vision OCR: Added
POST /api/v1/vision/extractendpoint using Gemini Vision to extract mathematical content and solve problems directly from images, replacing Tesseract OCR. - LaTeX Math Support: Updated system prompt template to use proper LaTeX math mode (
$...$and$$...$$) for all mathematical expressions instead of restricted unicode symbols. - Added
.env.examplefile for new setup credentials.
- Added
tests/test_gemini.pyto verify text querying, fallback mechanisms, and vision extraction. - Total test count increased to 50 passing tests.
Decomposed the 2,800-line monolithic main.py into single-responsibility modules:
backend/src/config.py— Centralized Pydantic Settings + system prompt templatebackend/src/math/symbolic_engine.py— SymPy symbolic math (differentiate, integrate, solve, simplify, matrix ops)backend/src/math/knowledge_indexer.py— MathDataLoader + MathDataPreprocessor + MathTextSplitterbackend/src/math/graph_utils.py— Safe expression evaluator (Phase 0 fix) + OCR helperbackend/src/services/memory_service.py— MongoDB chat memory with in-memory fallbackbackend/src/services/vector_service.py— ChromaDB/FAISS vector store + build pipelinebackend/src/services/llm_service.py— Groq LLM factory + MathAIEngine orchestrator
backend/src/main.py— FastAPI application with CORS, lifespan eventsbackend/src/api/v1/chat.py— REST endpoints:POST /api/v1/chat— Process math queries through full RAG pipelineGET /api/v1/history/{session_id}— Retrieve chat historyDELETE /api/v1/history/{session_id}— Clear session historyGET /health— Health check with KB document count
- Pydantic request/response models for type-safe API contracts
backend/Dockerfile— Python 3.11-slim, non-root user, port 8080docker-compose.yml— Multi-service: FastAPI backend + Streamlit frontend with health checksbackend/requirements.txt— Dedicated backend dependency manifest
tests/test_api.py— 6 tests for FastAPI endpoints (health, root, chat validation)
- CRITICAL FIX: Removed dangerous
eval()call in graph plotter (main.py:L876)- Vulnerability:
eval(re.sub(r'\^', '**', expr), ns)with an incomplete namespace allowed arbitrary Python code execution through the graph plotter input field. An attacker could escape the__builtins__: {}sandbox via reference chain attacks. - OWASP Classification: A03:2021 — Injection
- Fix: Replaced with
_safe_evaluate_expression()usingsympy.sympify()+sympy.lambdify(). SymPy's parser only understands mathematical syntax and cannot execute arbitrary Python code. - Additional Defense: Added blocklist pattern matching for
__import__,exec,eval,compile,open,getattr,setattr,subprocess,os.,sys., and other dangerous constructs. - Status: ✅ CLOSED — Verified by 12 attack-pattern tests and 17 safe-expression tests
- Vulnerability:
- Extracted 5 existing unittest classes from
main.py(L2589-L2670) into standalone test files:tests/test_data_sources.py—TestDataSources(knowledge base loading)tests/test_preprocessing.py—TestPreprocessing(text cleaning, dedup, topic detection)tests/test_chunking.py—TestChunking(text splitting, metadata preservation)tests/test_symbolic_engine.py—TestSymbolicEngine(differentiation, integration, solving)tests/test_memory.py—TestMemory(chat history add/retrieve)
- Created new
tests/test_graph_security.pywith 29 test cases for the eval() fix:- 17 tests verifying safe mathematical expressions (sin, cos, tan, log, sqrt, exp, abs, arcsin, sinh, cosh, tanh, pi, e, polynomials, caret notation, constants, composites)
- 12 tests verifying malicious inputs are blocked (os, sys, subprocess, open, exec, eval, compile, getattr, globals, pathlib, builtins, import)
- Added
pytest>=7.0.0andpytest-cov>=4.0.0torequirements.txt
- Updated
.gitignorewith:.pytest_cache/,htmlcov/,.coverage,*.egg-info/,dist/,build/ - Created this
CHANGELOG.mdto document the transformation journey
- Architecture: Single-file monolith (
main.py— 2,745 lines) - LLM: LLaMA 3.3 70B via Groq API
- Vector Store: ChromaDB (primary) / FAISS (fallback) — local, ephemeral
- Embeddings: HuggingFace sentence-transformers/all-MiniLM-L6-v2
- Chat Memory: MongoDB Atlas
- UI: Streamlit
- Authentication: None
- CI/CD: None
- Docker: None
- Google AI: None
- Hackathon Score: 3/10
-
eval()security vulnerability in graph plotter (L876) — FIXED in Phase 0 - God Object anti-pattern (all logic in one file)
- No user authentication
- No Google AI ecosystem integration (Gemini, Firebase, Cloud Run, ADK)
- No agent architecture (single-shot RAG, not multi-agent)
- Local vector store (not cloud-persistent)
- No CI/CD pipeline
- No Docker containerization