Rewrite Agent.js