Split agent.js into multiple modules