I'm especially surprised a tiny milligram worth of brain is able to provide such high level functions and coordination. I'd normally expect all those neurons would be occupied fully with processing visual stimuli, smells and coordination limb movement alone.
I guess just hard to tell how much of that is attributable to cognition inside the brain of each ant, and how much is network effects with each ant responding in individually stupid ways to the pheromone (and other) signals they create.
Each ant could be very dumb while the system of ants as a whole are quite "smart" (I.e. exhibit complex and interesting behaviours).
But adaptions also happen by evolution and (very speculatively) might also happen at the colony level by it changing its responses somehow. E.g. I could imagine an ant colony suddenly faced with many attackers adapting by breeding more soldiers.