A Montgomery County Court judge sentenced confessed burglar Thomas O'Leary yesterday to a 40-year prison term, brushing aside as irrelevant O'Leary's years of work as an informer and self-described police "agent" who helped put other criminals behind bars.

During the years he worked with law enforcement authorities throughout the metropolitan area, O'LEARY helped solve several major crimes, involving everything from drug-dealing to counterfeiting, from gambling to prostitution.

Then last July, the 32-year-old Silver Spring man, who shifted uneasily back and forth between the world of criminals and that of the people who catch them, was indicted for 26 burglaries of homes in affluent Bethesda neighborhoods.

"You deliberately violated people's right to sanctity in their homes," Circuit Court Judge David L. Cahoon told O'Leary.

"What arrangements law enforcement agencies enter into are not matters of concern to the court," the judge added. "I can't be bound by those arrangements and circumstances."

Those arrangements and circumstances, however, were the primary focus of yesterday's four-hour sentencing, extraordinary for both tis unusual length and the nature of the testimony.

The state's attorney's office had planned to call to the witness stand victims of O'Leary thefts, many of them residents of the county's most affluent areas. The thought of confronting his victims, he later said, caused O'Leary to deliberately miss the original sentencing proceeding scheduled in mid-March.

The victims did not testify but were in the audience yesterday, listening to police officials describe O'Leary increasingly active role in law enforcement work, listening to personal, often emotional pleas for compassion from his father and wife, and listening to O'Leary speak on his on behalf.

O'Leary was responsible for the largest cocaine seizure in the county's history, said Lt. Jim Elkins, director of the county division of vice and parcotics and the officer with whom O'Leary worked most closely.

Elkins said O'Leary did more than supply information. He often made the drug buys, at great personal risk, and in fact survived at least three attempts on his life, the police officer said.

Balanced against such testimony was a 14-page presentence report written by a probation officer, recommending "that the subject be given the maximum period of incarceration at minimum expense to the people of the state . . .

"It is obvious that the defendant worked with law enforcement over the years in attempt to avoid prosecution for his offenses."