I observed something curious and slightly frightening the first time I grew yardlong beans: the plants were covered in wasps. Instead of panicking, I did some reading and discovered that yardlong beans have extrafloral nectaries. While flowers produce nectar to lure pollinators, some plants have additional nectar-producing glands in locations other than their flowers in order to lure predators. Many predatory bugs sip nectar in the absence of their preferred prey, so the extrafloral nectaries "bribe" predatory bugs to stick around, thereby protecting the plant from other bugs that might chomp on it. With yardlong beans, the extrafloral nectaries are located where the beans connect to the vine, the inflorescence stalk. These are the same locations where I would see the wasps hanging out. The wasps never bothered me when I picked the beans because they were fat and happy, full of nectar. And I mean, c'mon, it's not like I tried to pet them or anything, I'm not daft.
It turns out, lots of plants have extrafloral nectaries and many of them are common to edible gardens. The reason I'd never noticed before on other plants is because the primary predators attracted by most extrafloral nectaries are ants, which are tiny and don't fly. Ants are generalist predators that will patrol and fiercely defend a plant against other bugs that would try to eat the plant.
It's not just yardlong beans, but most beans including green beans, lima beans, and black-eyed peas that have extrafloral nectaries. And so do sunflowers, Jerusalem artichokes, sweet potatoes, and pretty much all squashes and gourds. And fruits such as passion flower, elderberry, apples, pears, strawberries, quince, and stone fruits: peaches, apricots, plums, and cherries.
It's truly fascinating that plants and bugs have evolved such complex relationships with each other. While plants cannot run away to escape being eaten, they can still fight back. It blew my mind when I learned that plants can "scream for help" with chemical signals. And now I know that they can also recruit bodyguards with extrafloral nectaries.
That is, until the bug partners betray their relationship to the plant (oooh, drama!), as in the video below: