I even heard of a small number of gunpowder weapons being used at the Battle of Agincourt. If so, why didn't gunpowder weaponry take off until much later? Surely they would have seen the benefits?
I can only really speak for Europe, particularly Western Europe and not for China, the Islamic World or other areas. I've seen it said that an important factor in the limited development of gunpowder weaponry in China was that it's most dangerous enemies were fast-moving cavalry forces, against whom gunpowder weapons had few advantages. I can't verify that though.
Gunpowder was introduced into Europe in the mid to late 13th century. Two centuries later, it still had a long way to go to displace bows, although it was dominant as siege artillery.
The main thing to remember is that early gunpowder weapons were pretty rubbish. So why bother with them when you've got bows? We look back and might see the success of gunpowder as inevitable, but it wasn't so obvious at the time.
Early handguns were expensive, unreliable, sometimes blew up, were unusable in the rain, and highly inaccurate. You might get some advantages in terms of armour penetration, but most of the time you're probably better off with a crossbow. In fact, their performance shared a lot in common with crossbows: slow firing, good armour penetration, not great range. Both weapons tended to be vulnerable on the open battlefield and worked best from good defensive positions.
It was only after a long period of incremental improvements that handheld firearms really gained a decisive advantage over bows. Important changes were a reduction in the cost of powder, due largely to domestic production of saltpetre, refinements in the composition of powder, and the invention of corned powder, which was less sensitive to moisture and (iirc) more powerful because of the way it burned.
The story is a bit different with cannon. Of course, there were technological improvements being made that made cannons more effective, more reliable and lighter. However these much more quickly gained a decisive advantage over older siege artillery (ie. trebuchets). Rate of fire was less of a problem compared to the extra power of a cannon. Cannon could also use a cheaper lower grade of powder than handguns (although they could use very large quantities). From the early 15th you start to see field battles opening up with cannon fire - usually ineffective but enough to unnerve the enemy. This was common in the Wars of the Roses at the end of the century even while handheld firearms were in only limited use in England. I get the impression they were often used just because they were there (if you've got a siege train moving with you, you might as well give the guns some use).
Probably the biggest limiting factor for cannon was that they were expensive. They needed to be manufactured, supplied, crewed, hauled around. You couldn't just whip up a cannon from a pile of wood and use stones for ammo like you could a trebuchet (ok, that's a bit of an exaggeration). To have lots of cannon you need lots of money, and nobles and kings in the middle ages tended to be short of money. So the increasing use of cannon ties in with the centralisation of state power and finances.
(Key source here is Weapons and Warfare in Renaissance Europe by Bert S Hall, which annoyingly I've lent to a friend so can't reference properly.)