Rep. Frederick W. Richmond (D-N.Y.) is attempting to prevent a federal grand jury in Brooklyn from subpoenaing his office files, which might relate to convict Earl W. Randolph Jr., on the ground that they are protected by the speech-and-debate clause of the Constitution, according to informed sources.

That clause, which was designed to protect legislators from investigation or prosecution for their legislative actions, also was invoked last month by three top Richmond aides who had been called to testify before the grand jury.

Randolph was a fugitive from Massachusetts prison authorities in January, 1981, when, with Richmond's recommendation, he was given a job on the staff of the House doorkeeper under an assumed name.

The aides, Richmond administrative assistant Arthur Craig, staff assistant Judith A. Berman and Agriculture subcommittee consultant Carolyn Morrow Cheney, each initially refused to answer questions about "Mr. Richmond's relationship" with Randolph before the grand jury on April 26, according to a memo filed with the federal court in Brooklyn by the U.S. attorney.

The aides' refusals, the memo said, was based on their interpretation that the speech-and-debate clause covered all conversations between a congressman and his aides.

Last week U.S. District Court Judge Jack Weinstein held a hearing on the question of the aides' testimony and Richmond's lawyer was allowed to participate.

Government lawyers argued that the Richmond staff lawyer failed to show how the clause, which is not supposed to cover political as opposed to legislative matters, was applicable to questions about Randolph.

Weinstein then ruled that the three would have to testify before the grand jury about their knowledge of the millionaire congressman's relationship with Randolph.

The grand jury, according to the government lawyers' presentation to Judge Weinstein, is investigating whether Richmond aided Randolph knowing he was a fugitive. To do so is a violation of federal law.

Berman has worked on Richmond's congressional staff since September, 1976, according to records of the Clerk of the House. The records also show that Cheney joined in 1978 and Craig in 1979.

Another Richmond staff aide, Patricia Lott, has been identified by Massachusetts correctional authorities, according to published reports, as the person who made telephone calls in 1979 to the Warwick, Mass., prison camp where Randolph was serving an 18-year sentence for assault with intent to murder.

Lott left Richmond's staff last October and briefly returned to her parents' home in South Carolina. According to her mother, Lott recently returned to Washington.

Randolph escaped from a halfway house in Boston in July, 1980, when he was about to be returned to prison for using drugs, according to published reports.

He left his job with the House doorkeeper on Feb. 28, 1981, and was subsequently arrested in New York on March 25, 1981, on a charge of male prostitution when he solicited an undercover policeman and suggested they perform a sexual act in a car that turned out to be Richmond's.

New York police then discovered he was a fugitive and he was returned to prison in Massachusetts. He is now in the federal penitentiary at Danbury, Conn., in the custody of the U.S. attorney who is conducting the investigation of Richmond.