#6 #8 Fix template typo, fix agent loop