Image copyright Getty Images Image caption Reaching the end of his time at the White House, President Obama is considering his legacy as a leader

It's been a long and complicated eight years for America's foreign policy under Barack Obama, but the chastened president is still a believer in US leadership, as PJ Crowley writes.

In the first year of his presidency, Barack Obama the idealistic internationalist cared deeply about what the world thought of US policy and power and committed himself to repairing America's standing in the world.

The United States was the indispensable nation, but needed to develop effective partnerships to solve the world's problems and share the burden of administering an interconnected and interdependent global system.

In the last year of his presidency, a far more chastened and realistic Barack Obama gave a remarkably blunt series of interviews to Jeffrey Goldberg of The Atlantic that revealed the difficulty of translating that presumed indispensability into coherent strategies and meaningful collective action to resolve complex conflicts that are rooted as much in the past as the present.

Obama remains a true believer in the importance of US leadership. But he recognises the limits of American power, understanding that there are intractable problems that even the world's most influential nation can't solve.

The president rejected what he called the "Washington playbook", that the answer to every situation is military force. Obama was elected largely because of the war in Iraq (he alone among the presidential contenders in 2008 had not voted for it) and to avoid another Iraq.

Image copyright Getty Images Image caption Mr Obama pledged to end wars in Iraq as well as Afghanistan where Capt Florent Groberg earned his Medal of Honor

Obama tried to better match the level of military muscle and diplomatic commitment to the importance of the interest and the potential for impact. He refused to take ownership of the outcome of a problem that he felt America didn't need to solve or couldn't solve at an acceptable or sustainable financial and political cost.

This strategic logic, as Obama told Goldberg, explained in large part his cautious approach to Libya and Syria.

How did Obama and Cameron fall out?

White House insists leaders are 'close partners'

Obama was pushed by British Prime Minister David Cameron and French President Nicolas Sarkozy to support the Nato intervention to prevent an imminent massacre and protect the Libyan people from their unhinged leader, Muammar Gaddafi, who threatened to kill his political opponents "like rats".

Somewhere along the line, the three leaders decided that the only way to protect the Libyan people was to help the Libyan opposition, the National Transitional Council, overthrow the Gaddafi regime.

The world is undoubtedly better off without Gaddafi, but not yet Libya. While Obama rightly placed primary responsibility on Libya - the interim government was overconfident of its ability to manage its transition to democracy — he seemed to also finger a distracted Europe, which had a bigger stake in Libya's future.

"I had more faith in the Europeans," he said. Ok, but in fairness the EU financial crisis and Greek bailout were more than mere distractions. Their ripple effects impacted American markets in meaningful ways.

Image copyright AFP Image caption Fighters loyal to Libya's internationally recognised government celebrate a small victory in the fight against Islamic State militants

In fact, Nato did no post-conflict planning for Libya, to a great degree repeating a critical mistake made in Iraq. In the ensuing chaos, a group affiliated with al Qaeda attacked the US diplomatic and intelligence compounds in Benghazi and the Islamic State established a redoubt in Sirte, Qaddafi's hometown.

There is plenty of blame to go around, but no doubt the Libyan "mess", as Obama termed it, reinforced his doubts about Syria.

Obama drew a red line over Syria's use of chemical weapons, but after it was crossed in August 2013 he feared a slippery slope into the middle of what he considered "someone else's civil war." He threatened military force but in a dramatic moment in the Rose Garden pressed "the pause button," unexpectedly asking Congress for a vote on the proposed military strikes while buying time for a political alternative.

While the United States worked with Russia to force Syria to give up its chemical weapons stocks, many world leaders and some members of his own national security cabinet believe the mismanagement of the red line undermined the credibility of US power, a charge Obama categorically rejects.

Nonetheless, Obama would be drawn into the Syrian conflict within months as the Islamic State took control of three major Iraqi cities and released brutal videos showing the beheadings of American journalists and British aid workers.

Image copyright Getty Images Image caption The strategy in Libya was dubbed 'leading from behind' with other Nato powers taking the lead

Characteristic of Obama's definition of American indispensability, the United States now leads a 65-nation coalition that is steadily degrading the Islamic State. But it's unclear whether the limited application of military force is enough to destroy the caliphate. That, believes Obama, is the region's responsibility.

"A president does not make decisions in a vacuum," Obama said. "He does not have a blank slate." In the end, Obama more or less delivered the foreign policy that he advertised on the campaign trail in 2008 and for which he was elected — ending America's wars and avoiding new ones.

Which playbook the next American president brings into the Oval office 10 months from now - Washington's traditional internationalism, Obama's limited interventionism or the revisionism that has characterised the 2016 campaign thus far — is why elections matter and how domestic politics has come to shape America's foreign policy.

PJ Crowley is a former U.S. Assistant Secretary of State, a distinguished fellow at The George Washington University Institute for Public Diplomacy & Global Communication and author of the forthcoming book, Red Line: American Foreign Policy in a Time of Fractured Politics and Failing States.