The ability to evaluate variability in the environment is vital for making optimal behavioral decisions. Here we show that Caenorhabditis elegans evaluates variability in its food environment and modifies its futurebehavior accordingly. We derive a behavioral model that reveals a critical period over which information about the food environment is acquired and predicts future search behavior. We also identify a pair of high-threshold sensory neurons that encode variability in food concentration and the downstream dopamine-dependent circuit that generates appropriate search behavior upon removal from food. Further, weshow that CREB is required in a subset of interneurons and determines the timescale over which the variability is integrated. Interestingly, the variability circuit is a subset of a larger circuit driving search behavior, showing that learning directly modifies the very same neurons driving behavior. Our study reveals how a neural circuit decodes environmental variability to generate contextually appropriate decisions.