Refactored AgentWrapper.