Motivated by the close relation of predictive coding and activeinference to cognition, we introduce a dynamic artificial neu-ral network-based (ANN) adaptation process, which we termREPRISE: REtrospective and PRospective Inference SchEme.REPRISE first executes a retrospective inference process, in-ferring the unobservable contextual state that best explains itsrecently encountered sensorimotor experiences. It then exe-cutes a prospective inference process, inferring upcoming mo-tor activities in the light of the inferred contextual state anda given goal state. First, the ANN – a recurrent neural net-work – is trained to learn one sensorimotor temporal forwardmodel, that is, the sensorimotor contingencies generated by thebehavior of three moving or flying vehicles. During training,additional three bits are provided as input, indicating whichmode currently applies. After training, goal-directed controland system state inference are activated: Given a goal state,the system imagines a motor command sequence optimizing itwith the prospective objective to minimize the distance to thegoal. Meanwhile, the system evaluates the encountered sen-sorimotor contingencies retrospectively, adapting its vehicleestimation activities and, in order to maintain coherence, theneural hidden states accordingly. This ANN’s ’mind’ is thuscontinuously imagining the future and reflecting on the past –showing superior performance on the posed control problems.The architecture effectively demonstrates that neural error sig-nals and neural activities can be projected into the past and intothe future, respectively, optimizing both neural context codesthat approximately generate the recent past and upcoming be-havior in the light of desired goal states.