Implementation:24kchengYe MemoMind ExtensionContext
| Knowledge Sources | |
|---|---|
| Domains | Software_Architecture, Extensibility |
| Last Updated | 2026-10-28 00:00 GMT |
Overview
Abstract context providing controlled API access to extensions — security boundary between extension code and system internals.
Description
The ExtensionContext ABC (with `DefaultExtensionContext` implementation) provides extensions with safe access to system internals: database migration runner, memory engine reference, and connection pool getter. Extensions use this context instead of direct access to internal components, providing a stable API and security boundary. Tenant extensions use `run_migration()` to provision per-tenant schemas.
Usage
Access via `self.context` in any Extension subclass. The context is set automatically by the extension loader after instantiation.
Code Reference
Source Location
- Repository: MemoMind
- File: engine/hindsight_api/extensions/context.py
- Lines: L1-157
Signature
class ExtensionContext(ABC):
@abstractmethod
async def run_migration(self, schema: str) -> None: ...
@abstractmethod
def get_memory_engine(self) -> MemoryEngineInterface: ...
Import
from hindsight_api.extensions.context import ExtensionContext
I/O Contract
Outputs
| Name | Type | Description |
|---|---|---|
| run_migration() | None | Creates schema and runs pending migrations |
| get_memory_engine() | MemoryEngineInterface | Memory engine for DB operations |
Usage Examples
Using Context in a Tenant Extension
from hindsight_api.extensions.base import Extension
class MyTenantExtension(Extension):
async def provision_tenant(self, tenant_id: str) -> str:
schema = f"tenant_{tenant_id}"
await self.context.run_migration(schema)
return schema