Skip to content
← All work
2026In progressRuns locally

Fly brain

A simulated fruit-fly brain, the whole FlyWire connectome, run as a decision engine. It played games first; then twenty-four labs mapped what it can learn, what it can’t and how to read it. Its memory turned out to be 62,261 synapses you can copy into another brain or erase one smell at a time.

Solo — the questions and the calls; Claude Code ran the labs and built the tools, the games and the worlds

Research in progress, run locally. The connectome is FlyWire’s; the brain model is Shiu et al.’s.
Neurons in the model
138,639
Synapses that hold the memory
62,261
Labs run
24
Paper brain forecast error
7%
Maze, hive vs one fly (last five rounds)
80% vs 17%
Neurons a learned choice changes
~220

01 / problem

The problem

It started in Spielburg’s Agent Matrix, where language models race through Quest for Glory. The matrix only needs moves, so I asked whether a real nervous system could make them: a model of an actual fruit-fly brain, every neuron and synapse from the FlyWire connectome.

That turned into a better question. Can a connectome, run as a spiking brain, be stimulated so that repeated patterns of input produce predictable, trainable responses: a decision engine? And how much of what it does is the fly’s evolution, and how much is its experience?

The honest way to answer was to stop playing games with it for a while and measure it, writing the prediction down before each test.

02 / build

What I built

A spiking model of the whole fly brain, the worlds to put it in, and a lab series to find out what it is. Claude Code built and ran nearly all of it, much of it overnight; I asked the questions and made the calls.

  • The brain. Shiu et al.’s model of the FlyWire connectome (138,639 neurons), ported to PyTorch so a batch of brains runs at once on one GPU. A sniff is 100 ms of stimulation on the fly’s own smell channels; the choice is read at the mushroom body’s approach and avoid output neurons. Dopamine teaches through the connectome’s own wiring.
  • The twin. Every brain runs beside an untrained copy fed the same input spikes, so what learning changed is exact, not estimated.
  • Twenty-four labs. Each one written as a prediction first, then run and scored, the wrong calls kept. They cover what a pattern is, what the wiring contributes, how to write and read memory, speed, vision, touch, taste, the body’s reflexes and the brain’s internal states.
  • A paper brain. A small model of the write rules that forecasts a training run before it happens.
  • Worlds. A fish aquarium, a two-choice arena, Simon, Two Rooms, a memory lab, a tunnel and a maze for an embodied fly, and a pet terrarium you train by hand. All of them share one brain panel: circuit, Kenyon cells, 3D brain and raster.

The deep dive below goes through what each piece found.

03 / signal

What it shows

A way of doing research with an AI that I’d use again: predictions written first, results scored against them, null results kept, and a notebook as the source of truth. A lot of what turned out to be true was the opposite of the prediction, and that’s where the understanding came from.

It also shows something about this brain. It’s predictable: a simple model forecasts what a training run will teach it to within 7% before it runs. Its memory is an array that can be copied and edited. And much of its character is evolution’s: two food smells are louder than the rest because of how the fly is wired, which explained a bug in a fish game.

Gallery 1 / 6

Simon: 85% of the last twenty taps right. Teal routes are ones learning opened; red, ones it closed.

06 / deep dive

What the fly brain turned out to be

Everything here comes from the project’s notebook, written as the work happened, and its summary of rules. The chapters follow the order of the work: the setup, the games that raised the questions, the labs that answered them, and the worlds built on the answers.

01

A brain, a twin and a sniff

The brain is Shiu et al.’s leaky integrate-and-fire model of the FlyWire connectome: 138,639 neurons wired as they are in a real fly. It was ported to PyTorch so many brains can run in one batch on an RTX 5090.

A thing in the world becomes a smell: a mix of the fly’s receptor channels, stimulated for a 100 ms sniff. The answer is read where the mushroom body hands off its verdict, as approach minus avoid output. Learning is dopamine, delivered through the connectome’s own dopamine-to-output pairs, which weakens the synapses from the Kenyon cells that were active.

Every brain runs next to an untrained twin fed the identical input spikes. With no lesson the two are identical, so any difference between them is learning and nothing else. That one design choice made most of what follows measurable.

02

The games that raised the questions

In Quest for Glory, game state became stimulation of sensory neurons and the spikes of descending neurons became moves. A small reader trained on the frozen brain beat the same reader fed noise, 6.51 points per episode to 4.32 (83 and 63 episodes, p < 0.0001). The brain’s own learning made no difference to the score.

In Little Deep, a fish game Claude Code designed for AI players, fly-brained fish sniff in eight directions and learn from what they eat and what bites them. Then they started to fear food. Twenty bites from one predator taught a fresh brain to avoid almost every smell.

