Fix: Support both memory provider and general plugin contexts

- Check for register_memory_provider() before calling it
- Fall back to direct tool registration in general plugin context
- Use proper closure to avoid late binding issues with tool names
This commit is contained in:
2026-04-10 13:07:56 +02:00
parent 7dc7e03280
commit 73f7b98fcf
+29 -2
View File
@@ -410,5 +410,32 @@ class Mem0LocalMemoryProvider(MemoryProvider):
def register(ctx) -> None:
"""Register Mem0 local as a memory provider plugin."""
ctx.register_memory_provider(Mem0LocalMemoryProvider())
"""Register Mem0 local as a memory provider plugin.
Works in both contexts:
- Memory provider context (plugins/memory/) — uses register_memory_provider()
- General plugin context (~/.hermes/plugins/) — registers tools directly
"""
provider = Mem0LocalMemoryProvider()
# Memory provider context (plugins/memory/ directory)
if hasattr(ctx, "register_memory_provider"):
ctx.register_memory_provider(provider)
return
# General plugin context (~/.hermes/plugins/ directory)
# Register tools manually since we can't register as memory provider
from tools.registry import registry
def make_handler(tool_name: str):
"""Create a handler closure for a specific tool."""
return lambda args: provider.handle_tool_call(tool_name, args)
for schema in [PROFILE_SCHEMA, SEARCH_SCHEMA, CONCLUDE_SCHEMA]:
registry.register(
name=schema["name"],
toolset="mem0_local",
schema=schema,
handler=make_handler(schema["name"]),
)
logger.debug("Registered tool: %s", schema["name"])