Praise be to Allah.
If there was an agreement – as mentioned in the question – that this gold was a mahr that was given in advance, and was not a gift, then as the engagement was annulled, the suitor has the right to take back the mahr in full, because the woman does not become entitled to anything of the mahr except when the marriage contract is done.
With regard to your question: should he take the money or the gold?
The answer is: it says in the question, “so that she could buy several grams of gold as agreed upon.”
This indicates that the mahr was gold of an amount that had been agreed upon, and that he gave the money to them, by way of delegating them to buy on his behalf whatever gold they liked. This is the custom in the country of the questioner, and it is a kind of delegating someone to do a transaction (namely purchasing the gold with the cash). This is permissible according to scholarly consensus.
Ibn al-Mundhir (may Allah have mercy on him) said:
All of the scholars from whom we acquired knowledge are unanimously agreed that delegating someone to do a transaction is permissible. "Al-Ishraaf (8/312)"
Based on that, if the engagement was annulled before they bought the gold, then the delegation of them to make the purchase was also annulled. In that case, he is entitled to take back the amount of money that he gave to them, regardless of whether the price of gold increased or decreased.
Ibn Qudaamah (may Allah have mercy on him) said:
Appointing a proxy (or delegating someone to do a transaction on one’s behalf) is permissible for both parties. The one who appoints a proxy may dismiss his proxy whenever he wishes, and the proxy may dismiss himself, because it is permission to dispose of something, so each of them has the right to cancel it, such as if he gave him permission to eat his food.
The agreement is also annulled if either party dies, no matter which of them it is, or one of them becomes completely insane.
There is no difference of scholarly opinion concerning all of that, as far as we know. "Al-Mughni (7/234)"
If the engagement was annulled after they had bought the gold, then what he is entitled to take back is the gold, not the money that he gave to them, because they bought the gold on the grounds that they had been delegated to act as his proxies in the purchase, so it is as if he was the purchaser.
And Allah knows best.