haive.core.engine.base.registry¶
Registry management for Haive engines.
This module provides a centralized registry for all engine instances in the Haive system. The registry allows engines to be registered, retrieved, and managed through a singleton pattern, ensuring consistent access across the application.
Classes¶
Central registry for all engines in the Haive system. |
Module Contents¶
- class haive.core.engine.base.registry.EngineRegistry[source]¶
Bases:
haive.core.registry.base.AbstractRegistry
[haive.core.engine.base.base.Engine
]Central registry for all engines in the Haive system.
This class implements a singleton pattern to ensure a single point of access for all engine registrations and lookups. Engines are organized by their type and can be accessed by name or by their unique ID.
- engines¶
Nested dictionary storing engines by their type and name.
- Type:
Dict[EngineType, Dict[str, Engine]]
Initialize the registry with empty dictionaries.
Creates an empty registry structure with dictionaries for each engine type and an empty ID mapping dictionary.
- clear()[source]¶
Clear the registry.
Removes all engines from the registry, resetting it to an empty state. Useful for testing or when reloading configurations.
Examples
>>> registry = EngineRegistry.get_instance() >>> # After operations that registered engines >>> registry.clear() >>> assert len(registry.list(EngineType.LLM)) == 0
- Return type:
None
- find(name_or_id)[source]¶
Find an engine by name or ID across all engine types.
Searches for an engine by first checking the ID registry (faster) and then searching through all engine types by name.
- Parameters:
name_or_id (str) – The name or ID of the engine to find.
- Returns:
The requested engine instance, or None if not found.
- Return type:
Optional[Engine]
Examples
>>> registry = EngineRegistry.get_instance() >>> # Can find by ID >>> engine1 = registry.find("550e8400-e29b-41d4-a716-446655440000") >>> # Or by name >>> engine2 = registry.find("gpt-4")
- find_by_id(id)[source]¶
Find an engine by its unique ID.
Retrieves an engine instance from the registry using its unique ID.
- Parameters:
id (str) – The unique ID of the engine to find.
- Returns:
The requested engine instance, or None if not found.
- Return type:
Optional[Engine]
Examples
>>> registry = EngineRegistry.get_instance() >>> engine = registry.find_by_id("550e8400-e29b-41d4-a716-446655440000") >>> if engine: ... print(f"Found engine: {engine.name}")
- get(item_type, name)[source]¶
Get an engine by its type and name.
Retrieves an engine instance from the registry using its type and name.
- Parameters:
item_type (EngineType) – The type of engine to retrieve.
name (str) – The name of the engine to retrieve.
- Returns:
The requested engine instance, or None if not found.
- Return type:
Optional[Engine]
Examples
>>> registry = EngineRegistry.get_instance() >>> engine = registry.get(EngineType.LLM, "gpt-4") >>> if engine: ... print(f"Found engine: {engine.name}") ... else: ... print("Engine not found")
- get_all(item_type)[source]¶
Get all engines of a specific type.
Returns a dictionary mapping names to engines for the given type.
- Parameters:
item_type (EngineType) – The type of engines to retrieve.
- Returns:
A dictionary of engine names to engine instances.
- Return type:
Examples
>>> registry = EngineRegistry.get_instance() >>> all_llms = registry.get_all(EngineType.LLM) >>> for name, engine in all_llms.items(): ... print(f"LLM: {name}, ID: {engine.id}")
- classmethod get_instance()[source]¶
Get the singleton instance of the engine registry.
This method ensures that only one instance of the registry exists throughout the application lifecycle.
- Returns:
The singleton instance of the registry.
- Return type:
Examples
>>> registry = EngineRegistry.get_instance() >>> # All subsequent calls return the same instance >>> registry2 = EngineRegistry.get_instance() >>> registry is registry2 True
- list(item_type)[source]¶
List all engines of a specific type.
Returns a list of names of all engines registered for the given type.
- Parameters:
item_type (EngineType) – The type of engines to list.
- Returns:
A list of engine names of the specified type.
- Return type:
List[str]
Examples
>>> registry = EngineRegistry.get_instance() >>> llm_engines = registry.list(EngineType.LLM) >>> print(f"Available LLM engines: {', '.join(llm_engines)}")
- register(item)[source]¶
Register an engine in the registry.
Adds the provided engine to the registry, indexed by both its type/name and its unique ID.
- Parameters:
item (Engine) – The engine instance to register.
- Returns:
The registered engine instance (same as input).
- Return type:
Examples
>>> from haive.core.engine.base.base import Engine >>> registry = EngineRegistry.get_instance() >>> engine = Engine(name="my_engine", engine_type=EngineType.LLM) >>> registry.register(engine) >>> registry.find("my_engine") is engine True