Previous experience plays a critical role in how subjects acquire and interpret sensory information. Expected stimuli for instance produce faster responses and can be discriminated with greater accuracy. Little is known however about how the brain circuitry accumulates experience over various time scales to build expectations and how these are combined with sensory information give rise to perception. In order to identify the neural basis of expectation and its impact on perceptual decisions we designed a variant of a standard two alternative forced-choice (2AFC) task that required the generation of an unbalanced prior that had to be updated trial-by-trial in order to maximize performance. Acoustic stimuli consisting in the superposition of two amplitude modulated tones of high and low frequency (31 kHz and 6.5 kHz) were presented to rats that were trained to associate each frequency to the delivery of water in the Right and Left ports. Stimuli were parameterized by the coherence c that set the relative weight of each tone: c = +1 or -1 represented the high and low tones in isolation, respectively, and c =0 a balanced superposition of the two. The two stimulus categories, i.e. sign(c) = +1 or -1, were presented randomly using a two-state Markov chain. Transitions were parameterized such that the probability of repeating the previous stimulus category was 0.5+lambda and the probability to switch was 0.5-lambda. The absolute value of the coherence was picked among the values 0, 0.1, 0.4 and 1, randomly and independently of previous history. We presented blocks of 200 trials with fixed lambda > 0 (repetitive environment) and lambda <0 (alternating environment) in a random order. We found that animals learned the statistics of each environment and made use of them to increase reward rate. Specifically, after error trials animals did not show a systematic choice bias that depended on recent trial history. After a correct trial however, the behavior showed a bias towards the same or the opposite choice depending on whether they were in the repetitive or in the alternating environments, respectively. Moreover, the magnitude of this choice bias increased with the number of correct past responses following the environment's sequence pattern (e.g. in the alternating environment, the probability of choosing Right conditioned of trial history grew as P(R|Error) < P(R|L, Error)< P(R|L,R, Error) < P(R|L,R,L,Error) < É). The magnitude of the biases were greater in the repeating than in the alternating environment. These results demonstrate that animals integrate the stimulus and rewards history to generate computationally advantageous priors. These priors are adapted to the statistics of the sensory environment but seem to be modulated by the changing confidence of the animal on the environment's statistical rule.