Skip to content

memory: move provider-specific cache-busting keys out of gateway/run.py into a MemoryProvider hook #33381

@kshitijk4poor

Description

@kshitijk4poor

Background

PR #30077 added a Honcho-specific block to GatewayRunner._extract_cache_busting_config() so edits to honcho.json identity-mapping keys (peerName, aiPeer, pinPeerName/pinUserPeer, userPeerAliases, runtimePeerPrefix) bust the cached AIAgent on the next gateway message. This was needed because HonchoSessionManager freezes the resolved identity at first-message init — without busting on these key changes, mid-flight honcho.json edits go unread until an unrelated cache eviction.

The implementation works correctly, but it hardcodes a backwards dependency from gateway/run.py to plugins.memory.honcho.client.HonchoClientConfig:

https://github.com/NousResearch/hermes-agent/blob/main/gateway/run.py#L14677-L14695

try:
    from plugins.memory.honcho.client import HonchoClientConfig
    hcfg = HonchoClientConfig.from_global_config()
    out["honcho.peer_name"] = hcfg.peer_name
    ...

Problem

  1. Layering violation. Gateway code shouldn't know about specific memory-provider plugins by name. If mem0, supermemory, hindsight, or any future memory provider adds analogous identity-mapping config (which they plausibly will, given the per-user-peer pattern this PR established), each one would require another try/except: from plugins.memory.X import ... block in core gateway code.

  2. Per-message disk I/O for everyone. HonchoClientConfig.from_global_config() does path.read_text() + json.loads() on every gateway message — including for users who don't run Honcho at all. The file is small so it's microseconds, but it's still unnecessary work on the hot path.

Proposed fix

Add a cache_busting_signature() -> dict | None hook to the MemoryProvider ABC (agent/memory_provider.py). Memory providers return a flat dict of provider_name.key -> value entries that should bust the cached agent when they change. The default implementation returns None (no busting).

Then in _extract_cache_busting_config, ask the active memory provider for its signature:

# Pseudocode — replace the honcho-specific block
active_memory = MemoryRegistry.get_active_provider(user_config)
if active_memory is not None:
    extra = active_memory.cache_busting_signature() or {}
    out.update(extra)

This also incidentally fixes the per-message disk read for non-Honcho users — only the active provider's hook runs.

Honcho's implementation moves to plugins/memory/honcho/__init__.py::HonchoMemoryProvider.cache_busting_signature() returning the same 5 keys it returns today.

Acceptance criteria

  • MemoryProvider.cache_busting_signature() exists with a sensible default
  • Honcho's identity-mapping cache-bust moves from gateway/run.py into the plugin
  • gateway/run.py no longer imports from plugins.memory.honcho.*
  • Existing TestAgentConfigSignatureUserId tests in tests/gateway/test_agent_cache.py still pass
  • Adding a new memory plugin doesn't require touching gateway code

Context

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3Low — cosmetic, nice to havecomp/gatewayGateway runner, session dispatch, deliverycomp/pluginsPlugin system and bundled pluginstool/memoryMemory tool and memory providerstype/refactorCode restructuring, no behavior change

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions