WORKING VERSION! Agent doesn't crash when tree depth > 1