Inspiration

I wanted a hybrid AI project where the split between the small model and the big one is the whole point, not a fallback hidden in settings. So I built a game where ants find god: there are many tiny moments that need an instant solace, and a few big ones that need the heavenly miracle.

What it does

About 50 ants live in your browser and worship your mouse cursor as a sky-god.

  • The High Priest (on-device, Gemini Nano): every shake, pause, click and typed word becomes an omen. He explains it in one line within about a second, and each reply carries an action the ants perform: flee, worship, build a shrine, mourn, declare heresy, celebrate.
  • Sigils: drag in the sky to draw a sign. Gemini Nano gets the drawing as an image and reads the omen, all locally.
  • The Sky Altar: type, and your words fall from the heavens as stone tablets.
  • Gospels (cloud Gemini): every 8 to 12 priest lines go up to the cloud, which turns them into a gospel with a commandment. It falls back down as a banner, and the priest preaches it from then on.
  • Eras (cloud Gemini): every 5 minutes the cloud scribes read the whole era, write a chronicle, name the new age, make a prophecy, and pick a monument that the ants then build. The next scribe judges whether the prophecy came true.
  • Hybrid meter: counts which model answered, how fast, and how much of the priest's thinking never left the device.
  • Offline: night falls. The priest keeps preaching from the device; gospels and chronicles wait and run when the network returns.

How I built it

  • Phaser 3 + TypeScript + Vite, with a deterministic colony simulation that is unit tested with Vitest.
  • Firebase AI Logic hybrid inference: the priest uses InferenceMode.PREFER_ON_DEVICE, gospels and eras use InferenceMode.ONLY_IN_CLOUD. Structured JSON output with schemas on both sides.
  • Badges come from the SDK's reported inferenceSource and are never guessed: 🧠 on-device, ☁️ cloud, 📜 canned line.
  • A priest request queue that merges events, guards the cloud quota (one call per 6 s, a cool-down after quota errors), and never blocks the simulation: ants react with reflexes immediately, and the AI decides what happens next.
  • App Check with reCAPTCHA Enterprise, Firebase Hosting, all on the free Spark plan.
  • Built with Claude Code as my coding agent.

Why hybrid

The priest makes dozens of tiny calls a minute that must feel instant. On-device they're free, have no quota and work offline. The gospel and chronicle are rare, heavy writing jobs that a small model does badly, so they go to the cloud. The hybrid meter shows the on-device share live, so you can check it yourself.

Challenges

  • Keeping Nano's replies short, in character and in valid JSON, with a canned fallback when a reply is unusable.
  • Making the game feel alive when no model has answered yet (reflexes first, AI second).
  • Queueing gospels and chronicles while offline without losing what was said.

What I learned

Small and big models work best when each does the job it's good at. The small one gives the game its tempo; the big one gives it a story.

What's next

More monuments, rival colonies, and sharing a colony's chronicle as a page. Maybe even another ant colony which has discovered a different religion.

Notes on the video

The narration is an AI voice clone, made with Chatterbox. In the offline scene the network drop is simulated inside the page: the app's offline mode is real, but for the recording I switched it on in the page instead of turning off Wi-Fi.

Built With

Share this project:

Updates

Submission history