Uganda has said it will pull its troops out of Somalia by December 2017.
Uganda's Chief of Defence Forces, General Katumba Wamala, told the BBC the decision was taken because of frustration with the Somali army and international partners.
He said it was time for Somalia's army to take over its own security, but that was not happening.
The US, UK and Turkey were among countries training Somali soldiers and police officers.
But Uganda's government says they are not coordinating their activities and this is causing problems.
Uganda provides the biggest contingent of soldiers to the African Union force fighting militant Islamist group Al-Shabaab. Other troop contributing countries are Kenya, Ethiopia and Burundi.
Some have questioned the effectiveness of the AU mission in Somalia because it has struggled to secure areas outside the big towns. It has also been plagued by allegations of corruption.
General Wamala said Uganda could pull out before December 2017 if another country was found to replace it.