Until the smart people arrive I'll throw in my limited understanding.
They can culture the bacteria ( or fungus or virus or whatever else is causing the RI ) from a swab of the mouth or a lungwash.
They spread the swab on the agar gel and apply a range of possible treatments.
Then they incubate it and see which treatment killed or retarded the growth the most.
This is then the one they prescribe to replace the broad spectrum that they give just after taking the swab.
dr del