fix agent code