Inspiration
A university help desk gets hundreds of tickets a day, and each one has to reach the right team out of a dozen or more. The hard part is local knowledge: which lab is on which side of campus, which office owns the student-worker forms. New staff take weeks to learn it, and a misrouted ticket sits in the wrong queue for a day.
Cloud models route well, but help-desk tickets are full of student IDs, names, emails and phone numbers, which most universities must protect (FERPA in the US). A small model on the staffer's own computer keeps that data local, but on its own it gets too many tickets wrong. We wanted both: local by default, the cloud only when it is needed, and never the raw ticket.
What it does
Every ticket goes through five steps:
- Mask, on this computer. Student IDs, emails, phone numbers and names become
[STUDENT_ID],[EMAIL],[PHONE],[NAME]before any model sees the ticket. - Route on device. Chrome's built-in model picks a team. Its prompt holds the team list and the 8 most similar past tickets from this desk, found with TF-IDF in plain TypeScript.
- Check. If the on-device answer disagrees with the vote of those similar tickets, the ticket is marked unsure. If they agree, it is routed, and nothing about it leaves the browser.
- Ask Gemini, with the staffer's OK. For an unsure ticket the staffer sees exactly what would be sent (masked text, team list, masked similar tickets) and can mask any other word with one click. Only then does Gemini suggest a team and a one-line reason a new staffer could reuse.
- Learn. The staffer confirms or changes the team, and the masked ticket is saved as a new example for this desk. The next similar ticket is more likely to stay on the computer.
The page shows the share of tickets that never left the browser, live, next to the numbers we measured offline.
How we built it
- Firebase AI Logic hybrid inference (
firebase/ai), two models through one SDK:- routing uses
InferenceMode.ONLY_ON_DEVICEwith Chrome's built-in model, its JSON output held to the team list withresponseConstraint, andinitializeDeviceModel()to download the model on a click; - the check uses
InferenceMode.ONLY_IN_CLOUDwith Gemini 3.5 Flash-Lite and a response schema (team enum plus reason); - for browsers without the on-device model, an admin switch turns routing into
PREFER_ON_DEVICE, still on masked text, andresponse.inferenceSourcetells the UI where each answer came from.
- routing uses
- App Check with reCAPTCHA Enterprise guards Gemini and Firestore; a debug token is used only in development.
- Anonymous Authentication gives every visitor a private desk.
- Cloud Firestore stores each desk's masked examples and routing log, with rules that only allow the owner and the expected fields. Its offline cache keeps examples available, so on-device routing works without a network.
- Remote Config holds the admin switches: cloud model, how many examples go in the prompt, whether to escalate on disagreement, a spot-check rate for confident tickets, cloud fallback routing, the starter bank size.
- React, TypeScript and Vite; unit tests (Vitest) and browser tests (Playwright) with a stand-in for Chrome's model that check, among other things, that no personal detail ever reaches a prompt.
What we measured
On 80 held-out synthetic tickets, with the app's own prompts and masking:
| Past tickets on the desk | 20 | 60 | 120 |
|---|---|---|---|
| Tickets that never left the browser | 14% | 25% | 40% |
| Accuracy, hybrid | 68% | 68% | 80% |
| Accuracy, Gemini on every ticket | 69% | 75% | 85% |
| Accuracy, on-device model alone | 51% | 50% | 55% |
With 120 examples, 4 in 10 tickets never leave the browser, for 5 points of accuracy against sending everything to
Gemini. The unsure check catches 81% of the on-device model's mistakes. Gemini also improves with the desk's own
examples (69% to 85%). The full write-up, raw results and the harness are in the repo (eval/RESULTS.md).
Challenges
- The on-device model alone is not accurate enough for this task (about 50-55% on masked text). The design had to get its value from knowing when to trust it, not from hoping it is right.
- Our first hybrid numbers were too good: they paired on-device answers from a small bank with cloud answers that had seen all 120 examples. We re-ran everything with matched bank sizes and the app's exact prompts, and corrected the write-up.
- The dev laptop has no supported GPU, so we ran Chrome's model on the CPU (about 7 s a ticket).
- The Gemini free tier allows 15 requests a minute; the app paces and retries with a clear message.
Accomplishments we're proud of
- A complete help-desk flow, not a demo prompt: queue, review, masking you can see and extend, confirm, learn.
- Honest, reproducible numbers with confidence intervals, including where the hybrid loses to all-cloud.
- Raw ticket text never leaves the browser, and tests check it.
What we learned
- Agreement between a small model and simple retrieval is a cheap, useful confidence signal.
- Local examples help both models: they teach Gemini rules it cannot know.
What's next
- One shared example bank per help desk instead of per user.
- A learned masking model for names in odd positions, on device.
- Trying it on real (consented, de-identified) tickets.
Built With
- chrome-built-in-ai
- cloud-firestore
- firebase-ai-logic
- firebase-app-check
- firebase-authentication
- firebase-hosting
- firebase-remote-config
- gemini
- playwright
- react
- recaptcha-enterprise
- typescript
- vite
- vitest