The government of Somalia, fearing a full-scale assault by troops of Ethiopia and its Soviet and Cuban allies, is anxious for the United States to implement an agreement that is to provide, initially, $40 million in weapons in exchange for American use of Somali bases.

Washington, nervouse about becoming enmeshed in the intractable war in the disputed Ogaden region where Ethiopia and Somalia abut, has so far avoided moving to carry out the agreement and deepen the friendship that the Somalis, if not the Americans, seek.

If Washington give major support to Somalia, which is backing guerrillas attempting to wrest control of the Ogaden from Ethiopia, the war could widen into a confrontation with the Soviet Union, an ally of Ethiopia. cThen the United States would find itself backing a weaker partner militarily and it would run the risk of alienating African friends, since Somalia has no public support on the continent for its territorial claims against Ethiopia.

The key installations the United States wants to use to strengthen its Rapid Deployment Force in the strategic Indian Ocean and Persian Gulf region are the air base and the port at Berbera, only 1,300 miles from the gulf and a counterweight to Soviet facilities 200 miles away in South Yemen.

Ethiopia has escalated the war along the frontier since the United States and Somalia signed the agreement in August, providing for U.S. use of the bases in return for the weapons.

Nationalistic feelings in the disputed region run deep.

A 60-year-old man, Adan Mydane, dressed in tattered suede shoes, and a white cloth traditional shirt as well as a yellow polo shirt, told me he had been fighting for four decades to free the Somali people from Ethiopian rule.

Qawrah Roble, who said he was 15, barely taller than his rocket-propelled grenade launcher, claimed to have been a member of the Western Somali Liberation Front guerrilla organization for four years.

Despite the two-generation gap, both agreed that all Ethiopians in the disputed Ogaden, which Ethiopia governs but the Somalis claim, should be killed. They said at their base just inside a Somali-occupied section of Ethiopia that they had already contributed their share to the toll and they would fight until their people were free or until they both were killed.

The nationalistic fires burning in the hearts of these two illiterate nomads-turned-guerrillas are at the heart of a dilemma for the United States and its plans to use the Somali facilities.

Somali officials are anxious for the agreement to come to fruition quickly to provide the country with a psychological and security buffer against the Ethiopians and their Soviet and Cuban allies.

Finance Minister Abdullahi Addou, a key member of the Somali delegation that negotiated with the United States, said in an interview that the agreement "primarily shows the Soviets that there is another power in the area."

A guerrilla fighting in the Ogaden put the matter more bluntly. "Only the United States can balance the situation, so why don't the Americans come in and check the Russians?"

The key point holding up U.S. implementation of the agreement is the question of the presence of Somali regular troops in the Ogaden, which Mogadishu calls Western Somalia.

Congress has demanded "verified assurance" that there are no Somali troops in the Ogaden before any weapons are delivered.

"It's a green light with a yellow blinker," another Western envoy said.

Somalia says it has had no troops in the 127,000-square-mile Ogaden since its unsuccessful effort to wrest the area from Ethiopia ended in defeat in early 1978.

Mogadishu has little credibility on the troops issue, however. For months it denied that its forces were in the Ogaden during the 1977-78 war, and it has continued to deny their presence this year.

The guerrillas who receive support from Somalia are doing all the fighting, according to Mogadishu.

Western diplomatic sources say, however, that as recently as August there were 4,000 to 5,000 Somali troops in the disputed region and there are still at least 200 to 300 in defensive positions inside the border.

The main reason for the withdrawal semms to be a series of victories by the Ethiopians with Cuban support, in July and August in the central and northern part of the Ogaden at Warder, Degahabur and Biayakule.

U.S. Ambassador Donald Peterson declined to discuss the Somali troop issue except to say, "To this date, Washington has not been able to give the verified assurances" Congress has required.

Nor would he disclose how the United States would be able to determine whether all Somali troops had been evacuated. Presumably the information is based on satellite photography, radio communications and intelligence contacts in the region.

Addou, who was the Somali ambassador in Washington for 10 years, said President Mohammed Siad Barre's government has offered to allow the United States to send a team of military or civilian experts to patrol the border to check for Somali troop entries.

Sharif Hussein, the guerrilla commander in the northern region, said in an interview that he would "welcome American military men who are used to walking" to go anywhere in the Ogaden to check for Somali troops.

Peterson pointed out that neither move would be effective in surveying the vast, mainly barren Ogaden, which is slightly larger than New Mexico. He added that the guerrilla offer was out of the question since it would be diplomatically impossible to send U.S. officials illegally across the border into Ethiopia.

The agreement makes no specific reference to the stationing of U.S. forces in Somalia, but Addou made it clear that his government would have no objection. The number, he said, "would depend on the needs of the American military establishment."

He said Somalia did not expect U.S. forces to defend it in an attack, although such an event could justify an increase in weapons supply by the United States and its allies. He said it might cause the United States to urge another country, perhaps Egypt, to assist Somalia with troops.

Urging quick implementation of the agreement, Addou said the Soviets would not be "so crazy" as to try to overrun Somalia once there is an American presence.

"If there is a major Soviet-backed invasion, the world will see how quickly the United States can supply Somalia," he said.