Bagram - The US Defence Secretary Ashton Carter arrived in Afghanistan on Tuesday for talks with President Ashraf Ghani, days after the United States and Nato pledged to keep thousands of troops in the troubled country.The Pentagon chief's visit follows a renewed commitment to Afghanistan from Nato, which said over the weekend it would keep forces there at least until the end of 2017.Most are American, but some 40 countries have deployed troops there. Their official role is to train Afghan forces, who are now responsible for their country's security. Despite a massive, nearly 15-year international effort to defeat the Taliban, the resurgent group controls large areas of Afghanistan and have vowed to keep fighting until foreign forces leave. Carter visited Bagram to meet Chief Executive Abdullah Abdullah in Kabul.Barack Obama's 2008 pledge to end the wars in Afghanistan and IraqLast week, Obama dialed back plans to cut US troop numbers in Afghanistan from 9 800 to 5 500 by the end of the year.Instead, some 8 400 US troops will remain, providing training and air support to the Afghans. Obama has also relaxed rules of engagement, making it easier for US troops to target the Taliban - a move that the head of Nato forces in Afghanistan, General John Nicholson, said was in "recognition of the difficulties that we are facing"."We can strike the Taliban and disrupt the enemy," he told reporters in Kabul over the weekend, adding that Obama had granted "all the capabilities that we requested". Local forces took the lead in providing security in 2015, but are struggling to contain Taliban offensives and prevent attacks from the Islamic State group and al-Qaeda.More than 5 000 Afghan security forces were killed last year, and attacks continue. The Taliban claimed responsibility last month for a suicide attack that killed more than 30 Afghan police cadets in Kabul.Further complicating matters is endemic corruption and allegations of rights abuses. Approximately 13 000 mostly Nato troops are currently stationed in Afghanistan under Operation Resolute Support to train and assist Afghan security forces.Nato has agreed about 12 000 troops will remain in Afghanistan through at least 2017, though in reality local troops are likely to need foreign support and funding for years to come. In return, Nato is demanding reforms of the Afghan security forces.Carter's visit followed a brief trip to Baghdad on Monday, where he pledged hundreds of additional US troops to assist Iraqis fighting against the Islamic State group (ISIS).