Inspiration
People handling sensitive matters hold context they cannot paste into a cloud chatbot. A client name. A case number. A courier they already know. That context makes the answer useful and makes the upload unacceptable.
Most hybrid demos frame on-device inference as a way to save latency or cost. AIRGAP frames it as a trusted enclave. The cloud becomes the fresh knowledge source because only the cloud can do web grounding. The visible boundary between the two is the product.
What it does
AIRGAP answers one message using private notes that stay on the device, then prints a receipt that cannot bluff. The receipt names the engine that answered, the policy requested, the mode that actually ran, the model, the latency, and what was transmitted. Requested and effective mode are separate fields, so a fallback reads as a fallback instead of being rewritten as the original choice.
Four policies put the boundary in the user's hands:
- ONLY ON DEVICE runs locally and blocks with a clear message when the model is unavailable. Nothing is transmitted.
- PREFER ON DEVICE runs locally when ready and falls back to the cloud with a written reason.
- PREFER IN CLOUD tries the cloud first and drops back to the device when offline.
- ONLY IN CLOUD is the deliberate cloud request. Deep check adds Google Search grounding and asks for consent first.
Every path ends in the same receipt. No badge is simulated. The source comes from response.response.inferenceSource in the native SDK. If a private request cannot run locally, the app stops instead of transmitting.
How I built it
The Flutter firebase_ai package does not expose OnDeviceConfig, inference mode selection, or inference source, so I wrote a typed MethodChannel to a Kotlin layer that owns the real Firebase AI Logic objects. That layer builds OnDeviceConfig, calls generateObject against a schema generated by KSP, and reads response.response.inferenceSource. The hand-written bridge is the single Dart call site. pigeons/hybrid_ai.dart records the request and reply contract so the two sides stay in sync.
The core decision is deliberate: every request builds two prompts. The private prompt carries local context and reaches only an ONLY_ON_DEVICE execution. The context-free prompt is built from the message alone and is the only one a cloud call can see. The Dart layer also clears the context list before a cloud-only call, so local notes do not cross the bridge on that path. There is no branch where a cloud execution can pick up the private prompt.
Remote Config supplies the cloud model name, on-device category, prompt version, and deep-check switch, with compiled defaults when a fetch fails. App Check uses the debug provider in debug builds and Play Integrity in release builds. History stores a keyed HMAC-SHA256 digest and the verdict, capped at twenty entries, with no raw message text. A stable debug token is supplied through a Dart define and is never committed. No telemetry, Analytics, Crashlytics, Firestore, or Authentication SDK is included.
Challenges I ran into
The SDK gap was the first challenge. A thin native bridge solved it without faking hybrid support.
The receipt then reported the effective mode in the requested field. Selecting local first and falling back to cloud made the card claim the user chose cloud. I split the values and carried the original selection through the bridge. Source labels also had to accept both SDK spellings, In Cloud and IN_CLOUD, or a genuine cloud run appeared as UNKNOWN.
The audit found four failure paths. A second on-device status call during reply construction threw after a successful inference. A timeout could cancel the native coroutine before it replied. A missing annotation or a plain-text response could make getObject return null with no exception. A storage failure could leave a phantom context item in memory. Each now has a fix, plus a 25 second call timeout.
Unsupported hardware was the final constraint. Many phones cannot run the local model. The app reports UNAVAILABLE and blocks private mode rather than quietly transmitting. The submitted video proves that refusal on the available device.
Accomplishments I am proud of
The privacy claim survives code review. Local context cannot reach a cloud prompt because the cloud prompt is built from a different string. Requested and effective mode stay separate, so every fallback is honest. The engine comes from the SDK. Structured output comes from KSP @Generable, with a plain-text JSON recovery path. Touch targets are 48 dp, and status uses text and icons rather than colour alone.
Verification is green: zero analyze issues, twenty-five passing unit tests, and successful debug and release APK builds. On a Galaxy S25, cloud verdicts produced receipts with LIKELY SCAM 98% and LIKELY LEGITIMATE 90%. The private mode refusal was verified on the same device.
What I learned
Hybrid inference is a policy tool before it is a speed trick. A green build says little about a platform bridge, a physical device, or a race between two taps. I verified the bridge decisions on a real device and kept the failure states honest. The supported-hardware local success path is ready for a Pixel or Galaxy device with AI Core installed; the submitted recording proves the boundary and refusal paths on the available hardware.
What's next for AIRGAP
I am closing the remaining verification gap rather than adding features. With supported hardware available, I will record the local path in airplane mode and the receipt changing from ON DEVICE to IN CLOUD. I will re-run analyze, test, and the release build on the final tree. After the deadline I will add release signing, a hashed history screen, and real download progress, in that order.
The four-mode policy, the two-prompt split, and the receipt are frozen. I am shipping the boundary, not a roadmap.