Leaders from the world's largest economies have agreed to promote free trade to tackle the sluggish global economy.