Running an agent loop is easy. Knowing when to iterate, when to wait, and when to quit is the hard part.