I'm currently reading a book called 'Directorate S' about Afghanistan. The title refers to the Pakistani ISI department that was responsible for pursuing Afghan strategy.
The whole thing was a mess. Karzai was a weak, corrupt leader who tried to play the USA & Pakistan off against each other. Billions of dollars were poured into the country, most of which was siphoned off. $800m disappeared from the Afghan National Bank into the pockets of corrupt individuals.
The USA really didn't have a clear strategy, with the Pentagon, State Department and CIA all pursuing their own agenda, often with conflicting strategies even within those organisations. The Pakistanis were more concerned about neutralising Indian influence within Afghanistan and internal terrorism, than about Afghan sovereignty. The US worked out what the top five Pakistani issues were and none coincided with the top American issues.
Really, the US should have said to the Taliban that if they distanced themselves from Al Qaeda then they'd happily leave Afghanistan to its own devices. There were certainly indications that the Taliban were prepared to do this. It was simply never going to be possible to gain a military victory when the Afghan Taliban were able to find refuge in Pakistan. So the US should have also told Karzai and Pakistan to sort it out between themselves.