Himanshu Gupta

Hi, I'm Himanshu Gupta.

Curious about how things work, why people struggle, and what we can build to help. Exploring learning, AI, and human performance.

Want to know more?

Engineering

Building Shiv

(The data existed. Answers didn’t.)

Engineering an Intelligence Layer for Student Performance

Engineering Case Study • AI Infrastructure • Student Intelligence
Built while developing Learnzy.

Overview

Shiv connects Learnzy's student data to a language model. It supplies identity, memory, context, safety checks, and product behavior so the model can respond to a student's preparation, not just their latest message.

The Problem

Learnzy held revision history, mock results, chapter progress, mistakes, weak subjects, streaks, and schedules in separate features.

Yet a question such as "How am I doing?" or "Why do I keep making the same mistakes?" required the student to connect those records themselves.

I needed a layer that could reason across them.

The Original Vision

Instead of asking students to open five screens, I wanted one place to make sense of their preparation: mistakes, habits, progress, and eventually wellness, physiology, and recovery.

First Attempt

I first considered making Shiv a custom language model. I explored fine-tuning smaller open-source models because ownership, domain-specific reasoning, and control over behavior were attractive.

But that choice also meant training infrastructure, GPU costs, deployment, inference optimization, and ongoing maintenance. I could spend months improving the model before learning whether the product helped a student.

The bottleneck was not producing language. It was validating what Shiv should do with the student's preparation history.

I needed to separate control over the product from ownership of the model.

The Realization

Instead of asking how to build an AI model, I began asking which parts of an intelligence system needed to belong to Learnzy.

Identity, context, memory, safety, and product behavior could live around an existing model. Those were the layers I could change as I learned from students.

The model could then become replaceable without making the student experience start over. That decision shaped the architecture below.

Why “Shiv”

While building Learnzy, I spent time reflecting on surrender, calmness, and clarity. Those ideas influenced my product decisions, and "Shiv" felt natural when the system needed a name.

Students interact with Shiv; the model behind it can change.

Core Philosophy

The more relevant context Learnzy can supply, the less a student has to repeat. Weak chapters, revision backlogs, previous mistakes, study history, and recent mocks should inform the answer when those records are available and relevant.

System Evolution

Version 1

flowchart TD
  A[Student] --> B[Chatbot]
  B --> C[LLM]
  C --> D[Answer]

The first version answered isolated questions, without memory or preparation context.

Version 2

flowchart TD
  A[Student] --> B[Shiv]
  B --> C[Student Context]
  C --> D[Preparation History]
  C --> E[Mistake Notebook]
  C --> F[Revision Engine]
  C --> G[Calendar]
  C --> H[Wellness]
  C --> I[LLM]
  I --> J[Response]

Instead of answering questions in isolation, Shiv reasons over structured student data before producing a response.

The model became only one component inside the architecture.

High-Level Architecture

The diagrams show the shared architecture and its extension points. Academic assistance is the current focus; voice, wellness guidance, and physiological context are future directions.

flowchart TD
  A[Student] --> B[Android App]
  A --> C[WhatsApp]
  A --> D[Voice Future]
  B --> E[Shiv Runtime Layer]
  C --> E
  D --> E
  E --> F[Persona Engine]
  E --> G[Safety Layer]
  E --> H[Prompt Orchestration]
  E --> I[Context Builder]
  E --> J[Memory Manager]
  F --> K[Student Intelligence Context]
  G --> K
  H --> K
  I --> K
  J --> K
  K --> L[Mistake Notebook]
  K --> M[Revision History]
  K --> N[Calendar]
  K --> O[Mock Tests]
  K --> P[Weak Topics]
  K --> Q[Wellness]
  K --> R[Future Physiology]
  K --> S[Previous Conversations]
  K --> T[Profile]
  K --> U[Cloud Run AI Gateway]
  U --> V[Vertex AI Gemini]
  V --> W[Final Response]

Runtime Architecture

