Inspiration
Small sellers on Instagram and WhatsApp answer hundreds of customer messages a day. AI could write those replies, but every cloud call costs money and sends customer data off the device. Firebase AI Logic can run Gemini Nano right in the browser, but out of the box you pick one mode for the whole app. Real inboxes are mixed: most messages are easy, and only a few need a bigger model.
What it does
Downshift is an open-source smart router for Firebase AI Logic hybrid inference, plus a reply assistant for small sellers built on it. For every customer message, it decides whether to answer on-device (Gemini Nano in Chrome, Apple's on-device model on iPhone) or in the cloud (Gemini). In a full demo day of 51 messages, 69% were answered on the laptop, free and private.
- Easy questions (stock, price, size, delivery) are answered on-device.
- Hard messages (refunds, angry customers, Hindi, several questions at once) go to the cloud, with an instant on-device draft shown while the cloud writes.
- Fact checks: every on-device reply is checked against the shop's catalog. If Nano gets a price, size or delivery time wrong, the router escalates to the cloud automatically.
- Spam gets no reply, and messages with addresses or phone numbers never leave the device.
- Offline mode: everything is drafted on-device, replies that normally need the cloud are flagged for review, and they are redrafted when back online.
- Learning: the cloud grades a sample of on-device replies, and Downshift learns which question types Nano handles well.
- Live tuning: routing thresholds come from Remote Config, so a change in the console applies to the next message, with no redeploy.
How we built it
- Firebase AI Logic hybrid inference for every AI call, with explicit on-device and in-cloud modes, recording where each answer actually ran (
inferenceSource). - A five-stage router in pure TypeScript: rules, then Nano classification (intent, complexity, sentiment) streamed in the same call as the reply, then a score against a threshold, then execution, then fact checks with cascade to the cloud.
- Remote Config for thresholds, sample rates, keywords and models, updated live.
- Firestore stores only anonymous pass/fail counters, never message text, enforced by security rules. Anonymous Auth and App Check (reCAPTCHA Enterprise) protect it, and Firebase Hosting serves the app.
- iOS: the same router in Swift and SwiftUI, using Apple's Foundation Models on-device and Gemini through Firebase AI Logic in the cloud.
- Open-source SDK:
@imshivamb/downshift(core),@imshivamb/downshift-firebase(adapter) and@imshivamb/downshift-react(<DownshiftDashboard />), so any Firebase app can use the router. - Web app: React, Vite, Tailwind, IndexedDB (all messages stay in the browser).
Challenges we ran into
- Nano is small and sometimes gets facts wrong, so every on-device answer is checked and can cascade to the cloud.
- On-device calls run one at a time, so the router queues Nano work and runs cloud work in parallel.
- Hinglish was misread as Hindi by the language detector, so we keep romanized text on-device and let Nano reply in the customer's style.
- The iOS SDK changed: its hybrid API was replaced during the hackathon, so the iOS app routes between Apple's model and Gemini itself.
Accomplishments that we're proud of
- Hybrid is the core of the product, not a fallback: per-message routing, instant drafts, fact-checked cascades, offline mode and learning.
- Two platforms run the same routing logic: Chrome with Gemini Nano, and iPhone with Apple Foundation Models.
- Privacy by design: customer text is never stored in Firebase, and personal details never leave the device.
What we learned
On-device models are fast and free for everyday questions, but they need guardrails. Checking their answers and escalating only when needed gives near-cloud quality at a fraction of the cloud calls.
What's next for Downshift
An npm release of the SDK, an Android port, and real inbox integrations (Instagram, WhatsApp, Gmail).
Try it
- App: https://downshift-hybrid.web.app (desktop Chrome; works cloud-only without Gemini Nano)
- Code: https://github.com/imshivamb/downshift
Built With
- apple-foundation-models
- cloud-firestore
- firebase-ai-logic
- firebase-app-check
- firebase-authentication
- firebase-hosting
- firebase-remote-config
- gemini
- gemini-nano
- react
- swift
- typescript
- vite