debugging AI agent loops that get stuck