As I’ve noted many times before, there are two models for American military involvement in Third World countries. In the Korean model, we decide the country in question has so much strategic importance, we are obligated to stay indefinitely; in the Vietnam model, we prepare the natives to fight for themselves, and then leave.
Once Trump, and then Biden, chose the Vietnam model for Afghanistan, its fate was sealed. So what can we learn from this experience? That attempting to foster a kind of liberal democratic regime on a Third World nation with a completely different culture, and then leaving, will not succeed if the armed opposition has a place of refuge from which they cannot be displaced.
There are two ways to avoid the Vietnam/Afghanistan experience. The first is to accept the burdens of the Korea model up front; the second is to install and arm the most competent warlord you can find, give him guns and money, and let him take responsibility for the country. Call it the Putin Solution.