agentFactory.py 728 B

1234567891011121314151617181920212223
  1. # -*- coding: utf-8 -*-
  2. from ..builder import AGENTS
  3. from ..agentBase import BaseAgent
  4. from typing import List
  5. from yacs.config import CfgNode as CN
  6. from digitalHuman.utils import logger
  7. from digitalHuman.protocol import ENGINE_TYPE
  8. class AgentFactory():
  9. """
  10. Agent Factory
  11. """
  12. @staticmethod
  13. def create(config: CN) -> BaseAgent:
  14. if config.NAME in AGENTS.list():
  15. logger.info(f"[AgentFactory] Create instance: {config.NAME}")
  16. return AGENTS.get(config.NAME)(config, ENGINE_TYPE.AGENT)
  17. else:
  18. raise RuntimeError(f"[AgentFactory] Please check config, support AGENT engine: {AGENTS.list()}")
  19. @staticmethod
  20. def list() -> List:
  21. return AGENTS.list()