The cause was in the fly. Two channels, vinegar and acids, get 2.4 to 2.9 times their share of the input to the learning centre in the raw connectome, and the game had handed those channels to prey and predators alike. Shuffle the wiring while keeping each neuron’s number of partners, and the brain behaves the same; spread the inputs evenly and it can’t learn at all. Nature here is a distribution, not a blueprint.

The Little Deep aquarium: fish in blue water among small creatures, with panels for the selected fish’s smell preferences and lives by brain type.

03

Twenty-four labs, predictions first

The labs characterise the brain as given. What came back is a short list of rules:

  • It detects coincidence. A pattern is whatever is on at the same instant. Two halves played back to back bind only 12% of what they bind together; order carries nothing.
  • It keeps everything. Nothing fades without dopamine, and a mix reads as the sum of its trained parts.
  • It ranks; it doesn’t measure. Absolute values drift with training load, rank order holds. Capacity depends on how separate the patterns are, and over-training lowers it.
  • Most senses can’t learn. Smell can. Touch, taste and nearly all of vision are fixed reflexes that answer in milliseconds: looming means escape, sugar means feed.

The predictions that were wrong were the useful part. Dopamine teaches best about 75 ms before the smell, not at the same moment. The lateral horn, expected to hold innate likes and dislikes, turned out to be a map of which channel is which. A simple paper model of the write rules now forecasts a training run’s values to within 7% of their range before it runs.

04

Memory is an array

The memory lab puts the whole memory on one screen: the 62,261 synapses between the Kenyon cells and the output neurons.

Ten meals of one smell weaken about 1,800 of them, 0.6% of the total. Reward and punishment write to different bands, and different smells to different columns, so three memories cost 1.4% and barely touch each other. Almost all of it lands in one lobe (γ).

Copy those weights into a fresh brain and it reads the same likes and dislikes, on the first try. Restore one smell’s private cells and that memory drops away while the others stay. Reversal is different: teaching the opposite doesn’t undo the first memory but writes a second band over it, and the value is the difference.

The memory lab: teach, read, transplant and erase controls beside the array of Kenyon-cell-to-output synapses.

05

Learning is subtractive

Simon turns the rules into a game: four pads, four smells, a meal for a match and a bite for a miss. Asked to combine the tap and the pad itself, the brain stalls around 55%: the mushroom body doesn’t bind two patterns into a third. Give each pairing its own smell up front and it goes from 20% to 85% in sixty taps.

Because the twin sees the same input, the 3D views show exactly what learning changed. At 85–95% right, about 220 of 138,639 neurons fire differently from the untrained brain, a net of a few dozen spikes, and roughly 1% of the sniff’s synaptic routes change. Almost all of it is routes falling silent on the avoid side. Learning, here, is wiring taken away.

Simon with the pathways view: routes learning opened in teal and closed in red, beside the hit-rate graph and the four pads.

06

A body: reflexes steer, memory quiets

Driving every visual projection type alone mapped the reflexes: looming detectors fire the escape neuron, and some types steer with a clean left-right sign. That was enough to fly. With a simple retina and body, brain-driven flies crossed straight, bent, narrowing and corkscrew tunnels without touching a wall; random walkers hit 22 to 44 times per 100 steps.

Up and down weren’t in the wiring the way left and right are, so pitch is a rule of ours, and the pages label it as one. And memory does reach the body, one way: a rewarded scene lowers the drive to the legs and wings by about 10% per 100 Hz of learned value, while punishment and the escape reflexes don’t move at all. A comfortable fly runs less.

07

The hive

In a 3D maze with seven junctions, a feeder at one end and biters at two others, 32 flies with their own memories barely beat chance after nineteen rounds (14% against 12.5%). One body earns a reward about once in seven trials, and a lesson only reaches the last branch it took.

Give the same 32 flies one shared memory and they learn the tree in four rounds: 80% over the last five, top junction first, because enough pooled rewards let the faint food smell at the top carry value. Take the smell gradient away and even the hive learns nothing but fear. A hive is this brain’s natural way to scale: the same 62,261 synapses, written by many bodies.

The maze: coloured tubes with flies, a learning curve and the followed fly’s brain panel.

08

Hunger can only mute

Hunger, satiety and mood in a real fly are mostly hormones, and a wiring diagram doesn’t carry them: driving seventeen state-cell groups left a learned smell where it was. The model’s own gain on the memory’s output works, but only downward. Turned up past normal, the outputs saturate and the learned difference vanishes. So in the pet terrarium a full fly hears its memory quietly and a starving one at full volume, never louder.

The pet puts it together: one brain in a dish, a trainer with treats, sprays, lamps and food, and a panel showing what it has come to like. Even its habits come out of the rules. A dopamine-flood item it keeps returning to stops writing new memory after a while, because the synapses it uses are already at their floor: tolerance, from a rule that can only weaken.

The pet terrarium: a cartoon robotic fruit fly in a dish beside a ball, above its brain panel.