The United States and Saudi Arabia agreed today to raise the level of their formal military cooperation by establishing a joint defense planning committee and working together to help other friendly nations in the Middle East and Indian Ocean.

Defense Secretary Caspar W. Weinberger announced these new links at the end of lengthy negotiations here that stretched from Saturday until 4:30 this morning. Prince Sultan, the Saudi defense minister, sat beside Weinberger and appeared to join in endorsing the agreement sketched by the U. S. defense secretary, although Sultan had no direct comment on the joint planning committee.

The Saudis declined Weinberger's request to issue the agreement in the form of a joint communique, American officials said, but they acquiesced in a compromise formula that resulted in Weinberger reading to reporters parts of a draft paper that had been the subject of the intensive negotiations with Sultan. Weinberger's prepared statement was not distributed to reporters.

In the end, officials said, Weinberger by waiting out the Saudis, managed to get Saudi agreement to verbal presentation of the points he had presented in writing, with Prince Sultan sitting at his side on a blue couch in an unusual ceremony in the richly carpeted VIP lounge at the Dhahran Airport.

In contrast to many American officials who have come here and left with what they thought was a solid agreement that quickly unraveled when the traditional Saudi hospitality collided with political and economic pressures, Weinberger has extensive experience with the Saudis and confidence in his ability to win them over. As an executive of the Bechtel Corp., which has participated in major construction projects in Saudi Arabia, he was involved in at least seven extensive commercial negotiations with Saudi interests.

Prince Sultan, evidently trying to keep his public involvement in the agreement to a discreet minimum, remained silent but did not object as Weinberger told American and Arab reporters that the United States and the oil-rich kingdom had formally agreed to establish a Saudi-U.S. Joint Committee for Military Projects to coordinate defense efforts. It was not immediately clear how many members the commission would have, but similar commissions in other friendly Arab countries have about 25 American military specialists who draft blueprints for the structuring of the host nations' armies.

The idea here is to formalize and upgrade the existing U.S.-Saudi relationship, including a plan for the American defense secretary to go to Saudi Arabia one year and the Saudi defense minister to travel to the United States the next.

American officials said that these high-level visits would force a specific agenda on U.S.-Saudi planners in Saudi Arabia and in the United States. They said the Carter administration had tried to do the same thing but did not succeed.

Robert Hunter, a Middle East specialist who served on the National Security Council staff during the Carter administration, acknowledged that forcing a specific agenda was "always a goal, but we hadn't reached there yet." He added that "the essential difference" between the efforts of the former administration and what was announced today is that "we sought to work out a range of cooperative relationships in a way that would be politically tolerable to the Saudis by not requiring them to go formally on the record."

The joint committee, officials traveling with Weinberger said, will not require sending additional American military people to Saudi Arabia. The 950 already here will be plenty to do the job for at least the next three or four years, officials said.

Besides trying to give Saudi Arabia the most effective defense forces, American officials said that the team might eventually work on five-year military plans for other friendly countries in the Persian Gulf area.

In response to a question, Sultan and Weinberger said there would be increased coordination in the giving of economic and military aid to other countries to help stabilize the Persian Gulf, Middle East and parts of Africa.

Although U.S. officials said no countries were specified in the U.S.-Saudi understandings, candidates for help include Morocco, North Yemen, Pakistan, Somalia, Sudan and Tunisia.

One possibility is that the Saudis could give or loan poorer nations in the region money to buy American weapons. But Prince Sultan at the airport press conference tried to distance himself from that money-guns combination.

"We would like to say that the relationship and the cooperation between our two countries are not based on the cooperation in the field of military endeavor but in other fields such as the economic field and the technology field," the prince said.

Weinberger replied, "His Highness is, of course, correct" that military cooperation is not the only avenue.

The two nations have agreed to help refugees from Afghanistan, but not the resistance forces fighting Soviet occupation forces.

In another measure of the military relationship, the four American Airborne Warning and Control System (AWACS) planes on duty in Saudi Arabia will remain here until the five the Saudis have ordered are delivered and become operational. This means it will be about 1990 before the Saudi AWACS can take over completely from the Americans.

The sudden willingness of the Saudi royal family to enter into such formal and highly visible arrangements with the United States after resisting for so long suggests that Riyadh is increasingly worried about external military threats.

To the south is a Soviet-equipped South Yemen; to the east, across the Persian Gulf is an increasingly bold and competent Iranian military, as evidenced by recent successes in the Iranian-Iraqi war; and to the northwest is Israel whose Air Force could knock out the fledging Saudi one in minutes, in the view of U.S. experts.

Although the Saudi Army, Navy and Air Force are being improved, American officers here seem to agree that they are years away from being able to take on anything but a weak Third World military force.

"Their basic problem is manpower," said one longtime American military adviser who likes and admires the Saudis. He said the Saudis must either recruit that manpower somehow, buy it from another country or borrow it in an emergency. One theory is that the Saudi ruling family is willing to step closer to the United States now so it could more easily look for help in a sudden emergency.

In contrast to its manpower shortages, Saudi Arabia has the barracks, ports and airfields to accommodate a large outside military force that the United States could deploy to that country in an emergency.