Fix null reference in Agent