Register a SIP programmatically

Can I programatically enter a record into the ps_contacts table to make an agent go online or offline. Or is there any other way to register a sip device in the asterisk service to set an agent online or offline.

It’s not really made to do that. What exactly are you trying to achieve (without going into implementation detail)?