Egypt and the United States are moving swiftly to a new level of military and strategic cooperation that, joined to broad diplomatic and economic commitments, gives Washington an increasingly important stake in the policies and survival of President Anwar Sadat.

The rapid expansion of links, particularly since the Afghanistan crisis, means that in effect Egypt has replaced Iran as the most powerful and dependable U.S. ally in the Middle East, after Israel.

Despite its distance, Egypt thus is becoming a key to American ability to exert influence in Africa and Persian Gulf oil nations under the shadows of Soviet intervention in Afghanistan and uncertainty in Iran.

In addition, what has become the largest U.S. economic aid program in the world, moving into its sixth year, is reaching into Egyptian society with a hearty American handshake. More than a billion dollars a year is being allocated in an effort to show Egyptians that Sadat's peace policies will make their lives easier and to foster the free enterprise that Sadat has resolved to revive after two decades of stultifying Nasser socialism.

Although no one may have planned it that way, the cumulative effect of these commitments increasingly seems to be to tie U.S. Middle East policy to Egypt's pro-western orientation, in the expectation but without the guarantee that the direction set by Sadat will continue in the years to come.

"We're building here for the long haul, no doubt about it, on the assumption that we've got a firm foundation," said a senior U.S. diplomat closely involved in the evolution of U.S.-Egyptian relations. "Of course, you have to review the assumption from time to time. And we're doing that. Otherwise, you're engaging in self-fulfilling prophecy."

A junior American diplomat of Arab origin who opposes Sadat and U.S. policy here called the assumption "putting all our eggs in one bastard." u

Other U.S. and European diplomats in the Middle East also question -- in more polite ways -- the wisdom of investing so heavily in Egypt as a strategic partner after the Iranian experience and as the only channel for resolving the Arab-Israeli conflict despite opposition by the other Arab nations.

"There is general agreement that Sadat seems permanently pro-West but the thing is that if Sadat were to disappear for one reason or another, [Vice President Hosni] Mubarak or whoever else took over could change things around completely," remarked a European diplomat who watches Egyptian politics closely.

As an example, he cited the turnabout by Sadat himself, who in 1970 took over an Egypt tightly allied to the Soviet Union by President Gamal Abdul Nasser but who within a few years reversed alliances and has ended up as a U.S. champion in the Arab world.

A military specialist from a Western country friendly to both the United States and Egypt also noted the uncertain future and said, "It's just like Iran." After a pause, he smiled and added: "Except the Iranians were paying for it."

Sadat's high-visibility role as the only world leader to grant asylum to the fallen shah underlines the comparison with an irony embarassing to American officials involved in U.S.-Egyptian relations. Since Sadat has taken up where the shah left off as a U.S. ally in the Middle East, his display of concern seems to refelct a newly intense personal solidarity with an old friend of the United States refused U.S. asylum and reduced to drifting as an international outcast.

But beyond the irony, U.S. officials here insist the comparison with Iran is false because Egypt under Sadat is more stable than Iran under the shah and the scale of U.S. involvement here is much smaller than it was in Iran before the Islamic revolution.

The number of American officials and their families living here, they point out, is only about 730, with approximately 100 more on temporary duty. Including nonofficial U.S. citizens here, the total of Americans in Egypt is about 6,000, among a population of 41 million.

Although these numbers are certain to rise as more experts accompany U.S. arms that are on their way, U.S. diplomats say the numbers will never reach the scale of Iran, where 40,000 Americans lived at the peak of U.S. involvement.

U.S. diplomats and Egyptian officials agree that Washington's commitment to Egypt, particularly military, has grown so fast in recent months primarily because of Washington's attempt to replace Iran as a strategic friend in the Middle East -- even faster since Soviet forces intervened in Afghanistan last December.

"You look around the region, and what else is there?" asked a ranking U.S. official. "There is Israel, but that presents all kinds of other problems. Egypt, after all, is an Arab country."

U.S. officials say that originally the American willingness to get deeply involved here sprang from three main considerations:

