Make agent_socket.py more fault tolerant