The District government and lawyers for inmates of the modular facility at the city's Lorton prison complex signed an agreement yesterday to reduce crowding and improve living conditions there.

The agreement was reached after the prisoners' case was presented in a civil trial before U.S. District Judge June Green.

"We have been trying the case during the day and negotiating at night," said Jonathan M. Smith, a lawyer with the D.C. Prisoners' Legal Services Project. He said the inmates had a "very good case" and that the city "realized they were in a very difficult position."

Richard S. Love, who represented the D.C. Department of Corrections in the lawsuit, declined to comment on the proposed 23-page agreement.

Under the rules that govern class-action suits, the inmates will have an opportunity to comment on the consent decree before it is endorsed by Green.

The legal action was the sixth major class-action suit to be filed against the District alleging severe prison crowding.

In terms of population density, the modular facility "probably was the most overcrowded facility that we had seen at Lorton," said Alan A. Pemberton, one of several lawyers from Covington & Burling representing inmates.

The facility, designed for 400 prisoners, was holding more than 900 when the lawsuit was filed in March. The suit asserted that living conditions there were inhumane, and that the facility was crowded and filthy.

Corrections Director Walter B. Ridley said at the time the suit was filed that the prison held too many inmates. "I've said that in court testimony, that it's overcrowded," he said.

Lawyers said the population of the modular facility now is close to the maximum allowed by the consent decree, 688. "As the trial approached, the numbers came down," Pemberton said.

The lawsuit also asserted that showers and toilets were stopped up or inoperable much of the time and that bathrooms were filthy. In one case, the suit said, "half-inch-long black worms, living in a slimy area of chipped floor tile, infested the bathroom of one of the dormitories."

Pemberton said that "there was a greatly increased management attention to problems of sanitation" after the suit was filed.

The agreement requires the city to expand medical services, replace bed springs that can be removed by prisoners and used as weapons and implement a system to house prisoners according to behavior patterns to reduce violence among prisoners.