Backend Registry¶
deep_db_agents.backend_registry ¶
Singleton registry of BackendProtocol backends indexed by UUID.
Allows registering a backend instance (derived from deepagents' BackendProtocol),
obtaining an opaque identifier that can later be used to retrieve or remove it,
without letting the reference to the object circulate through the system.
The registry is shared at the process level: whoever registers a backend (add)
is responsible for removing it (remove) at the end of the agent's lifetime,
otherwise the instance stays referenced for the entire process lifetime.
BERegistry ¶
Singleton UUID -> BackendProtocol registry.
Every instantiation returns the same object, so the registry is shared at the process level. Creation and mutations are protected by a lock: tools may run in parallel threads (parallel tool calls in the tool node).
reg = BERegistry() key = reg.add(my_backend) reg.get(key) is my_backend True reg.remove(key) reg.get(key) is None True
__new__ ¶
__new__() -> BERegistry
Create or return the singleton instance.
Returns:
| Name | Type | Description |
|---|---|---|
BERegistry |
BERegistry
|
The single shared instance of the registry. |
Source code in src/deep_db_agents/backend_registry.py
39 40 41 42 43 44 45 46 47 48 49 50 51 52 | |
add ¶
add(backend: BackendProtocol) -> str
Register a backend and return its identifier.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
backend
|
BackendProtocol
|
The |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The UUID (as a string) associated with the registered backend. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If |
Source code in src/deep_db_agents/backend_registry.py
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | |
get ¶
get(key: str) -> BackendProtocol | None
Retrieve a registered backend.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
The UUID string previously returned by :meth: |
required |
Returns:
| Type | Description |
|---|---|
BackendProtocol | None
|
BackendProtocol | None: The registered backend, or |
BackendProtocol | None
|
|
Source code in src/deep_db_agents/backend_registry.py
73 74 75 76 77 78 79 80 81 82 83 84 | |
remove ¶
remove(key: str) -> None
Remove a registered backend.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
The UUID string previously returned by :meth: |
required |
Returns:
| Type | Description |
|---|---|
None
|
None. This is a no-op if |
Source code in src/deep_db_agents/backend_registry.py
86 87 88 89 90 91 92 93 94 95 96 | |