Sadat's peace treaty with Israel was largely a response to U.S. urging and the United States therefore had an increased responsibility to be "fair" in dividing up its aid to Israel and Egypt. Against this background, U.S. economic aid grew from a "quick fix" to display the fruits of friendship with the United States into an open-ended project aimed at revamping much of the country's economic organization.

The run-down Egyptian military -- its 21 Mig23 fighters and many of its 80 Mig21s are reported grounded for lack of repairs -- was in need of refitting to meet what is regarded as a potential threat from the heavy arsenal built up by neighboring Libya under the unpredictable and hostile Col. Muammar Qaddafi.

Sadat's definition of Egyptian interests made him the most valuable U.S. friend in the Arab world. The Egyptian president also showed himself willing to use Egyptian forces and arms for causes supported by the United States, making military aid to them possible without the red flag of direct U.S. help.

In this context and as part of the peace treaty with Israel, Egypt was to receive $1.5 billion in military aid, including 35 F4E Phantom jet fighters and improved Hawk antiaircraft missiles.

Since the upheavel in Iran and the Soviet military intervention in Afghanistan, however, the amount of U.S. military aid and the quality of weapons to be supplied has risen sharply and the rationale for military links with Egypt has shifted to regional strategy.

First a study mission that visited here last fall under William Perry, the Pentagon's research director, recommended a major U.S. commitment to revitalize the Egyptian Army and Air Force. Then late last month a Pentagon negotiating team under Assistant Secretary David McGiffert agreed to provide Egypt of 40 F16 jet fighters and 250 M60A3 battle tanks as part of a new series of credits expected to reach $4 billion over five years.

"The program agreed to by two governments is a step in a longterm program based on the common interest of the two governments in peace and security in the area," said a communique announcing the deal.

As part of the program, President Carter also informed the Egyptians of his willingness in principle to supply F15 fighters, the mose advanced jet in the U.S. arsenal, the communique said, adding: "The Egyptian government hopes in due course to order such F15 aircraft as may be necessary for its defense needs."

The Egyptian defense minister, Gen. Kamal Hassan Ali, told a class of Egyptian air cadets last week that the United States also is negotiating with Egypt for production of F5 jets and Bell 214ST helicopters in Egyptian factories. These projects would replace plans to build the French-West German Alpha Jet and the British Lynx helicopter, abandoned after Saudi and other Persian Gulf Arab financing fell through in disagreement with Sadat over the peace treaty.

As U.S. willingness to provide arms has increased, so has Sadat's willingness to cooperate militarily with U.S. aims in the region. U.S. AWACS (Airborne warning and control system) reconnaissance planes with about 250 U.S. personnel participated with Egyptians in training exercises last December using an Egyptian air base at Kennan in Upper Egypt.

Since then the planes have returned to Egypt several time for deployment over the Persian Gulf and Indian Ocean in coordination with a U.S. naval fleet. Some are reported to be spending time at Egyptian facilities, presumably with U.S. personnel to maintain them.

Sadat has pledged that such military "facilities" will be opened to the United States here if the need arises to defend any threatened Arab state.

"Egypt will give full facilities to the United States to defend any gulf Arab country subjected to invasion from Iran or the Soviet Union, out of our Arab and Islamic responsibility," he told his ruling National Democractic Party in a speech Jan. 28.

Sadat also has trained Afghan rebels and dispatched Egyptian arms or advisers to Morocco, Zaire and Oman.

Although Egyptian officials reject Arab suggestions that they are acting as U.S. surrogates, the aid operations coincide U.S. policy and, the aid American officials here express satisfaction at seeing U.S. friends receive such help without direct U.S. involvement.

Egyptians emphasize, however, that noe of Sadat's commitments has been written into formal treaties such as those that bound Egypt to accord military facilities to the Soviet Union during the years of Soviet influence and aid here.

"Each situation would have to be considered on a case-by-case basis," said an Egyptian government official. "As long as our interests coincide, fine. If not . . ." he added, trailing off and flicking his hand into the air.