An Algorithm for Psychological Treatment of an Intelligent Agent