Updated to use built-in JSON parsing in agents.
Agent is now, accordingly, much shorter.