iflytek/astron-agent · error · ValueError

No factory registered for the service class

Error message

No factory registered for the service class '{service_name.name}'

What it means

ServiceManager._validate_service_creation raises ValueError when the requested service class has no factory registered in self.factories. The manager can only construct services whose class was previously registered via a register/register_factory call.

Solutions

  1. Register a factory for the service class before creating it: service_manager.register_factory(ServiceClass, FactoryClass).
  2. Ensure the module containing register_factory calls is imported at application startup (check lifespan/init code).
  3. Verify the exact class object passed to create_service matches the one registered (same import path, no duplicate class definitions).
  4. Grep for 'register_factory' to see which services are registered in this deployment.

Example fix

// before
service = service_manager.create_service(MASDKService)  # ValueError: no factory
// after
from workflow.extensions.middleware.masdk.factory import MASDKServiceFactory
service_manager.register_factory(MASDKService, MASDKServiceFactory)
service = service_manager.create_service(MASDKService)
Defensive patterns

Strategy: validation

Validate before calling

if not hasattr(service_manager, "factories") or ServiceClass not in service_manager.factories:
    raise RuntimeError(f"{ServiceClass.__name__} factory not registered; call register_factory first")

Type guard

def factory_registered(mgr, cls) -> bool:
    return cls in getattr(mgr, "factories", {})

Try / catch

try:
    service = service_manager.create_service(ServiceClass)
except ValueError as e:
    logger.error(f"Service factory missing: {e}")
    raise

Prevention

When it happens

Trigger: Calling service_manager.create_service(SomeServiceClass) (or get_service) where SomeServiceClass was never passed to register_factory; a typo in the service class; using a service class defined in a module whose registration code was never imported at startup.

Common situations: Forgetting to import the factory registration module (e.g. the masdk factory) before boot; renaming a service class so the registration key no longer matches; adding a new middleware service without registering its factory.

Understand the failure class

Background: "not installed", "pip install", "required for": how missing-dependency errors surface across open-source libraries — this error's family across 34 libraries.

Related errors


AI-assisted analysis of iflytek/astron-agent@5e758547a8 (2026-09-12). Data as JSON: /api/errors/e3578b486e2bdc95. Report an issue: GitHub.

Appendix: source

Thrown at core/workflow/extensions/middleware/manager.py:96

        :param service_name: The name of the service to create
        """
        logger.info(f"🔍 Creating service: {service_name}")
        self._validate_service_creation(service_name)

        # Create the actual service
        self.services[service_name] = self.factories[service_name].create(**config)
        self.services[service_name].set_ready()
        logger.info(f"✅ Service {service_name} created successfully")

    def _validate_service_creation(self, service_name: ServiceType) -> None:
        """
        Validate that a factory exists for the given service.

        :param service_name: The name of the service to validate
        :raises ValueError: If no factory is registered for the service
        """
        if service_name not in self.factories:
            raise ValueError(
                f"No factory registered for the service class '{service_name.name}'"
            )


# Global service manager instance
service_manager = ServiceManager()

View on GitHub (pinned to 5e758547a8)