History did an about-face in the middle of Jimmy Carter's term as president. The administration tried to adjust, but never quite succeeded.

For the change went against the grain of the president's personal instincts and political interests, and he also lacked the managerial apparatus to organize a comprehensive shift. So the Carter legacy is a ramshackle collection of shattered illusions, compromised ideals, half measures and unresolved dilemmas.

"High goals and great ambitions," as the president put it in his last budget message, prevailed at the start. In foreign policy, the Carter administration tried to achieve a more perfect detente with Russia. From first to last, the arms control treaty known as SALT II was a central preoccupation.

At the same time there was a push toward harmony with the countries of the Third World. Hence the Panama Canal treaty, the recognition of Communist China and -- by a circuitous route -- the settlement between Egypt and Israel.

At home, Carter aimed to complete the welfare state. Despite the threat of inflation, he moved to stimulate the economy, especially for the jobless. He also advanced an energy policy based on fair sharing or reduced consumption.

Iran -- or more specifically, the long drawn-out catastrophe that caused the shah to be replaced by the Ayatollah Khomeini -- proved fatal to all these hopes. An oil pinch developed, and then there were gas lines in this country. A new burst of inflation came next. There followed acute insecurity in the region around Iran, dramatized by the Soviet invasion of Afghanistan.

A unified response to the cataclysm was never attempted by the Carter administration. Nor could it have been. The administration lacked -- as two of its most acute junior officials, Curtis Hessler and Ben Heineman Jr., point out in a remarkable new book on the presidency -- a strategic center, a White House that managed policy across the board. So instead of a coherent reaction to the disaster in Iran, the administration gave ground bit by bit.

Inflation was promoted in the fall of 1978 to Public Enemy No. 1. But administration efforts to cut back budgets and to set in motion machinery for wage and price restraints were largely foiled by constituent groups inside the Democratic Party. By default, the burden of fighting inflation fell to the Federal Reserve with its power to tighten money and credit. The predictable result was a sharp recession and continuing inflation.

Energy policy, by the spring of 1979, had been pushed way beyond the allocation of scarcity on a fair basis. Emphasis passed to the stimulus of higher output by the incentives of the marketplace -- namely money. Under pressure from the Senate and the Allies, the president ordered the staged decontrol of oil. Producers battened, and the consumer interest suffered accordingly.

Foreign policy changed last -- but most dramatically. After the Soviet invasion of Afghanistan, the president threw in the towel on SALT. He committed the administration firmly to big increases in the military budget, and to a program (MX) for reducing the vulnerability of this country's land-based missiles to a Soviet strike. He asserted a vital interest in the Persian Gulf, and moved to acquire various basing rights in the area and to build a Rapid Deployment Force. He endorsed to the point of near irreversibility the development of modernized nuclear forces in Europe.

For political purposes, Carter varied the emphasis he placed on these sundry changes. To win the Democratic nomination from Edward Kennedy, he stressed his enthusiasm for standing up to the Russians, fighting inflation and providing incentives for energy production.

In doing battle against Ronald Reagan, he reversed gears. He tried to gather the Democratic Party around him by stressing the traditional interest in helping poor folk at home achieving peaceful accommodations abroad. i

In his farewell address, Carter came ful circle. He asserted anew the need for controllng nuclear weapons, for conserving natural resources and for promoting human rights. He dedicated himself to "our American values . . . our common vision of a free and just society." He ended as president as he had begun.

No one contests the ritht of a leader to turn different facets of policy to the light as circumstances change and audiences vary. Nor to put his best foot forward as he leaves office -- especially if the glow of good feeling is confirmed by the release of the hostages.

But chopping and changing confuse the spectators as much as the opposition. Flashing now one signal and now another works to weaken government. At the center of the Carter legacy is an institution in trouble. A supreme office was trivialized to the point where it became thinkable for an actor to be elected president.