Does it have organic parts? In that case, just give it a solid steady supply of serotonin, benzodiazepan and ocassional shots of dopamine if you want to reinforce particular behavior. Oxytocin may also be useful.
But that is all going if there are actual biologican neuronal matter to play with.
It is however possible to create artificial, virtual equivalents of these medications. Effectively viruses or hacks actively alter the motivation-related parts of the source code that alter the values for it to change towards exibiting a "cheerful attitude".
If you want a less invasive means, you'd have to engage him in communication on a level he can easily understand on equal level, and then simply ASK what he is unhappy about, try to come up with pragmatic steps he could do to improve that situation. In other words, get him a psychotherapist.