On the campus of the University of Sao Paulo, Brazil, some trees buzz more than others – which is exactly what behavioural ecologist Francisca Segers had hoped for.

She approaches one buzzing tree. There is a short wax tube extending from a hole in the trunk. Hovering around the opening are half a dozen small yellow-and-brown bees, the source of the gentle buzz.

Next, Segers reaches into a box she is carrying and takes out a tiny black lump. It is the crushed head of a robber bee (Lestrimelitta limao), freshly killed that morning. She gingerly places the robber bee head on the tube opening, and watches as it slowly rolls down the tube into the tree.

In an instant, a cloud of the tiny yellow-and-brown bees bursts from the tube. "It was just six bees flying at the entrance… then suddenly there were two hundred," says Segers.

These are no ordinary bees, though. Colonies of Tetragonisca angustula, known locally as "Jatai bees", are particularly adept at seeing off enemies. That is because Jatai bees, uniquely, have developed a soldier caste.

Christoph Grüter at the University of Mainz and his colleagues first announced in 2012 that Jatai bees have soldiers. Their suggestion stirred up quite a buzz.

Jatai bees, uniquely, have developed a soldier caste

Of course, we already know that a number of other social animals have evolved a soldier caste: ants, termites, and even some less socially-complex animals like aphids, snapping shrimps and flatworms. Yet until Grüter and his colleagues made their announcement, nobody had found bee soldiers. That fed a general assumption that bees cannot evolve such a class.

One reason why Jatai soldiers went unnoticed for so long is because of the diminutive size of this particular bee.

"It is very difficult to spot the size differences in Jatai bees because they are so small," says Martin Kaercher, who examined the defensive behaviours of Jatai guards for his PhD at the University of Sussex. "I had also not expected size differences in bees."

Kaercher was not alone. Over the years, many researchers have examined the 5mm-long Jatai bees up close, without noticing that certain individuals are subtly, but consistently, larger. Size differences at such scale are almost impossible to spot; at least, without very good vision. Fortunately, Grüter's colleague, Cristiano Menezes at the University of Sao Paulo has an eye for detail.

"We were running a study where we introduced workers from one Jatai bee colony to the nest entrance of another," says Grüter. "Eventually, Cristiano noticed that the guards seemed larger than the workers we introduced."

Robber bees are pirates on wings

Meticulous measurement of more than 300 bees confirmed Menezes's observation: Jatai bees guarding the entrance are 30% heavier than the rest. They also have larger hind legs.

"I was amazed and delighted [to know of Jatai bee soldiers], since we only knew about caste differences in ants and termites," says Kaercher of Grüter's 2012 discovery.

Why might Jatai bees have developed a class of soldiers while other bees apparently have not?

There is no definitive answer, but clues might come from Segers's experiments with the decapitated heads of robber bees. Because it turns out that robber bees pose a very real threat to Jatai colonies.

Robber bees are pirates on wings. They plunder the colonies of other bees – like the Jatai – and raid their stores.

If one robber bee encounters a Jatai colony and returns to its own colony to recruit more robbers for an attack, the result can be devastating, says Segers. "We have lost colonies to robber bees." 

The much larger robber bee usually succeeds in killing the Jatai soldier, often decapitating it in the process

This is why it is in the Jatai bees' best interests to attack a robber scout before it can relay its message. As Segers's experiment shows, the mere whiff of a robber bee's presence is enough to alert the Jatai soldiers. They rush out of the nest and charge at the intruder, flying close enough to lock on to the robber bee with their powerful jaws.

"Ideally, the Jatai bee grabs the wings of the robber bee and doesn't let go," says Grüter, who has witnessed many such fights. Both bees fall out of the sky, the robber grounded by the soldier. They grapple with each other as the robber bee tries to tear away its tenacious attacker.

Eventually, the much larger robber bee usually succeeds in killing the Jatai soldier, often decapitating it in the process. But the dead bee's relentless jaws clamp on to its killer, preventing the robber from flying away.

"The Jatai bees commit suicidal defence, lying on the ground with the robber bee until maybe an ant comes along and [takes] them away," says Grüter.

Jatai soldiers hover around the nest, expanding the defence perimeter and intercepting robber bee scouts before they reach the colony. In addition, Jatai bees seal their nests at night, and use wax and resin on complex nest tunnels to entangle enemies.

Jatai bee soldiers are quite unlike any other animal soldiers we know

It is a surprisingly comprehensive system, which Grüter has described as "one of the most sophisticated defences among social bees".

"I've read that Jatai bees and robber bees overlap greatly in their distribution," says Grüter. "If so, this would mean a long history of co-evolution and arms race between the bees."

Recently, however, Grüter and his colleagues reported that Jatai bee soldiers are quite unlike any other animal soldiers we know.

While ant or termite soldiers do little else but fight enemies, Jatai bee soldiers also partake in civilian duties. They build and clean the nest, nurse the larvae and dry the wax.

What we see in Jatai bee soldiers is counterintuitive

Even more surprising is that in the first half of their month-long lives, Jatai bee soldiers outwork the workers. On average, each Jatai bee soldier performs ten different behaviours to the worker's eight, and each soldier does between 30 and 40% more work than the workers. Most of this work involved nest maintenance.

"We do not know of any other case where soldiers show more diverse behaviours than workers," says Grüter. "In ants, soldiers are specialists that work very little and have a relatively narrow set of behaviours.

