Clearly once you have run out of the temporary hit points (THPs) provided by the spell or they have been replaced by choosing to take temporary hit points from another source, creatures hitting you no longer take damage. However, RAW, the spell does not end until the 1 hour duration has expired, it just provides you with no benefits.
Armor of Agathys PHB p.215
Duration: 1 hour
A protective magical force surrounds you, manifesting as a spectral frost that covers you and your gear. You gain 5 temporary hit points for the duration. If a creature hits you with a melee attack while you have these hit points, the creature takes 5 cold damage.
The wording of the spell suggests that the spell continues to run even after the THPs are gone: "If a creature hits you with a melee attack while you have these hit points, the creature takes 5 cold damage" suggesting the spell continues but does not inflict damage, as opposed to a description such as "When the THPs are used up the spell ends".
Can you benefit from a second (or third etc.) casting of the same spell within the duration or does it need to be dispelled first?
To be clear this is not a question fishing for more THPs at one time by power gaming the spell, it is about what occurs when the THPs of the spell run out and you want to recast.