Gemany before WW1 had great influence on Austria-Hungary. I´m from Austria myself and in History we learned about something called the blank cheque which was a treaty between Austria and Germany. It was stated that if serbia shows any retaliation against the Austrian annexation the shall show the serbs an Ultimatum. In The Ultimatum it had many things that must be completed by the serbs as an apology. After the attack in Sarajevo the Austrians were forced by the germans to show this ultimatum to Serbia. Serbia denied it resulting in Austria having to attack Serbia.
The Black Hand conspiracy was backed by officials in the Serbian government. They approved of the assassination plot against Arch Duke Franz Ferdinand. He was the next Emperor of the Austria Hungarian Empire. They did it out of Nationalist aspirations to take Bosnia away from the Empire. The murder of the Arch Duke was clearly an act of war. Austria was not willing to fall for some nonsense about it being lone gunmen. They wanted a full scale retaliation against Serbia. Russia stuck it's nose into the affair and threatened Austria. Germany was the sworn ally of Austria and mobilized to address Russia's interference.
Due to the manner in which the various alliances were set up at the time eventually someone was going to have to put their money where the mouth is and war would have broken out. It sucks for Germany that they caught the short end of the stick, but it could just as well have been anyone due to the powder keg that had been set up.
While Austria was justifiably angry about the assassination the assassination was carried out by a private group, not the Serbian government. Austria could've just asked Serbia to cooperate in apprehending the Black Hand, and Serbia could've helped them with this covertly if the government didn't want to look antinationalist.
By demanding Serbia become a protectorate or go to war Austria essentially started World War I. Still none of the other powers were smart for getting involved, except that Britain was just trying to protect Belgian neutrality.
Austria wasn't smart about going to war. With all its ethnic divisions its a wonder the monarchy didn't realize that a war would destroy the empire. Although chances are if there wasn't World War I it would've collapsed anyways. Or it would've been the site of the first communist revolution instead of Russia.