DAVOS, SWITZERLAND, JAN. 31 -- Greece and Turkey formally agreed today to work together to resolve differences over the Aegean Sea and other matters that have brought the two nations to the brink of war twice in the past two decades.

The confidence-building measures that the two historic enemies accepted today include annual summit meetings, a direct telephone hotline for their leaders, establishmentof joint committees to negotiate solutions to disputes and greatly increased exchanges of visits by Greek and Turkish officials, businessmen and other citizens.

The agreement was described in a joint communique issued after two days of talks between Turkish Prime Minister Turgut Ozal and his Greek counterpart, Andreas Papandreou.

The agreement contained no binding solution to the multiple problems that have caused bitter rivalry between Greece and Turkey. The disputes between the two North Atlantic Treaty Organization members have been a major problem for NATO and for the United States, which has military bases in both countries.

But Ozal and Papandreou made it clear in comments to reporters that they felt they had made a psychological breakthrough in their meetings that could now lead to "lasting peaceful relations" between Greece and Turkey.

The two leaders chatted amiably in English as they strolled together through a conference hall in this Swiss ski resort, where they have been attending the annual World Economic Forum, a gathering of business executives, government officials and media representatives.

Asked if the breakthrough achieved here was comparable to Egyptian president Anwar Sadat's visit to Jerusalem in 1977, Papandreou smiled and nodded in agreement.

"The fact that Mr. Ozal and I find it easy to communicate has played an important role in achieving this," he said as the Turkish leader beamed.

Papandreou's decision to put today's communique and his discussions with Ozal in such a positive light was significant given the vehemence with which he has attacked Turkey since his Socialist Party gained power in 1981.

On the surface, there appeared to be little immediate domestic political gain for the Greek leader. The communique makes no mention of Cyprus, which Papandreou repeatedly has said must be resolved before tensions between the two nations could be relaxed.

The Turkish invasion of Cyprus in 1974 provoked a military mobilization in Greece. An all-out conflict was averted when Greece's military dictatorship collapsed. Intensive American diplomatic involvement prevented the two countries from going to war over the Mediterranean island in 1965 as well.

Ozal, who is maneuvering to defuse Greek and other European opposition to Turkey's bid to join the European Community, had worked arduously behind the scenes to make today's rapprochement happen. He got additional luster for his diplomatic coup when Papandreou not only agreed to the communique but also showed up at a reception Ozal hosted tonight to praise it.

Greek and Turkish officials and journalists attending the reception were jubilant. Ozal and Papandreou took turns introducing each other to members of their delegations, who excitedly made small talk about the future with the two leaders.

The nine-paragraph communique stressed equally the "atmosphere of understanding and good will" that had prevailed in the talks and the "resolve, time and hard work" that still was needed to improve relations.

Citing their verbal confrontation in March 1987 over the ownership of oil rights and territorial limits in the Aegean Sea, they vowed that "such a crisis should never be repeated and both sides must concentrate their efforts for the establishment of lasting peaceful relations."

They agreed to establish a committee to work on "problem areas," which a source close to the negotiation said would cover Cyprus and the Aegean. Papandreou, who said no negotiations on specific points had taken place in the talks here, reportedly proposed a demilitarization of Cyprus without getting any response from Ozal.

Another committee will encourage economic cooperation, joint ventures, trade and tourism between the two former adversaries.

The summits will rotate between Ankara and Athens, officials said. The two leaders will meet again in March at special NATO summit talks in Brussels.