Inspiration
Reflection tools ask for the most private thing a person has: what they wrote about a hard choice. Most of them send it straight to a server. We wanted to show that the private part can stay on the device, that the heavier cloud model can be kept for what a person chooses to share, and that an AI can help someone reflect without ever grading them.
What it does
Held Choice walks you through six moments from L. Frank Baum's The Wonderful Wizard of Oz (1900, public domain):
- the Lion at the Kalidah ditch
- the Scarecrow's plan at the log
- the Tin Woodman and the beetle
- the poppy field
- the Golden Cap
- the humbug behind the screen
Every choice costs something, and none is marked right. After you choose, the load rises: the cost of your choice gets heavier, and you decide whether to keep it or change it.
After each moment you can write a private note and ask for a private reflection, written on your device. At the end, the grey sky over home holds a colour for every choice you kept under load. Grey patches show where the load moved you, which is information, not a mark against you. You can then opt in to a longer summary of the pattern you walked.
How we built it
Held Choice routes inference by how private the input is, using Firebase AI Logic hybrid inference:
| Job | Input | Mode | If unavailable |
|---|---|---|---|
| Private reflection | Your choice plus your private note | ONLY_ON_DEVICE (Gemini Nano in Chrome) |
A plain-code reflection; nothing is sent |
| Longer summary | Only the six choices, after a consent box | PREFER_IN_CLOUD (falls back to on-device offline) |
A clear "not available" message |
ONLY_ON_DEVICEis the privacy guarantee. It throws rather than falling back to the cloud, so a private note cannot leave the machine by accident. The app catches that and writes the reflection in plain code instead.- Every response shows where it was written ("on this device", "in the cloud", or "by plain code"), using the SDK's
inferenceSource. initializeDeviceModel()is called on the user's first click, as Chrome's user-activation rule requires.- App Check with reCAPTCHA Enterprise protects the Gemini API and is enforced for AI Logic.
- The AI never judges. A system instruction forbids grading, and
js/guard.jschecks every generated text before display. Scores, percentages, "right choice", "you should have" and verdicts on the person are blocked, and the plain-code reflection is shown instead, with a note saying why. - The rules of the walk are plain, tested code (
js/hold.js): choose, the load rises, keep or change. No number about the person is ever produced. - Plain HTML, CSS and JavaScript with no build step. The Firebase JS SDK 13.4.0 loads from Google's CDN. Hosted on Firebase Hosting.
Challenges we ran into
- Keeping the private path private.
PREFER_ON_DEVICEwould quietly send a note to the cloud whenever the device model was missing. UsingONLY_ON_DEVICEfor the note, with a plain-code fallback, made "private" something the code enforces rather than something we promise. - Keeping the AI out of judgment. A prompt alone is a request, not a guarantee, so we added a code guard with tests. The tests include planted failures, to prove the guard can catch them.
- The inference badge. In SDK 13.4.0,
inferenceSourcecomes back as lowercasein_cloudrather than theIN_CLOUDshown in the docs, so our first badge said "written by plain code" for cloud text. Normalising the value fixed it. - Keys and a public repo. The Firebase web config lives outside the repository. A staging script runs the checks first, then assembles the deployable site in a separate folder, so the public repo never holds a key.
Accomplishments that we're proud of
- A hybrid design where the inference mode carries the privacy promise.
- An AI feature that helps someone reflect and is provably kept from grading them.
- Story material adapted directly from a public-domain book (silver shoes, not ruby), with every choice given a real cost.
What we learned
- Hybrid inference is most useful when routing follows the data, not just speed or cost.
- On-device inference is single-turn and limited to 9,216 tokens, which suits short, private reflections well.
- Showing the user where each response was generated builds more trust than any privacy paragraph.
What's next
- Streamed reflections.
- More public-domain stories.
- A group mode where each person's reflection stays on their own device and only consented summaries are shared.
How Firebase AI Logic is used
js/ai.jsimportsgetAI,getGenerativeModel,GoogleAIBackendandInferenceModefromfirebase/ai(SDK 13.4.0). It creates two models:- The reflection model uses
InferenceMode.ONLY_ON_DEVICEwithonDeviceParams(system prompt, English in and out). - The summary model uses
InferenceMode.PREFER_IN_CLOUDwithinCloudParams(gemini-3.5-flash-lite, system instruction, output cap).
- The reflection model uses
- The code calls
initializeDeviceModel()on a user gesture andgenerateContent()for each request, and readsresponse.inferenceSourceto label each result.
Built With
- chrome-prompt-api
- css
- firebase-ai-logic
- firebase-app-check
- firebase-hosting
- gemini
- gemini-nano
- html
- javascript
- recaptcha-enterprise