async def _restart_on_cancel(logger, agent):
    """ Restarts an agent when it is cancelled """
    while True:
        try:
            await agent.run()
        except asyncio.CancelledError:
            logger.exception("Restarting agent")
            pass
Restarts an agent when it is cancelled