IMAGINE: Integrating Multi-Agent System into One Model for Complex Reasoning and Planning