HubΒΆ
Central registry for agents, prompts, tools, guardrails, LLMs, and services.
Thread-safe component registration and discovery with category validation.
v2.0 Improvements
Hub now validates categories against a frozenset, uses threading.Lock for thread safety, and provides list_items() / remove() helpers.
OverviewΒΆ
The Hub acts as a service locator β a single place to register, discover, and retrieve framework components at runtime.
Supported categories (validated via frozenset):
| Category | Description |
|---|---|
agents | Agent instances |
prompts | Prompt templates |
tools | Tool definitions |
guardrails | Guardrail validators |
llms | LLM provider instances |
services | Arbitrary service objects |
Quick StartΒΆ
Service RegistrationΒΆ
The Hub provides convenience methods for services that don't fit a specific component category:
| Python | |
|---|---|
These are equivalent to hub.register("services", name, service) and hub.get("services", name).
Category ValidationΒΆ
Attempting to register or retrieve from an invalid category raises a ValueError:
| Python | |
|---|---|
Thread SafetyΒΆ
All Hub operations are protected by threading.Lock, making it safe to register and retrieve components from multiple threads:
API ReferenceΒΆ
HubΒΆ
MethodsΒΆ
| Method | Returns | Description |
|---|---|---|
register(category, name, item) | None | Register an item under a category |
get(category, name) | Any | Retrieve an item by category and name |
list_items(category) | dict | List all items in a category |
remove(category, name) | None | Remove an item from a category |
register_service(name, service) | None | Shortcut for register("services", ...) |
get_service(name) | Any | Shortcut for get("services", ...) |
InternalΒΆ
| Attribute | Type | Description |
|---|---|---|
_CATEGORIES | frozenset | Valid category names |
_registry | dict[str, dict] | Internal storage |
_lock | threading.Lock | Thread synchronisation |
Best PracticesΒΆ
Do
- Register components early during application startup.
- Use the Hub for dependency injection in multi-agent systems.
- Use
list_items()for admin / debugging views. - Clean up with
remove()when agents are disposed.
Don't
- Use the Hub as a general-purpose key-value store β it's for framework components.
- Bypass the Hub by passing components directly between agents (breaks discoverability).
Related DocumentationΒΆ
- Agents β agent lifecycle and registration
- Tools β tool definitions
- Guardrails β input/output validation
- Configuration β framework configuration