shuffle some code out of the agent package