Inspiration
Firebase AI Logic hybrid inference lets an app use the on-device model when it is there, and the cloud when it is not. That solves availability. It does not solve quality. Nobody checks if the small on-device model is good enough for your prompt. Teams guess, ship, and learn from unhappy users. We wanted that answer to come from a test instead.
What it does
Tandem gives every AI feature in your app a simple loop:
Test on real devices. Tandem runs your test cases on the real on-device models (Gemini Nano in Chrome, and Apple Foundation Models on macOS) and on a cloud model for comparison. Each case runs several times, because small models do not always give the same answer. Check the answers are honest. If a "device" answer actually came from the cloud, it counts as a failure, never a pass. Grade. Code checks the answer's format and values. A cloud model judges the open-ended cases. Decide with statistics. A model earns a feature only when the 95% Wilson lower bound of its pass rate clears a bar (τ = 0.85). That number means "we are 95% sure the real pass rate is at least this," so a lucky small sample cannot sneak through. Repair. A cloud model rewrites the prompt to fix the device's own mistakes. The new prompt must pass three gates before it can ship: the training cases, held-out cases it never saw, and no drop in quality on any other model. Publish with no release. A Cloud Function writes the decision into Remote Config. Apps using the Tandem runtime switch models while they run. Watch and roll back. Apps send telemetry with no prompt or answer text in it. If an on-device route starts failing, Tandem moves it back to the cloud automatically.
What we found on real hardware
We tested both on-device models on the same Apple M1 with a support-ticket triage prompt.
With our hand-written prompt, Apple's model passed 68 of 80 (lower bound 0.756) and Gemini Nano passed 51 of 80. Neither cleared 0.85, so Tandem kept triage in the cloud and wrote down why. We asked a cloud model to simply "improve" the prompt. The new prompt scored better on the cloud (74 of 80) but worse on both devices: Apple's model dropped from 68 to 58 and Nano from 51 to 39. Tandem's gates rejected it. If you only trusted a cloud model's opinion, it would have shipped. So we built a smarter repair. It looks at exactly which fields the device got wrong, protects the rules the device already gets right, and makes small edits. On a fresh confirmation run, the repaired prompt scored 151 of 160 on Apple's model (lower bound 0.897). It passed all three gates and was accepted. We published it. Our Mac sample app was already running in the cloud. A few seconds later it printed "triage policy applied, no release" and started answering on the Mac's own model in about 1.5 seconds. The same repair helped Nano too (130 to 136 of 160), but about a quarter of its cases still flip between runs. Its lower bound is 0.786, so Nano stays in the cloud for now, and the policy says why.
Every one of these numbers is on the public results page, recomputed from the raw job records in your browser.
How we built it
Firebase AI Logic for every model call, on device and in the cloud. Firestore as a job queue. Runners claim jobs in a transaction, keep a heartbeat, and only take jobs for their own model. Security rules enforce this. Cloud Functions for publishing, pairing devices, cleaning up stuck jobs, summing telemetry and rolling back. They never run a model themselves. Remote Config carries one routing policy per feature, read in real time by the apps. App Check with reCAPTCHA Enterprise protects AI Logic and the functions. TypeScript monorepo: a pure engine for the checks, the statistics, the policy compiler and the repair gates, with 100% line coverage; a runtime SDK, tandem.generate(); a React console that is also the Chrome on-device runner. A Swift helper that runs Apple's on-device model, using the feature's JSON schema so the model can only answer in the right shape.
Challenges we ran into
Gemini Nano is not deterministic. 43% of triage cases changed answer between two runs, so testing each case only once would have been misleading. Two models sharing one chip slow each other down. Nano's slow numbers in the morning came from sharing the M1 with the Apple runner. The Firebase Apple SDK changed during the hackathon, so we test Apple's own on-device model directly. Several things only showed up on the real project, not the emulator: indexes, service account roles and App Check enforcement. We wrote each one down.
Accomplishments we're proud of
Real on-device runs on two different on-device models, with an integrity check that never lets a cloud answer count as a device pass. A repair loop that caught a "better looking" prompt that was actually worse on the device. A live switch from cloud to device in a running app, with no release. Every number is public and checkable.
What we learned
A prompt that looks better to a cloud model can be worse on the device. You have to measure on the real device, with enough samples, and decide with a cautious statistic, not an average.
What's next
An Android runner, the runtime SDK for iOS apps, a slider that trades cost against quality, and gradual rollouts using Remote Config conditions.
Built With
- app-check
- apple-foundation-models
- cloud-functions
- firebase-ai-logic
- firebase-hosting
- firestore
- gemini
- gemini-nano
- react
- remote-config
- swift
- typescript
- vite