Once it was overdue books. Now librarians fight overdoses.

The director of the public library in this Hudson Valley town calls his assistant and security guard “Starsky and Hutch.” They have been trained to spot signs of overdose in library patrons — paleness and shortness of breath when it is heroin; sudden collapse when it is fentanyl — and administer the drug naloxone. They patrol the bathrooms and stacks at the Middletown Thrall Library, checking on anyone who is dozing.

“It’s easier to call the police, to wait for E.M.S.,” said the library director, Matt Pfisterer, who had to decide whether to use the overdose-reversing drug himself a few years ago, after he found a woman lying in the grass outside, unconscious and covered with ants.

“You don’t know how they’re going to react,” he said. “But when it comes down to it, you ask, ‘Do I want to see this person dying in front of me?’ ‘No.’ So you take the leap.”