"What we see in Jatai bee soldiers is counterintuitive. It goes against the theory of caste evolution that increasing specialisation leads to narrowing behaviour sets."

Maybe there are developmental limits that make it impossible for Jatai bees to evolve extreme soldier types

For now, Grüter and his colleagues can only speculate why Jatai bee soldiers are so versatile and hard-working.

Perhaps Jatai bees have evolved their specialised soldier caste far more recently than other social animals, so the soldiers have not yet evolved to focus all their efforts on fighting.

Or perhaps Jatai soldiers can work like workers do because they are not starkly different in size and shape. The soldiers in colonies of army ants or leafcutter ants dwarf the worker ants like tigers to cats. Jatai soldiers, in contrast, stand next to Jatai workers like horses to donkeys.

"Maybe there are developmental limits that make it impossible for Jatai bees to evolve extreme soldier types," Grüter says.

Those limits might be set by the design of their nests.

All Jatai bees are born in rigid cells of brood combs in the hive centre. Worker bees regurgitate food into each cell, the queen adds an egg, and the worker seals the cell. The egg hatches and the larva eats the provisioned food, developing in the cell until it emerges as an adult.

Soldiers are really just hard-working workers until they reach the entrance

Segers found that Jatai soldiers are reared in specific cells right in the centre of the brood. There the cells are a little larger and receive more food, giving rise to larger and heavier bees. But the size difference is still constrained by the need for the cells in the brood combs to tessellate.

In contrast, ant and termite larvae grow in open space and are fed continuously by their carers, which allows individuals destined to be soldiers to grow much larger.

Scientists call the larger Jatai bees "majors" and the rest of the smaller workers "minors". Jatai bee majors make up less than 6% of the workers. Most end up as soldiers.

But that does not happen until the end of their lives.

Newly-emerged majors and minors alike start work in the brood, deep in the hive. As the workers age, they move further from the hive's centre and switch occupations, dealing with waste, wax and resin. At this stage, majors work a lot more and have a couple more tasks in their repertoire than minors.

The soldiers in colonies of army ants or leafcutter ants dwarf the worker ants like tigers to cats

But by the third week of their short lives, when their workplace moves to the periphery of the hive, minors and majors wear completely different uniforms. Minors forage for food while majors guard the hive, most becoming the soldiers that Grüter and Segers study.

"In a way, soldiers are really just hard-working workers until they reach the entrance," says Grüter. "It makes sense to call them majors, and refer to them as soldiers only when they pick up the defence at the end of their lives."

Majors seem to be an asset to the hive. They outwork minors early in their life, and then later they help defend the hive. But they make up less than one-tenth of the workforce of the hive. So why does a Jatai bee colony not produce more majors?

For one thing, majors are expensive. A juvenile major eats 20% more food than a juvenile minor, and as adults they likely eat more food too. Yet majors do not collect food for the nest.

It appears that Jatai bees can tune their production of majors and minors according to their needs

Furthermore, Jatai bee majors may work more than minors, but nobody has compared their efficiency. "If majors are less efficient, they might not be worth the extra cost," says Grüter.

For a better sense of the value a Jatai colony places on its majors, we simply have to look at the way colonies respond to limited food and threats. In one experiment, Segers moved Jatai bee colonies into areas where competition for food was intense. Five months later, the colonies had adapted by producing smaller soldiers – but minors remained the same size.

In areas where enemy robber bees are rare, meanwhile, Jatai bee colonies deploy fewer soldiers. But when scientists jack up the threat for several weeks, or give the impression of a greater threat by rolling robber bee heads into the nest, Jatai bee colonies build up their army of soldiers.

In other words, it appears that Jatai bees can tune their production of majors and minors according to their needs. Majors – soldiers – are valued most when robber bees are lurking.

This makes sense to Paul Cunningham, an insect behavioural ecologist at the Queensland University of Technology in Brisbane, Australia, who has documented a four-month-long war between Australian stingless bees. He thinks that enemies play a key role in shaping the evolution of a defence system.

"If your enemy are larger bees and you are more likely to overpower them with individual strength, then having strong soldiers is an advantage," says Cunningham. "This is the case with Jatai bees against robber bees."

Perhaps other bees have also evolved hard-working soldiers that juggle many tasks

On the other hand, if both sides are similarly matched in strength, then the colony with the most workers wins. "Having stronger fighters isn't always the best strategy."

Next, Grüter and his team will scrutinise other bee species for soldiers. If they discover soldiers in other bees, they could better understand how species of bees evolve soldiers.

The diverse behaviours of Jatai bee soldiers "draw a big question mark", says Grüter. "[It's] not just about the evolution of soldiers in this species but also in general about the evolution of physical caste in social insects."

Perhaps other bees have also evolved hard-working soldiers that juggle many tasks. But that is not going to bother the Jatai bees – they are concerned only with robber bees and honey. As new cohorts of Jatai bee majors emerge from brood cells, they will live as all of the previous generations of soldiers did: work harder than the rest and die guarding the nest.

Join over five million BBC Earth fans by liking us on Facebook, or follow us on Twitter and Instagram.

If you liked this story, sign up for the weekly bbc.com features newsletter called "If You Only Read 6 Things This Week". A handpicked selection of stories from BBC Future, Earth, Culture, Capital, Travel and Autos, delivered to your inbox every Friday.