First of all, it would have happened earlier in the year, instead of during prime military offensive season.
It would have involved a drawdown of non military personnel.
It would have been preceded by Afghan special forces and interpreters being evacuated.
It would have included temporary air cover to keep the Afghani forces above water, at least until everyone but allied military was gone.
It would have included steps to legitimize the Afghan government, instead of treating them as an afterthought.
Basically anything would have been better than how it was handled.