DEV Community

devthinker
devthinker

Posted on

I wired a real fruit fly brain to reply to my emails (no cloud API)

Last week Google/Janelia released the complete wiring diagram of a fruit fly
brain, and someone made a demo where it replies to emails. I wanted the same
genre, but with a catch: no cloud, no chatbot, and an honest number I was
willing to show even if it was bad.

This is what I built: FLYMAIL. A web app where a real fruit fly brain's
wiring diagram — the FlyWire female connectome, 139,255 neurons and
15,091,983 synapses — runs as a live simulation in your browser on WebGPU,
reads your email, and decides how to reply to it.

How it actually works

The architecture is three frozen, deterministic pieces. No LLM in the brain
path, ever.

1. Email → brain. A small deterministic encoder maps the email (tokens,
language, salutation, urgency) into the sensory input channels of a vendored
WebGPU LIF engine. Nothing randomized at runtime — no Math.random, no
timestamps in the pipeline.

2. The brain. 1,000 steps of spiking LIF dynamics on the actual connectome
graph. On my M4 Pro this takes ~4 seconds and fires ~563,000 spikes. The brain
is frozen — fixed synapses. I don't pretend it's "thinking". It's a dynamic
system I'm reading.

3. Brain → decision. I walk every email through the real sim headlessly
(puppeteer), collect a 16-dim feature vector (per-class spike rates, motor
L/R asymmetry, global rate bands), and fit a logistic regression readout
on them. That model is committed to the repo as JSON. The browser does
matrix-vector inference only. It outputs a plan: category (complaint,
payment, meeting, receipt, digest, personal), tone, length, whether to ask a
question, language.

Then — and only then — the reply text is produced. Two modes:

  • Fly only: the plan selects a prewritten template. Byte-identical reply every time. Same email, close the tab, reopen, same bytes.
  • Fly + LLM pen: the plan becomes a prompt, and a local qwen2.5:7b via Ollama (temperature 0, fixed seed) drafts the words from the plan plus the email's facts only. The fly decides character; the LLM is a pen, not a brain.

The reply stays visually locked until the 1,000 sim steps have passed
through the brain. It's staging, but it's the whole point: the decision
happens in the sim, not in a chatbox.

The honest numbers

  • Classification holdout accuracy: 95.8% (6 categories, synthetic + hand-written emails incl. German).
  • Why 95.8% isn't a lie: a few feature dims are token-overlap shortcuts, so the classification is easier than "a fly understands language". The brain cascade still runs live and still moves the scores. "The fly understands your email" would be a lie. "The fly routes it" is defensible.
  • The LLM reply to a German complaint opened with: "Verstehen Sie unsere Schwierigkeiten mit den Verzögerungen." A 7B model's German. Unedited. I'm keeping it in the results file.

The one number I'm least proud of comes from the same repo: when I trained
the connectome to do a visual task (approximate number sense, dots), it hit
50% test accuracy — a coin flip — and collapsed to "always answer
yellow". That's in the repo too. Honest mediocre results are a better story
than fake numbers, so I'm publishing both.

What it runs on

  • FlyWire v783 connectome (CC-BY, Janelia Research) — the female brain, not the newer MaleCNS. The footer says so.
  • webgpu-fly LIF engine (MIT), vendored
  • Readout fitted with logistic regression in a torch venv (train-your-fly, Apache-2.0)
  • Ollama qwen2.5:7b for the pen mode — or zero APIs at all in Fly-only mode
  • ~120 MB brain blob loaded in the browser, ~1.3 s cached

Everything is open source: code, the trained readout JSON, the mock emails,
the screenshots, results.md with the numbers above, and a
reproduce.sh for the training side.

The fly doesn't understand English. It routes it.


Credits: FlyWire (Janelia/HHMI, CC-BY), webgpu-fly (MIT), train-your-fly

(Apache-2.0). Demo emails are fictional.

Top comments (0)