Ramesh Inampudi

Android

Building irai: An Offline LLM Assistant for Android

By Ramesh Inampudi · 2026-11-17 · 5 min read

Most AI assistants assume a network connection and a server somewhere that sees every question you ask. That is fine for many uses, but it is a poor fit when you are offline, when the question is private, or when you simply do not want your conversations stored in someone else's system. I built irai to remove that dependency: a chat assistant for Android that runs a large language model entirely on the phone, with no cloud and no data leaving the device.

Why I built it

I wanted to see how far an on-device model could go as a daily tool rather than a demo. The target hardware was a Samsung Galaxy Fold 7 (Snapdragon 8 Elite, 12GB RAM), though the app is meant to work on any modern Android phone. The goal was an assistant that is private by default, works without a connection, and feels like a real app: proper code rendering, memory across turns, and the ability to swap models.

What it does

irai is a chat app built around local models. The main features, from the changelog:

How it works

The app is written mostly in TypeScript on React Native 0.75, with native Android code in Kotlin and the usual Objective-C and Ruby files that come with a React Native project template. Inference goes through llama.rn, so the heavy lifting happens in native llama.cpp code while the UI stays in JavaScript.

A few design choices are worth explaining because they apply to any on-device LLM app.

Inject context at inference time

Small models have no idea what day it is. Rather than hoping the model guesses, the real date and time are added to the system prompt on every request. It is a tiny change that removes a whole class of wrong answers.

Clean the output before showing it

Reasoning models emit internal tags such as <think>. irai strips those before display, both while streaming and after completion, so the user sees only the final answer. This turned out to be where my worst bug lived (below).

Be careful with multi-gigabyte files

IRx-1 can be updated, and the Models screen checks a small JSON build manifest on Hugging Face when you open it. That is a tiny fetch, not a download. If a newer build exists, the installed card shows Load, Refresh and Delete together, so you can keep your current version or refresh it. The refresh deletes the old file and re-downloads. I made this manual and opt-in on purpose: the app never swaps a multi-gigabyte model on its own, over any connection.

Use the right layout primitives

On Android 15 with edge-to-edge rendering, the keyboard covered the chat input until I fixed the layout so messages and input scroll above it. Separately, the tab bar now adapts its height using useSafeAreaInsets() from react-native-safe-area-context, and screens use edges={['top']} to avoid double padding.

What I learned

The tag stripper that ate my answers

Users, including me, saw answers cut off in the middle of code. I first suspected the response length limit and the context window, and I changed both. The real cause was a function, stripModelTags, meant to hide an in-progress <think> block. It matched any text shaped like <word>, not just the model's own control tags. So #include <cmath>, #include <iostream> or vector<int> triggered it, and everything after that point was silently discarded even though the model kept generating.

The fix was to scope the stripping to the model's actual internal tags. The lesson: when you post-process model output with a regex, match the narrowest thing you can name. As side improvements I removed the fixed response-length cap, so generation runs until a real stop, and raised the default context window from 2048 to 8192, since conversation history also eats into the room for a fresh long answer. Neither was the root cause, but both were worth keeping.

Memory retrieval must match the current question

I reproduced a bug where a coding question, asked shortly after an earlier food or Hyderabad mention, pulled an unrelated seed memory into context and derailed the answer. Now the current question has to actually match before a memory is injected. A stale topic from a few turns back is not enough on its own. Cross-turn memory is useful, but it needs a relevance gate.

Not every bug is in the app

A "Cannot connect to Metro" banner overlapped the bottom tab bar. It was a debug-build artifact: react-native run-android always expects a live dev server. The fix was to build with the standalone pre-bundled process so installed APKs never depend on Metro.

Reproduce first

Both the truncation and memory bugs were solved only after I reproduced them directly. Changing the length cap felt productive but fixed nothing, which is a good reminder to find the cause before tuning parameters.

Conclusion

irai is a practical test of whether a phone can be a self-contained AI assistant. The model itself is the easy part; the real work is in the surrounding details: output cleaning, memory gating, safe model updates and Android layout quirks. The latest release at the time of writing is v1.1.5, and the model I fine-tuned is available at huggingface.co/ikppramesh/irx-1-GGUF.