I'm not sure this mechanism is fully known, however during the AGB phase we observe that some stars begin to pulsate (Mira variables). The systematic compression and expansion causes material to "bunch up" making the formation of molecules (and dust etc.) easier. These trap the outgoing flux and essentially drive a strong wind.

In very massive stars, the gravity at the surface is weak and the radiation strong, so the matter gets blown away.

As astrorob says, in AGB stars molecules form as the star pulsates. This is due to the dredge-up of carbon and/or oxygen from inside the star. The molecules form into grains which are easily blown outwards by the stellar radiation.