Reorganize agent code.