Two ways: Record inputs and time, or record absolute position and time.
Either way, storage would probably be done via an array. For example...
Every x seconds, push sprite.x to array, set sprite.y to array at (0,1)
Would populate an array with the sprite position x and y every x seconds. Then save the array, and have your ai move to each position in the array in sequence.
Alternatively, you would save what the player was inputting at every time instead of the sprite's position
Depending on your game and how it is set up, either of these approaches could be optimized for further detail.