Implements most of the agent, with a few to-dos