Refactor the agent main logic to be a bit clearer