Use minetest.line_of_sight. Mobs will only add targets they can see directly.