implemented agent event loops with thread-safe message enqueueing and handling