Dev.to AI 🤖 Ai 👁 0 📖 5 min read

I built an offline AI assistant for cabin crew on a Ditto mesh (Raspberry Pi + iPhone + Android)

At 35,000 ft there's no reliable internet. So what happens when a flight attendant needs the nut allergy procedure right now, and the answer lives in a 200-page manual? I wanted to find out whether a handful of phones a

I built an offline AI assistant for cabin crew on a Ditto mesh (Raspberry Pi + iPhone + Android)

At 35,000 ft there's no reliable internet. So what happens when a flight attendant needs the nut allergy procedure right now, and the answer lives in a 200-page manual?

I wanted to find out whether a handful of phones and a Raspberry Pi could answer that, with no internet and no router at all. The result is Galley Brain: a Pi in the galley runs a local LLM over the crew manuals, and the crew's iPhones and Android phones form a peer-to-peer mesh with Ditto. Ask a question on any phone, even one that's out of the Pi's range, and a cited answer streams back word by word, hopping through other crew devices.

A question asked out of the brain's range hops to the Pi, and the answer streams back piece by piece

Prefer video? Here's the 4-minute explainer:

The airline (Aerolume) and its manuals are fictional and synthetic. This is an independent project, not affiliated with Ditto.

What's in the box

  • The brain: Raspberry Pi 5 (8 GB) running Node.js with Ditto's JS SDK 5.2, llama.cpp with Qwen2.5-1.5B-Instruct (Q4_0), and bge-small embeddings for retrieval over 34 manual sections.
  • Crew apps: SwiftUI on an iPhone 15 Pro and Kotlin + Jetpack Compose on a Pixel 9a. Notes, questions with seat and zone, one-tap "quick question" chips, and a mesh debug view.
  • A live dashboard served by the Pi: who's linked to whom, over which transport, and the path an answer is taking right now.
  • Everything is open source: github.com/midopooler/galley-brain.

The data model is three collections: notes, questions and answers. Every device subscribes to all three. That one decision matters more than anything else in the design (more below).

How an answer streams across a mesh

The brain watches for pending questions, claims one, retrieves the matching manual section, and starts generating. It doesn't send tokens as messages. It writes them into the answer document, and Ditto syncs that document to every device.

The trick is how it writes them. Instead of rewriting one growing text field, it appends pieces to a map under sortable keys:

UPDATE answers
SET chunks.c0007 = :piece, chunkCount = 8, updatedAt = :t
WHERE _id = :id

It flushes every ~250 ms or 16 tokens, whichever comes first. In Ditto v5, objects are maps that merge field by field, so pieces never overwrite each other, and the batching keeps updates small enough for Bluetooth LE. Phones just sort the keys and concatenate. When the answer is done, the brain writes the full text and its sources.

The moment I built this for: break the mesh mid-answer

On a table, every device is within Bluetooth range of every other, so the dashboard has a simulated range switch. It makes the Pi refuse direct links to chosen phones (via Ditto's connection request handler), so their traffic has to hop through other devices.

Then I put the phones in airplane mode (Bluetooth on, no Wi-Fi network), asked a question from a phone two hops away, and switched off the relay carrying the answer while it streamed.

An answer streams through two relays; one dies and the answer keeps arriving through the other

The answer kept coming. Ditto doesn't route a stream down one path: every piece syncs over every link, so the second relay was already carrying it. We tried it both ways: killing the Mac relay's process, and turning off the Pixel's Bluetooth. Both times the far phone got the complete answer, and the brain dropped the dead relay from its view 6.7–9.9 s later.

Numbers from our demo

Our own end-to-end timings on this hardware, not a benchmark:

What Measured
First words on a phone 2 hops from the Pi 2–7 s
Extra time added by 2 mesh hops ~0.2–0.3 s
A note crossing 2 hops (warm links) 2.6–3.5 s
Dead relay dropped from the mesh view 6.7–9.9 s (the answer still completed)

Nearly all the wait is the Pi reading the prompt and generating, not the mesh. Two llama.cpp changes made the biggest difference on the Pi 5:

  • Q4_0 instead of Q4_K_M: llama.cpp repacks Q4_0 for the Pi's ARM kernels. Prompt reading went from 51 to 96 tokens/s, so first words came much sooner.
  • 3 threads instead of 4: llama.cpp waits on its slowest thread every token, so on a 4-core Pi anything else running stalls all four. Three threads generated faster (11.0 vs 10.1 tokens/s) and left a core free for the dashboard.

What I learned about Ditto v5 (the hard way)

  1. A device only relays what it subscribes to. If the phone in the middle doesn't subscribe to answers, answers never cross it. So every crew device subscribes to everything.
  2. Subscriptions and observers are different jobs. A subscription says what other peers should send you; an observer watches your local store. Subscriptions reject ORDER BY and LIMIT; sort in the observer.
  3. Don't name your config DITTO_*. Ditto's core reads every DITTO_-prefixed environment variable as its own system parameter.
  4. Sync scopes reset on every launch. ALTER SYSTEM SET USER_COLLECTION_SYNC_SCOPES (to keep data off the cloud) has to run each time, before sync.start().
  5. Development mode needs one online sign-in per device, then works offline; the SDK schedules a certificate refresh about 3 days later.
  6. iPhone ↔ Android talk over Bluetooth only with the router off. iPhone ↔ iPhone add Apple's peer-to-peer Wi-Fi; the Pi is Bluetooth-only.
  7. Unquoted DQL field names can't contain - or start with a digit. Wrap them in backticks.
  8. One database ID is one mesh. Any app or test on the same database links up and shares collections by name.
  9. On a Mac, Node + Bluetooth gets killed unless the parent app declares Bluetooth usage. Use LAN or AWDL for Mac test peers.
  10. Ditto keeps the links it has. It won't open a new Bluetooth link as a fallback when Wi-Fi drops, so make sure backup paths exist before you need them.

Turning the lessons into an agent skill

Most of those cost me real debugging time, and coding agents love writing v4-era Ditto code. So I packaged everything into a Ditto v5 agent skill (skills/ditto/). It has the mental model, a build order, the mistakes table, and Node/Swift/Kotlin skeletons taken from code that ran on my devices.

To test it, I gave a fresh Claude Code session nothing but the skill: no web, no docs, no access to my repo. The task: build a two-device peer-to-peer notes app. It took about 8 minutes, passed all 7 checks (v5 APIs only, auth before sync, the right subscriptions, idempotent writes, data kept off the cloud, no secrets in git, two-machine instructions), and its code then synced between my Mac and the Pi with both offline. The run also caught three gaps in the skill, which I fixed. The full record is here.

What's next

  • A run with the router physically unplugged, and more devices on the table.
  • A Realm → Ditto migration kit: model parser, DQL equivalents and a guide that's honest about the gaps.

If you're building anything offline-first, at the edge, or with local AI, I'd love to hear what you'd do with this. The repo has the demo script, the explainer animations and the verified API notes.

📰 Read the original article on Dev.to AI

Originally published by Dev.to AI. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.