iPhones are able to detect if there is an AirTag (that doesn't belong to you), whether or not it is following you or not. However, if the person that owns the AirTag is with you, then it will not set off an alert because the parent device that is was set up with is near it.