What are the ants underneath leafs in my garden doing?
From what you described, it seems to me the &quot;fruitflies&quot; are aphids and the ants are farming them. This is a widespread and common phenomenon known as ants-aphid mutualism.
P.S.
I elaborate a bit. Aphids feed on plant sap, rich in sugar, which they don't digest completely. The excretions (poop) are thus still rich in sugar (you may have noticed how your car windows get sticky sometimes under tress - that's aphids poop, I believe). Some ant species co-evolved with particular aphids and collect their excretions, a valuable sugary energy source. In turn, ants protect aphids from predators and they move them around to cover other good plant spots for aphids to suck sap and even move them to different plant individuals. This mutualistic interaction between aphids and ants is quite common and causes a lot of economic losses to the agriculture sector.
The behavior you observed of an ant attacking aphids was probably more the ant checking them and trying to evoke a pooping response. Sometimes they get them between their jaws and carry them around. Aphids also have quite complex social structure, with an optimal spatial organization. Hard to say if ants are moving them around to reach this optimal &quot;farm density&quot; or for other reasons.
TL;DR ants farm aphids as humans farm cows. When ants interact with aphids they are mostly checking them and trying to get their sugary poop.
/Emilio