moved event handlers to agent.py