Skip to content

Component configer util

ComponentConfigerUtil

Bases: object

The ComponentConfigerUtil class, which is used to load and manage the component configuration.

Source code in agentuniverse/base/component/component_configer_util.py
Python
class ComponentConfigerUtil(object):
    """The ComponentConfigerUtil class, which is used to load and manage the component configuration."""

    __COMPONENT_CONFIGER_CLZ_MAP = {
        ComponentEnum.AGENT: AgentConfiger,
        ComponentEnum.KNOWLEDGE: KnowledgeConfiger,
        ComponentEnum.LLM: LLMConfiger,
        ComponentEnum.PLANNER: PlannerConfiger,
        ComponentEnum.TOOL: ToolConfiger,
        ComponentEnum.MEMORY: MemoryConfiger,
        ComponentEnum.SERVICE: ServiceConfiger,
        ComponentEnum.PROMPT: PromptConfiger,
        ComponentEnum.DEFAULT: ComponentConfiger
    }

    __COMPONENT_MANAGER_CLZ_MAP = {
        ComponentEnum.AGENT: AgentManager,
        ComponentEnum.KNOWLEDGE: KnowledgeManager,
        ComponentEnum.LLM: LLMManager,
        ComponentEnum.PLANNER: PlannerManager,
        ComponentEnum.TOOL: ToolManager,
        ComponentEnum.MEMORY: MemoryManager,
        ComponentEnum.SERVICE: ServiceManager,
        ComponentEnum.PROMPT: PromptManager
    }

    @classmethod
    def get_component_config_clz_by_type(cls, component_type_enum: ComponentEnum) -> \
            Type[ComponentConfiger | LLMConfiger]:
        """Get the ComponentConfiger object by the component type.
        Args:
            component_type_enum(ConfigTypeEnum): the component type
        Returns:
            ComponentConfiger: the sub object of ComponentConfiger
        """
        component_config_clz = cls.__COMPONENT_CONFIGER_CLZ_MAP.get(component_type_enum)
        if component_config_clz is None:
            raise Exception(f"Failed to get the ComponentConfiger class by the component type: {component_type_enum}")
        return component_config_clz

    @classmethod
    def get_component_object_clz_by_component_configer(cls, component_configer: ComponentConfiger) -> Callable:
        """Get the component object by the ComponentConfiger object.
        Args:
            component_configer(ComponentConfiger): the ComponentConfiger object
        Returns:
            object: the component object
        """
        module = importlib.import_module(component_configer.metadata_module)
        clz = getattr(module, component_configer.metadata_class)
        return clz

    @classmethod
    def get_component_manager_clz_by_type(cls, component_type_enum: ComponentEnum) -> Callable:
        """Get the ComponentManager object by the component type.
        Args:
            component_type_enum(ConfigTypeEnum): the component type
        Returns:
            object: the ComponentManager object
        """
        return cls.__COMPONENT_MANAGER_CLZ_MAP.get(component_type_enum)

get_component_config_clz_by_type(component_type_enum) classmethod

Get the ComponentConfiger object by the component type. Args: component_type_enum(ConfigTypeEnum): the component type Returns: ComponentConfiger: the sub object of ComponentConfiger

Source code in agentuniverse/base/component/component_configer_util.py
Python
@classmethod
def get_component_config_clz_by_type(cls, component_type_enum: ComponentEnum) -> \
        Type[ComponentConfiger | LLMConfiger]:
    """Get the ComponentConfiger object by the component type.
    Args:
        component_type_enum(ConfigTypeEnum): the component type
    Returns:
        ComponentConfiger: the sub object of ComponentConfiger
    """
    component_config_clz = cls.__COMPONENT_CONFIGER_CLZ_MAP.get(component_type_enum)
    if component_config_clz is None:
        raise Exception(f"Failed to get the ComponentConfiger class by the component type: {component_type_enum}")
    return component_config_clz

get_component_manager_clz_by_type(component_type_enum) classmethod

Get the ComponentManager object by the component type. Args: component_type_enum(ConfigTypeEnum): the component type Returns: object: the ComponentManager object

Source code in agentuniverse/base/component/component_configer_util.py
Python
@classmethod
def get_component_manager_clz_by_type(cls, component_type_enum: ComponentEnum) -> Callable:
    """Get the ComponentManager object by the component type.
    Args:
        component_type_enum(ConfigTypeEnum): the component type
    Returns:
        object: the ComponentManager object
    """
    return cls.__COMPONENT_MANAGER_CLZ_MAP.get(component_type_enum)

get_component_object_clz_by_component_configer(component_configer) classmethod

Get the component object by the ComponentConfiger object. Args: component_configer(ComponentConfiger): the ComponentConfiger object Returns: object: the component object

Source code in agentuniverse/base/component/component_configer_util.py
Python
@classmethod
def get_component_object_clz_by_component_configer(cls, component_configer: ComponentConfiger) -> Callable:
    """Get the component object by the ComponentConfiger object.
    Args:
        component_configer(ComponentConfiger): the ComponentConfiger object
    Returns:
        object: the component object
    """
    module = importlib.import_module(component_configer.metadata_module)
    clz = getattr(module, component_configer.metadata_class)
    return clz