To survive in ever-changing environments, living organisms need to continuously combine the ongoing external inputs they receive, representing present conditions, with their dynamical internal state, which includes influences of past experiences. It is still unclear in general, however 1) how this happens at the molecular and cellular levels and 2) how the corresponding molecular and cellular processes are integrated with the behavioral responses of the organism. Here, we address these issues by modeling mathematically a particular behavioral paradigm in a minimal model organism, namely chemotaxis in the nematode C. elegans. Specifically, we use a long-standing collection of elegant experiments on salt chemotaxis in this animal, in which the migration direction varies depending on its previous experience. Our model integrates the molecular, cellular, and organismal levels to reproduce the experimentally observed experience-dependent behavior. The model proposes specific molecular mechanisms for the encoding of current conditions and past experiences in key neurons associated with this response, predicting the behavior of various mutants associated with those molecular circuits.