Let's review, shall we?
After the Shah Mohammad Reza Pahlavi is deposed in Iran and Ayatollah Khomeini takes over as Irans new leader in February 1979, the US is interested in continuing to work with the Iranian government.
At first the US is taken aback by the new fundamentalist Islamic government, and National Security Adviser Zbigniew Brzezinski contemplates fomenting a military coup to stop Khomeini. But Khomeini is fiercely anti-communist, and Brzezinski soon decides that Irans new government can become part of an effective anti-Soviet alliance he calls the arc of crisis (see November 1978-February 1979).
The US embassy in Teheran, Iran, remains open, and more US officials come to Iran and begin tentative talks there. [Dreyfuss, 2005, pp. 236-243] The CIA in particular begins secretly collaborating with Iranian intelligence, providing information about the Soviet Union, Afghanistan, and Iraq.
The CIA and Iran both covertly work to destabilize the pro-Soviet government in Afghanistan. [Dreyfuss, 2005, pp. 264-265]
In early November 1979, Brzezinski secretly meets with Iranian Prime Minister Mehdi Bazargan, as well as Irans foreign minister and defense minister, in Algiers, Algeria. But shortly before the meeting, the US agrees to allow the Shah, dying with cancer, to come to the US for medical treatment.
Khomeini is enraged, and on November 4, just three days after the Algeria meeting begins, Khomeini arranges for students to take over the US embassy in Teheran and seize hostages.
This realigns political forces in Iran and allows Khomeini to sideline Bazargan and other others meeting in Algeria, rendering the negotiations there moot.
Brzezinskis attempts to create a de facto alliance with Iran collapse. The US hostages will be held for over a year before finally being freed.