Fixing NPE issue when running a task with no agent assigned