It doesn't "know" anything. A thermos slows down the flow of heat, full stop. Doesn't matter if the heat is flowing in or out, the thermos slows it according to the basic physical laws of the universe.
If you really want to understand thermal flow, and electricity, and things like force and momentum and energy, study physics.