Is there a way to inspect a roof to know whether the asphalt shingles need to be replaced?
Short of actual leaks (which are better avoided by replacing before you notice them) aging in asphalt shingles (if you don't know when they were installed) is assessed by observing loss of the mineral covering and any signs of cracks developing, or loss of bond allowing the tabs to "flap" in the wind.
If you do know when it was installed, and it was 25 years or more in the past, assume you should plan to replace it unless you are quite sure it was claimed to have a longer lifespan and actually appears to be in good shape. If you don't know the claimed lifespan but it appears to be in good shape, start saving money for a replacement, at least.
In no case should you do any business with "drive-by" roofers nor should you let them "inspect" your roof. Contact a reputable local roofing contractor if you have concerns. The "drive-by" sort are a long-running but obviously effective enough (as they have been running for decades) scam of doing shoddy work and leaving town, and sad to say they may actually damage your roof while "inspecting" it to make a quick sale.