Maryland prison authorities have agreed to seek immediate construction of a temporary, 840-bed prison--possibly in Somerset County--to relieve overcrowding in the state's 11,000-inmate system and end almost seven years of litigation by prisoners in federal court here.

In a formal agreement filed in U.S. District Court and signed last Friday by attorneys for the state and the prisoners, prison officials said they would ask the General Assembly to approve construction of the temporary facility on the same site as a permanent, 1,000-bed prison recommended recently by a prison task force appointed by Gov. Harry Hughes.

The agreement, which must be approved by federal Judge Alexander Harvey II, calls for completion of the temporary facility by the end of this year. Prison officials said its buildings would ultimately be combined with the permanent facility.

On Feb. 1, the governor's task force recommended two possible sites for the permanent facility, both in Somerset County on the lower Eastern Shore, provoking angry reaction by county commissioners and residents who say they don't want prisoners there despite the financial boost the facility could mean for the economically depressed area. The five-member county commission originally requested the prison, but later changed its mind.

Meanwhile, prison officials are drawing up tentative construction and operating costs for the proposed temporary facility, according to Wayne Winebrenner, assistant commissioner for field services in the state division of correction. He said he was unable to estimate the cost of the facility now, but legislation for it probably will be introduced in the legislature within two weeks.

The agreement on the temporary facility was reached after years of litigation by prisoners at the Maryland House of Correction in Jessup and the Maryland Correctional Institution in Hagerstown.

The proposed prison is part of a larger agreement for improving living conditions, and attorneys on both sides say it does not end the litigation.

First, it must be approved by Judge Harvey, who has presided over the case since prisoners filed lawsuits in 1977 and 1978, contending that overcrowded conditions violated Eighth Amendment protections against cruel and unusual punishment. Harvey's approval or disapproval is at least a month away.

Prisoner attorney Paul D. Bekman said the agreement would eliminate what is called "double celling" and "double bunking," the practices of putting two inmates in a cell designed for one inmate and using double bunk beds in dormitories designed for single beds. It would also provide for at least 40 square feet per prisoner in dormitories.