Some research online eventually yielded this (not very easy to find) thread on the subject matter on Brogue's official forums: http://brogue.createforumhosting.com/your-monkey-can-now-what-t73.html. The important part is Pender's post (the developer of the game), the sixth one from the top, which I'll paraphrase.
Allies gain experience based on your exploration. With enough experience, and by observing specific kinds of enemies in battle as they die, they eventually gain the ability to "absorb" the ability. In the case of Trolls, this is done by eating them. Within a few turns of the death of the enemy, your ally can go absorb the foe and gain a special ability possessed by that foe. As they level up, they eventually can choose to absorb new qualities.
The full list of abilities to gain are as follows. It can only gain abilities from enemies based on what that enemy can do - hover over an enemy with the mouse to check what options are possible:
- Invisibility (there is almost no positive to this, avoid it like the plague)
- Flying
- Immune to Fire (one of the most useful)
- Reflects Magic (very risky)
- Can cast Healing (it can only target you or your other allies)
- Can cast Haste
- Can cast Blink (another very useful one)
- Can cast Negation
- Can cast Lightning Bolt (there's no such thing as immune to lightning)
- Can cast Fire Bolt (one of the most dangerous enemies in the game is immune to fire)
- Can cast Slow
- Can cast Discord
If your ally is devouring something for an ability you don't want or if you would like to try a different beast, you can interrupt your ally by moving into its square while it is eating.
As of version 1.6, hovering over your ally will inform you if they are ready to absorb a new trait.
Your allies do appear to be able to lose acquired traits. While it happened off-screen for me, I'm pretty sure it happens due to being subject to a Negation effect such as by a scroll or spell.