The trail that led Rep. Leo J. Ryan (D-Calif.) to his death in the jungles of Guyana began two years ago and thousands of miles away in San Francisco with another death - that of a young religious cult member.

When the mangled body of Bob Houston, a railroad worker, was found on the San Francisco tracks in the predawn hours of Oct. 5, 1976, the incident was written off as an accident.

But the dead man's father, Sam Houston, an Associated Press photographer, was a friend of Ryan. Shortly afterward, according to Ryan's aides, Houston told the San Francisco-area congressman how his son's body had been found on the day after he announced his intention to quit the religious cult known as the Peoples Temple.

In what his aides described as an emotional scene, Ryan, who had once been the younger Houston's high school teacher, promised to look into the activities of the cult, which had a flourishing membership in the San Francisco area.

Over the ensuing months, Ryan's dogged poking into the affairs of the Peoples Temple of its leader, Jim Jones, produced a picture of an organization that outwardly preached brotherhood and communal harmony to its members but ruled them internally through violence and fear.

From accounts of former cult members and the relatives of those on the inside, Ryan compiled a thick dossier of allegations that the cult, both in California and at its agricultural commune in Guyana, was holding people against their will, subjecting them to harsh physical punishment and forcing them to surrender all their belongings and money to the Peoples Temple.

But, his staff aides charged yesterday, when Ryan tried to get the State Department to do something about the reports of abuse in Guyana, the department's efforts proved so unproductive that he finally felt compelled to go to Guyana and investigate the situation on his own.

There, the trail ended last weekend in the macabre chain of events that saw the murder of Ryan and four companions and the apparent mass suicide-murders of hundreds of the cult's members.

Yesterday, friends and aides of Ryan bitterly declared that his death could have been avoided - that he was a victim of the State Department's failure to adequately investigate the situation in Guyana and warn the congressman of the dangers he would face there.

One member of his House staff, who asked to remain anonymous, summed up their feelings this way: "Sure, State briefed him completely on what they knew, but when he got there he found out they didn't know very much. They didn't warn him of what he'd he walking into. They made it sound like a bed of flowers."

These charges were denied quietly but firmly by department officials, who insisted both that the charges of abuse at the Guyana commune had been investigated conscientiously and that Ryan had been told of the perils he might encounter.

At a lengthy meeting with reporters, john A. Bushnell, a deputy assistant secretary of state for inter-American affairs, said Ryan had been given all the pertinent information in the department's possession but had not been advised either to make or avoid the trip.

"We find it difficult to say to any congressman that he should not visit any American citizens, particularly his constituents, anywhere in the world," Bushnell said. "It was proper for us to leave to him the choice of whether or not to make the visit . . ." Bushnell also noted that U.S. consular officials in Guyana had visited the commune four times this year most recently on Nov. 7 - and, on each occasion, had privately interviewed cult members described in complaints from relatives as being held against their will.

"More than 75 temple members talked to our consular officers over the last year, and not one confirmed any allegation of mistreatment," Bushnell said.

He said the department held several briefings for Ryan, the most recent on Sept. 15. In them, Bushnell added, the congressman was told that the commune had armed guards, that it was in a remote inaccessible area with "no significant law enforcement presence" and that the powers of the U.S. embassy 150 miles away in the capital, Georgetown, were limited in terms of the protection it could provide.

However, despite the facts cited by Bushnell, questions were still being raised last night by Ryan's friends and relatives of people in the cult about whether the State Department had treated the situation with sufficient seriousness and priority.

Several relatives, for example, pointed out that persons asking the department for information about the Peoples Temple in recent months were sent a form-letter reply that described the Guyana commune in almost rosy terms. After noting that U.S. consular officers periodically visited the commune, the letter added:

"It is the opinion of these officers, reinforced by conversations with local officials who deal with the Peoples Temple, that it is improbable anyone is being held in bondage. In general, the people appear healthy, adequately fed and housed, and satisfied with their lives on what is a large farm. Many do hard physical labor, but there is no evidence of persons being forced to work beyond their capacity or against their will."

In private, some department officials said a small embassy like the U.S. mission in Guyana, which has two overworked consular officials, doesn't have the capacity to make indepth investigations of the type Ryan wanted.

These officials noted that distance and difficult terrain made it impossible to visit the commune except at sporadic intervals, that U.S. constitutional guarantees of religious freedom placed restrictions on the kinds of inquiries embassy officials could make, and that the inquiries were being carried out in a foreign country whose government has a record of tolerating odd religious sects in general and the Peoples Temple commune in particular.

But, some of the officials conceded privately, the big upsurge of participation by U.S. citizens abroad in cults and counterculture activities during recent years has caused many embassies to take a permissive approach toward their activities and concentrate on other problems.

That, they said, frequently has been the case even when complaints are forwarded for investigation from high-level government officials, such as Secretary of State Cyrus R. Vance and Vice President Mondale, who had received complaints from relatives of Temple members. For example, the officials pointed out, when Ryan last conferred with senior State Department officials on Sept. 15, they were preoccupied with the bloody civil war in Nicaragua and undoubtedly were too busy to pay much attention to a group of religious fanatics in Guyana.

But the officials insisted that given these limits, the department, working through the embassy in Guyana, conscientiously tried to check out every allegation of abuse it received about the commune. And, they added, despite the complaints by Ryan's staff, the congressman, in that Sept. 15 meeting, conceded that the department had done all that was possible within its power.

Following the meeting, the officials said, Viron P. Vaky, assistant secretary for inter-American affairs, sent a message to the embassy in Georgetown saying Ryan had found no fault with the embassy's handling of the situation.But, Vaky's message added, the Congressman indicated that he was planning to visit Guyana because he felt "stronger measures were now required." CAPTION: Picture 1, REP. LEOJ. RYAN . . . shortly before his death, Copyright(c) 1978, The San Francisco Examiner; Picture 2, In 1970, then-assemblyman Ryan spent a week living behind bars at Californas Folsom prison to learn what was needed for prison reform. "The greatest thing I learned there was not to be afraid anymore," he later told a friend, AP