Afghanistan has become America's longest war, surpassing the Vietnam war last year.  But after 18 years the situation could at best be described as a stalemate. The Taliban is gaining more ground each year and Afghan security forces' losses have become unsustainable.  It has become clear that there is no military solution, a surge in 2009 that increased total coalition troop levels in Afghanistan to over 130.000 resulted in short-term victories but were reversed when most of those forces left.  The war also saw the rise of an Islamic State affiliate that has launched deadly terror attacks in Afghanistan and Pakistan , and Al-Qaeda is still active in the country, despite transferring most of its leadership to Pakistan. 
The trends are not optimistic and it is not surprising that the United States is looking for a way out. For the last few months the United States has had negotiations with the Taliban in pursuit of a peace deal. A draft agreement that was announced last week included a withdrawal of 5.000 U.S. forces within 135 days.  But due to the lack of mentions of Afghan-Taliban talks or a ceasefire in the document, the draft was heavily criticized by the Afghan government  and former U.S. ambassadors.  In a letter published by the Atlantic Council , those nine former U.S. Afghanistan ambassadors advocate for a partial troop withdrawal in return for the initiation of talks between the Afghan government and the Taliban, something the Taliban has been heavily opposed to because they view the Afghan government as a 'puppet' to the United States. They also voice their support for troop drawdowns based on conditions instead of defined dates. Given the lack of trust between all parties, this seems to be the smartest and safest path. It will incentivize the Taliban to follow the agreements to achieve one of their main goals: getting rid of 'invaders' , and it will allow the U.S. a foothold while those goals are not met. It is perhaps too optimistic and following this path will not mean a quick exit for U.S. and coalition forces in Afghanistan, but it is the best route that safeguards U.S. and Afghan interest.
There is a debate ongoing between those in favor of leaving or staying, and there are legitimate reasons for both.  But the U.S. will have to make a choice, if it is willing to stay because its primary goals are not achievable by a deal it must define a clear set of policies to progress towards these goals. If it wants to leave it has to do so responsibly and forge a conditions-based deal tied to troop reduction between itself, the Afghan government and the Taliban. The current U.S. administration prefers leaving, but doing so without a deal or without a conditional approach is a recipe for disaster. While the future of U.S.-Taliban talks is unknown following recent events , they are vital to ending America's longest war and for lasting peace in Afghanistan, as distant as it may seem.