agent: Do signal handling under the hook

The agent developer can now just use a channel to detect that the agent process
should exit immediately. No need for manual signal handling

Fixes #1