Inspiration

Cloud agents are getting good at doing things for us - planning, booking, messaging. To do it, they ask for everything: contacts, calendar, messages, and control of the phone. That is a bad trade, and prompt injection makes it worse: any web page an agent reads can try to talk it into leaking your data or doing something irreversible.

Hybrid inference let us ask a different question: what if the agent's brain were split in two - and the half that holds your secrets never left your device?

What it does

Enclave is a personal assistant with two brains:

  • Device brain - Gemini Nano, on device. Holds an encrypted personal vault (contacts, calendar, messages, notes, learned preferences). It routes every request, answers personal questions locally, and acts as a privacy guardian for everything the cloud asks.
  • Cloud brain - Gemini, in the cloud. Plans multi-step tasks with function calling plus Google Search / Maps grounding. It has no direct access to personal data or the phone.

Ask "Plan a dinner next week with my college friends and draft the invite" and the split happens live on screen:

  1. The request is aliased before upload - "Priya" becomes Person_1.
  2. The planner publishes a plan and asks the device questions through ask_vault(question, purpose).
  3. The on-device guardian checks each question against the user's original request and answers minimally, with aliases - e.g. "Person_1 is vegetarian and has classes Tuesday; Person_2 has a peanut allergy and can't do Wednesday; Person_4 is in Hyderabad." Phone numbers, emails and addresses never leave the device.
  4. The planner picks a day that fits everyone's constraints and searches for a venue.
  5. It proposes the invite; the device swaps aliases back to real names and numbers and the user holds to approve - the SMS composer opens pre-filled, the final tap is theirs.

Personal questions like "When is Priya's birthday?" are answered entirely on device with 0 bytes sent.

Built for safety

  • Encrypted at rest : AES-256-GCM under a non-exportable Android Keystore key (WebCrypto non-extractable key on web). Plaintext only exists in memory.
  • Pseudonymization : names → stable aliases; phones, emails, account numbers, OTPs, PAN, IFSC, addresses → typed placeholders before anything leaves the device.
  • Purpose-bound data access : every cloud data request carries a purpose and is judged against the user's original goal, which the device holds and the cloud cannot rewrite. Requests for identifiers or bulk data are denied by rule before any model sees them.
  • Prompt-injection resistance : web results are scanned and labelled untrusted. Red-team mode injects a malicious instruction into every search result so you can watch Enclave flag it - and no identifier is ever sent.
  • Action firewall : deterministic and deny-by-default - auto / hold-to-approve / biometric / blocked. Uninstalling apps, deleting data, factory reset, payments and security changes are blocked and have no code path in the native module. Rate-limited; loops detected.
  • Hold-to-approve : a 1.1 s press-and-hold with haptics - no accidental taps.
  • Outbound ledger : "What the cloud knows" shows every byte that ever left the device, exactly as sent.

How we built it

  • React Native + Expo (SDK 58) for one TypeScript codebase: the agent loop, guardian, policy engine, ledger and UI are shared across Android and desktop Chrome.
  • Android: a custom Expo native module in Kotlin on Firebase AI Logic (firebase-ai + firebase-ai-ondevice): ONLY_ON_DEVICE hybrid models for the router, local answers and guardian (personal data can never silently fall back to the cloud), ONLY_IN_CLOUD chat with function calling for the planner (sessions kept native so tool-call ids and thought signatures survive), grounded helpers with Tool.googleSearch() / Tool.googleMaps(), the onDeviceExtension lifecycle, Keystore sealing and guarded intents.
  • Desktop Chrome: the same interface on the Firebase JS SDK (firebase/ai) with Chrome's built-in Gemini Nano via the Prompt API (InferenceMode.ONLY_ON_DEVICE, initializeDeviceModel() on a user gesture), plus WebCrypto sealing.
  • inferenceSource labels every step On device or Cloud in the UI.
  • Firebase App Check enforced (debug provider; the judge APK ships one pre-registered debug token).
  • A resilient planner: model fallback chain (Gemini 4 Hydrogen → 3.8 Flash → 3.5 Flash-Lite), stall timeouts, retry-after waits, and a grounding chain (Maps → Search → clearly-labelled ungrounded).

Challenges we ran into

  • On-device limits. Single turn, short output, no tools. We gave Nano the jobs those limits fit - routing, guarding, minimal answers. Data minimization and a 256-token output budget turn out to be the same goal.
  • Device support. Neither of our phones (OnePlus 12, Galaxy S21) supports the ML Kit Prompt API, so we brought the same app to desktop Chrome, where Gemini Nano runs through Firebase AI Logic's web hybrid inference - and built a safe deterministic guardian for phones without Nano.
  • Free-tier capacity. Rate limits and "high demand" errors mid-plan led to the model fallback chain, timeouts and tool-failure handling.
  • Toolchain. Kotlin 2.4 metadata from the on-device SDK vs React Native's Kotlin 2.2, and Windows' 260-character path limit in React Native's C++ build.
  • Small-model JSON. Lenient parsing plus a deterministic second scrub, and the guardian only ever sees aliased data — so even a bad answer can't leak a real identifier.

Accomplishments that we're proud of

  • A real two-brain agent where the privacy boundary is visible, auditable and enforced in code.
  • Safety-critical decisions - blocked actions, identifier requests, secrets - never depend on a model.
  • An interface that shows the architecture instead of hiding it: every step says where it ran, how long it took and exactly what crossed the boundary.

What we learned

Hybrid isn't only "cloud when the device can't." The most valuable thing an on-device model can do is decide what the cloud is allowed to know.

What's next for Enclave

  • Real Contacts / Calendar import behind per-category consent.
  • Play Integrity / reCAPTCHA Enterprise App Check for production.
  • Per-contact sharing rules ("never share anything about Person_5").
  • Background notification triage once on-device inference is available outside the foreground.

Built With

Share this project:

Updates

Submission history