Responsiveness to external cues is a hallmark of biological systems. In complex environments, it is crucial for organisms to remain responsive to specific inputs even as other internal or external factors fluctuate. Here, we show how the nematode Caenorhabditis elegans can discriminate between different food levels to modu- late its lifespan despite temperature perturbations. This end-to-end robustness from environment to physi- ology is mediated by food-sensing neurons that communicate via transforming growth factor β (TGF-β) and serotonin signals to form a multicellular gene network. Specific regulations in this network change sign with temperature to maintain similar food responsiveness in the lifespan output. In contrast to robustness of stereotyped outputs, our findings uncover a more complex robustness process involving the higher order function of discrimination in food responsiveness. This process involves rewiring a multicellular network to compensate for temperature and provides a basis for understanding gene-environment interac- tions. Together, our findings unveil sensory computations that integrate environmental cues to govern physiology.