In a case publicized everywhere from local radio to “The Tonight Show” with Jay Leno, senior Brian Tippy — arrested after he allegedly asked Yale police to test the purity of the drugs he had purchased — reached an agreement Friday with state prosecutors that allows him to complete drug education classes and eventually to have the arrest removed from his permanent record.

In court, Judge Joan Alexander accepted the agreement and set Tippy’s next hearing date for Aug. 26. If he attends all of the required sessions of the drug education program by then, the charges will be dropped.

“It’s not ‘guilty,’ and it’s not ‘not guilty,'” Tippy said.

“It’s basically equivalent to a dismissal,” Tippy’s lawyer, William F. Dow III, said.

Tippy was arrested at 5 a.m. on Jan. 17 after he allegedly brought a small bag containing white powder to the Yale Police substation at Phelps Gate.

“He said that he had just purchased what he thought were drugs and wanted to test their purity,” Yale Police Lt. Michael Patten said.

Police administered a field test to the substance and discovered that it tested positive for narcotics. Tippy was charged with drug possession and arrested at the scene.

The case even reached the national spotlight when Jay Leno used it as part of his monologue last Thursday night.

“He takes this to the police, the police test it, determine it is heroin and they arrest him,” Leno said — without explicitly naming Tippy. “Here’s the scary part: This guy goes to Yale University. How dumb are the kids at DeVry?”

But Tippy has maintained that his case is more complex than mere drug possession. He said that as he was walking home to campus on Jan. 17, someone approached him and offered him drugs.

“Of course I would never ask for drugs, and I never will,” Tippy said. “I just wanted to do something about it.”

Dow also emphasized that Tippy never meant for events to transpire as they did.

“He never had criminal intent. [He] was just trying to help law enforcement,” Dow said. “He was trying to rid the campus area of drug dealers, but in a terribly naive and foolish way. This time things just went awry.”