Updated

British Prime Minister David Cameron said the United States was doing the right thing by meeting with Taliban representatives after the Afghan militants opened an office in Qatar.

Speaking at the end of the G8 summit in Northern Ireland, Cameron said leaders had discussed the issue during a dinner on Monday night during which they focused on foreign policy.

"I think this is the right thing to do, of course it involves all sorts of difficulties," Cameron told a news conference at the summit on the edge of a lake in the luxury Lough Erne golf resort.

Cameron said the security response in Afghanistan, where Britain still has around 7,900 troops and is in the process of handing over to Afghan security forces, had to be matched by a "political process."

"That is exactly what I hope can happen with elements of the Taliban -- that is the point of the Taliban office in Doha in Qatar and that is the point of the discussions that the Americans will have," Cameron said.

"And we've been fully engaged and involved in this process right from the start, indeed from the moment I became prime minister."

Washington announced the talks "in a couple of days" in Doha as the Taliban said they had opened an office there to oversee peace talks.

Cameron highlighted the similarities between the situation in Afghanistan and Northern Ireland, where a 1998 peace accord largely ended decades of Protestant-Catholic violence.

"In the end we're standing in a place where people who were once committed to violence decided to give up that violence and join a political process and that is what is required in Afghanistan," he said.

"That shouldn't signal any weakening of our security response, it absolutely doesn't, but if we can persuade people there is a legitimate political path for them to follow we should do so."