Merged rest of the agent client and server code.