Files
Hy-Memory/plugins/hermes/tests/conftest.py
de4292ed4e feat(hermes): add managed native prefetch provider (#143)
* feat: add native Hermes memory provider

* feat(hermes): support scoped private CA trust

* feat(hermes): bound write timeout separately from reads

* fix(hermes): support truststore scoped CA snapshots

* feat(hermes): add managed prefetch provider

Co-authored-by: kindong <727777477@qq.com>
Co-authored-by: Cursor <cursoragent@cursor.com>

---------

Co-authored-by: kindong <727777477@qq.com>
Co-authored-by: alvinfei <alvinfei@tencent.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-10-22 16:51:15 +08:00

60 lines
1.8 KiB
Python

"""Minimal fallback contract only when Hermes is absent."""
import contextvars
import importlib.util
import os
from pathlib import Path
import sys
import threading
import types
from dataclasses import dataclass
snapshot = os.environ.get("HERMES_MEMORY_PROVIDER_SNAPSHOT")
if snapshot:
real_spec = importlib.util.spec_from_file_location(
"agent.memory_provider", snapshot
)
module = importlib.util.module_from_spec(real_spec)
sys.modules[real_spec.name] = module
real_spec.loader.exec_module(module)
else:
try:
from agent.memory_provider import MemoryProvider # noqa: F401
except ModuleNotFoundError as exc:
if exc.name not in {
"agent",
"agent.memory_provider",
}:
raise
module = types.ModuleType("agent.memory_provider")
class MemoryProvider:
pass
@dataclass
class RecallStatus:
provider_label: str
count: int
def ctx_bound(fn):
ctx = contextvars.copy_context()
return lambda *args, **kwargs: ctx.run(fn, *args, **kwargs)
def spawn_context_thread(target, *, name, daemon=True):
return threading.Thread(target=ctx_bound(target), name=name, daemon=daemon)
module.MemoryProvider = MemoryProvider
module.RecallStatus = RecallStatus
module.ctx_bound = ctx_bound
module.spawn_context_thread = spawn_context_thread
sys.modules["agent.memory_provider"] = module
spec = importlib.util.spec_from_file_location(
"hermes_hy_memory",
Path(__file__).parents[1] / "hy_memory/__init__.py",
submodule_search_locations=[str(Path(__file__).parents[1] / "hy_memory")],
)
plugin = importlib.util.module_from_spec(spec)
sys.modules[spec.name] = plugin
spec.loader.exec_module(plugin)