A widespread mistake when adding AI to mobile products is routing every user utterance directly to the Large Language Model. While this looks simple on paper, it produces critical flaws in production:
Unacceptable Latency (6β12 seconds): Running on-chip neural inference consumes substantial clock cycles. For straightforward operations (e.g. checking a student balance or listing cancelled classes), waiting several seconds destroys usability.
Battery & Thermal Degradation: Continuous neural processing heats up device chips and drains battery life rapidly.
Arithmetic & Factual Hallucinations: Even fine-tuned Small Language Models (1Bβ2B parameters) struggle with precise date math, calendar reconciliation, and accounting calculations.
In HomeTutorPro, our on-device assistant SUE (Smart User Entity) uses a Two-Tier Hybrid Pattern:
ββββββββββββββββββββββββββββββββββββββββββ
β Incoming User Intent β
βββββββββββββββββββββ¬βββββββββββββββββββββ
β
ββββββββββββββββ΄βββββββββββββββ
βΌ βΌ
[TIER 1: FAST-PATH] [TIER 2: GENERATIVE LLM]
β’ Pure Kotlin / Room SQL β’ Local RAG + MediaPipe
β’ Structured balance & agenda β’ Complex pedagogical queries
β’ Sub-5ms execution time β’ Open-ended synthesis
β’ 0% GPU utilization β’ GPU-accelerated inference
β’ 100% precision (0 halluc.) β’ 2048 token context window
For operational queries, SueAgent bypasses the LLM entirely through optimized Kotlin algorithms:
Natural Language Time Engine: Parses explicit times (17:00, 21:30) as well as natural spoken expressions (at five, quarter past, ten to, midnight).
Contextual Afternoon Inference: If a tutor requests an appointment without specifying AM/PM ("schedule a class at 5"), the engine infers afternoon hours (17:00), matching the operational reality of private extracurricular tutoring.
Strict Schedule Collision Prevention: When rescheduling or booking extra lessons, SaveScheduleExceptionUseCase validates overlaps across existing classes, existing exceptions, and travel buffers. If a conflict occurs, mutation is blocked, and the tutor is immediately informed.
// Example: Deterministic collision evaluation in Domain Layer
class SaveScheduleExceptionUseCase @Inject constructor(
private val repository: ScheduleExceptionRepository,
private val studentRepository: StudentRepository
) : ISaveScheduleExceptionUseCase {
override suspend operator fun invoke(
professorId: String,
studentId: String,
exception: ScheduleException
): Result<Unit, DomainError> {
val allSchedules = studentRepository.getAllSchedules(professorId).first()
// Fast-path deterministic collision check in < 5 ms
for (existing in allSchedules) {
if (isTimeOverlap(exception.newStartTime, exception.newEndTime, existing.startTime, existing.endTime)) {
val studentName = studentRepository.getStudentById(existing.studentId)?.name ?: "Student"
return Result.Error(
DomainError.ConflictingStudent(
studentName = studentName,
time = "${existing.startTime} - ${existing.endTime}"
)
)
}
}
repository.saveException(professorId, studentId, exception)
return Result.Success(Unit)
}
}
Destructive database modifications (cancelling a booked class, recording payments, deleting records) must never occur based on raw acoustic ambiguity.
1. Intent Transition: SueAgent detects the destructive intent and transitions SueUiState to a Prepare state.
2. Visual Card Display: An interactive Jetpack Compose card (SuePendingAction) displays the exact mutation parameters.
3. Explicit Acoustic Prompt: SUE speaks a direct confirmation prompt ("Confirm cancelling Lucia's lesson on Friday? Say yes or no").
4. Transactional Execution: Only upon explicit voice affirmation ("Yes" / "Confirm") or UI tap is the database mutation use case executed.
Only when queries require open synthesis, relational advice, or complex pedagogical analysis does execution fall back to Gemma via MediaPipe GenAI:
Pedagogical Planning: "How do you recommend organizing Carlos's physics review before his exam?"
Relational Resource Overview: "What study materials have I shared with each student this week and what open time slots do I have left?"
By feeding Gemma structured data from Tier 1, the model functions purely as an articulate summarizer, completely eliminating factual fabrication.
Reserve LLMs for Language, Not Logic: Use Kotlin, Room indexes, and domain use cases for accounting, scheduling, and validation.
Speed is Feature #1: 90% of user queries in mobile productivity apps are transactional. Serving them in < 5 ms creates an instantly responsive, reliable user experience.
π‘ Architectural Takeaway: Don't use a 2-billion-parameter neural network to compute 15 + 20 or check if 17:00 overlaps with 17:30. A hybrid architecture delivers the best of both worlds: instant sub-5ms deterministic precision and rich natural language fluency.