Neural circuits detect environmental changes and drive behavior. The routes of information flow through dense neural networks are dynamic, but the mechanisms underlying this circuit flexibility are poorly understood. Here, we define a sensory context-dependent and neuropeptide-regulated switch in the composition of a C. elegans salt sensory circuit. The primary salt detectors, ASE sensory neurons, used BLI-4 endoprotease-dependent cleavage to release the insulin-like peptide INS-6 in response to large, but not small, changes in external salt stimuli. Insulins, signaling through the insulin receptor DAF-2, functionally switched the AWC olfactory sensory neuron into an interneuron in the salt circuit. Worms with disrupted insulin signaling had deficits in salt attraction, suggesting that peptidergic signaling potentiates responses to high salt stimuli, which may promote ion homeostasis. Our results indicate that sensory context and neuropeptide signaling modify neural networks and suggest general mechanisms for generating flexible behavioral outputs by modulating neural circuit composition.