Requests pass through authentication, context and memory selection, safety checks, and prompt assembly before reaching the model.

flowchart TD
  A[Student Message] --> B[Authentication]
  B --> C[Persona Resolution]
  C --> D[Context Selection]
  D --> E[Memory Retrieval]
  E --> F[Safety Evaluation]
  F --> G[Prompt Assembly]
  G --> H[Cloud Gateway]
  H --> I[Vertex AI]
  I --> J[Post Processing]
  J --> K[Student]

Separating these responsibilities lets me replace the model without rebuilding the product layers.

Persona Layer

The persona layer defines what students experience as Shiv:

  • identity
  • tone
  • boundaries
  • capabilities
  • safety rules
  • behavioral consistency

These rules stay outside the choice of model.

Context Builder

The context builder selects information for the current question rather than sending the entire database.

Examples include:

  • latest revision statistics
  • recent mock performance
  • weak topics
  • mistake categories
  • study streak
  • profile information
  • previous conversations
  • wellness summaries (planned)

The amount of context varies by question, limiting unnecessary tokens.

Memory Architecture

Memory exists on three levels.

Memory Layer Purpose Examples
Conversation Memory Recent chat history Current conversation, recent intent, short-term continuity
Student Memory Long-term preparation information Mistakes, revision habits, mock trends, preferred study style
Product Memory Static knowledge about Learnzy Revision methodology, spaced repetition, product behavior; planned wellness guidance
flowchart TD
  A[User Request] --> B[Conversation Memory]
  A --> C[Student Memory]
  A --> D[Product Memory]
  B --> E[Context Builder]
  C --> E
  D --> E
  E --> F[Shiv Response]

AI Gateway

The mobile application never communicates directly with the model.

flowchart TD
  A[Android] --> B[Supabase Edge Function]
  B --> C[Cloud Run Gateway]
  C --> D[Vertex AI]
  D --> E[Response]

Benefits include:

  • secure API key handling
  • centralized prompt orchestration
  • logging
  • rate limiting
  • model abstraction
  • provider replacement

Safety Architecture

Before any request reaches the model, it passes through safety and scope checks.

flowchart TD
  A[Input] --> B[Crisis Detection]
  B --> C[Identity Rules]
  C --> D[Scope Validation]
  D --> E[Context Injection]
  E --> F[Model]

These checks define safety and scope boundaries before generation.

Multi-Surface Design

The design shares identity, memory, and context across interfaces; voice remains a future surface.

flowchart TD
  A[Shared Intelligence Layer] --> B[Android]
  A --> C[WhatsApp]
  A --> D[Voice]
  B --> E[Same Persona]
  C --> E
  D --> E
  E --> F[Same Memory]
  F --> G[Same Context]

The interfaces call the same intelligence layer.

Engineering Principles

  • Keep the model replaceable. Persona and product rules belong in the application.
  • Select relevant context. More student data is not useful if it does not answer the current question.
  • Keep identity consistent. Students should not need to understand which provider generated a response.
  • Keep product logic outside the LLM. The application defines behavior; the model supplies reasoning.
  • Use memory selectively. Surface student data when it helps, not merely because it exists.
  • Preserve iteration speed. Improve the surrounding layers without retraining a model.

Lessons Learned

The key decision was to stop treating model training as the product. Building the context, memory, identity, and safety layers gave me more direct control over the student experience.

Future Direction

Shiv currently focuses on academics. Wellness, physiological signals, behavioral patterns, and long-term progress are future extensions of the same architecture, not a reason to replace it.

Project Outcome

Shiv connects Learnzy's product systems through one reasoning layer. The model handles generation; Learnzy supplies the student context and defines the behavior.

Project Details

Field Detail
Project Type Engineering Case Study
Category Intelligence Layer · AI Infrastructure · Student Performance
Built For Learnzy
Author Himanshu Gupta
Status Active
Part of LearnzyLabs

Related Work