Neuroscience & AI
Fly Brain: a Telegram bot on a real connectome
A bot that runs the full wiring diagram of a fruit fly brain: you tap a button, it simulates the whole brain, code decides what the fly did, and an LLM agent explains why.
- Client
- Own research project
- Format
- Practice case
- Stack
- Python, FastAPI, numba
- 138,639neurons and 54.5M synapses: the whole brain, no simplified wiring
- 0.3–2.5 sper whole-brain simulation, 10 runs of 1 s each
- 86automated tests: kernel accuracy, validation, every scenario

The problem
The FlyWire team has mapped the entire brain of a fruit fly: 138,639 neurons and 54.5 million synapses. My goal was to make this science understandable to someone with no biology background, and to make it obvious that the answers come from a brain model, not from a chatbot making things up.
The bot itself speaks Ukrainian, so the screenshots below are in Ukrainian.
The solution
A Telegram bot where this wiring diagram works as a model. The user taps a button, for example “swat the fly with a newspaper” or “give it sugar”, and the bot:
- runs a spiking simulation of the whole brain;
- shows what the fly did: escaped, started feeding or cleaned its antennae;
- sends a video with a schematic fly on the left and the signal running through its brain on the right;
- adds a neuron report with a brain map and explains why it happened.
Code decides the verdict, not the LLM. What the fly did is determined by three output neurons validated in the Shiu et al. paper (Nature, 2024). The LLM only explains the result and cannot invent neurons.
“Break the fly”. The same stimulus goes to a normal brain and a modified one. Switch off 2 neurons and the fly stops feeding. Switch off 4 and it fails to take off, so the newspaper lands on it. Cause and effect are visible.
Three modes:
- “Guess what the fly does” runs with no LLM: you guess first, then the simulation runs and code checks your answer.
- “Break the fly” shows two flies side by side, before and after.
- “Experiments”: an LLM agent (OpenAI or Claude) with seven tools answers questions using simulation, path search in the synapse graph, comparison and images.
Speed. In the standard Brian2 simulator a whole-brain run takes minutes, which is too slow for a chat. I rewrote the model in numba with exact integration, and neurons that are guaranteed not to fire are not stepped at all. A test confirms the spikes match the full calculation exactly.
The result
| Brain in the simulation | 138,639 neurons, 54.5M synapses |
| Simulation | 0.3–2.5 s (10 runs × 1 s of brain time) |
| Video rendering | 3–4 s |
| Bot reply with video | 5–17 s |
| Automated tests | 86 |
The paper’s results are reproduced: sugar triggers the proboscis with a sigmoid dose-response, bitter suppresses feeding, and touching the antenna triggers antennal grooming.
Honest limitations
This is not an “uploaded mind” or a copy of a fly. It is a wiring diagram plus very simple neurons, with no neuromodulation, learning or body. The fly in the videos is a schematic drawing; the simulation decides what it does and when. The bot says so in every answer.
FlyWire data is licensed under CC BY-NC 4.0, so the project is non-commercial.
How the work went
How work on this project went, from understanding the problem to launch and improvements.
- 01
Discovery
Studied the Shiu et al. paper (Nature, 2024) and the FlyWire v783 data: which output neurons are validated for behaviour, and what the model can honestly measure and what it cannot (flight, freezing, smell).
- 02
Solution design
Split the system into two services: a Python simulator with an API and a TypeScript bot. Code decides the verdict from three validated neurons, the LLM only explains it, and the game runs with no LLM at all.
- 03
Build
Rewrote the neuron model in numba, built the "fly + brain" videos, path search in the synapse graph, an LLM agent with seven tools for OpenAI and Claude, and a button-only menu.
- 04
Testing
86 automated tests: spikes match the full calculation exactly, the paper's results are reproduced, and every game and "break the fly" scenario is checked across several random runs.
- 05
Launch
One-command deployment with Docker Compose; the FlyWire data downloads on first start. The bot replies with a video in 5–17 seconds.
- 06
Optimisation
Cut a whole-brain run from minutes to 0.3–2.5 s and video rendering to 3–4 s. Runaway activity is capped by an event budget, and for smell, where the model is unstable, the agent honestly uses path search instead of simulation.
Videos and screenshots
- The fly takes off the moment the Giant Fiber escape neuron fires in the simulation
- "Break the fly": without 4 PVLP122b neurons the fly fails to take off
- Dust on the antenna: the fly cleans it with its legs
- Sugar: the fly extends its proboscis and feeds
Before / after report: same stimulus, different brains
Neuron report: the most active cell types and where they sit in the brain
Architecture: bot, LLM agent and simulation service
The strongest path in the synapse graph: from smell to movement
Start screen and button menu
"Guess what the fly does" game
Explaining what changed after "breaking" the fly