Secretary of State George P. Shultz said today that the Lebanese-Israeli peace agreement is "not going to be derailed," and he contended that Syria, despite its hostility, has "not slammed the door" on efforts to get all foreign forces out of Lebanon.

That was the message underscored by Shultz as he ended his two-week Middle East mission with stops in four countries today. He began by consulting Saudi Arabian leaders in Jeddah and then made brief return visits to Jerusalem and Beirut before flying here for an economic meeting.

However, Shultz left the region with a big cloud of uncertainty over his principal goal of translating the withdrawal agreement into reality.

From the outset, Israel made clear that it will not pull out of Lebanon until Syria agrees to withdraw the estimated 40,000 troops it has in eastern Lebanon. And, as Shultz learned during his talks in Damascus yesterday, Syrian President Hafez Assad remains defiantly resistant to that idea.

Still, Shultz, in a talk with reporters aboard his airplane today, refused to concede that Assad's position will not change. He said:

"Yesterday we had a clear statement of no enthusiasm for the agreement as such. But we have no flat statement of 'we will not withdraw' or anything like that. They didn't slam the door on this subject. It was about what we expected would happen."

U.S. officials accompanying Shultz said privately that, while the effort could take three to four months, the administration is hopeful that Syria can be made to cooperate by marshaling a campaign of pressures and persuasion from moderate Arab governments.

That effort began last night when Shultz went from Damascus to Jeddah to confer with Saudi King Fahd. The Saudis contribute substantial financial support to Syria, and Assad flew to Jeddah today to discuss the Lebanon situation.

When Shultz left Jeddah this morning, Saudi Foreign Minister Saud Faisal told reporters: "I don't think the Syrian presence will be a bone of contention with the Lebanese government. The Syrians are not an occupying force. They are there at the request of the Lebanese government."

When Saud was asked if that meant Syria would withdraw its forces if Lebanon requested it, he replied, "that is what Syria has announced, and there has not been any change."

Later, on the flight from Jeddah to Jerusalem, Shultz responded to questions about Saudi leverage by saying: "We didn't discuss leverage or whether to use it. I think they understand the problem very well. I would refer you back to the statement made by the foreign minister at the airport. It is very significant."

In Jerusalem, where Shultz briefed Israeli Foreign Minister Yitzhak Shamir and Defense Minister Moshe Arens about his talks in Syria and Saudi Arabia, he said:

"I think at this point we can once again say what a great thing it is to have the agreement between Israel and Lebanon. We know that there are difficulties ahead, but we understand them and we can work with them."

Israel has been suffering what it regards as unacceptable casualties in Lebanon as a result of attacks from Syrian-supported guerrillas. That has caused concern that Israel might take action against the Syrians or consolidate its forces in the extreme south of Lebanon, leaving a void elsewhere in the country that would aggravate the civil warfare between Lebanese Christian and Druze factions.

However, Israel is understood to have told Shultz that, despite the bellicose talk by Damascus, it still considers its agreement with Lebanon valid and is willing to wait and see whether the Syrians will change their position.

Shultz then went to Beirut, where the internal fighting had caused a surge of artillery and rocket duels during the past two days. After meeting with Lebanese President Amin Gemayel, Shultz said:

"The shelling in this neighborhood in the last couple of days has been a disturbing matter . . . . Those countries that are occupying Lebanese soil have a responsibility to control any fire that comes from sections which they occupy."

Shultz said he was leaving Reagan's two special Middle East envoys, Philip C. Habib and Morris Draper, in Beirut to help Gemayel work on a cease-fire and to tie down the remaining details of the agreement with Israel.

Washington Post correspondent Edward Walsh reported from Jerusalem:

The Israeli Cabinet held its weekly meeting today but did not discuss the troop withdrawal agreement. There continue to be public calls for a unilateral Israeli withdrawal to south of the Awali River in Lebanon, 20 miles south of Beirut--a step that would put the Israeli Army in a stronger defensive position--but sources said that such a move is unlikely, at least for now.

Seven more Israeli soldiers were wounded today by an explosion north of Damur, above the Awali River, a continuing casualty toll that is fueling the demands for a unilateral pullback. But sources said Arens and others oppose such a step in part because of its likely effect on the U.S. contingent of the multinational force in Beirut.

It is assumed here that an Israeli withdrawal below the Awali would create a vacuum that would be quickly filled by Syrians and Palestinian guerrillas, possibly endangering the multinational force. Arens therefore was said to have argued that the Israelis should stay put for now, taking no unilateral steps without consultations with the United States, while hoping that American diplomacy and pressure from other Arab countries would eventually persuade Assad to agree to a withdrawal.

Domestic reaction to the agreement, which the Israeli government described as less than it sought and "the best we could get now," has been unenthusiastic, but there has been no strong outcry against it.