Skip to content

[Bug]: Gateway memory flush creates agent with skip_memory=True, making memory tool non-functional #6157

@zipzagster

Description

@zipzagster

Bug Description

The gateway pre-reset memory flush creates a temporary AIAgent with skip_memory=True, which prevents _memory_store from being initialized. The memory tool is included in the enabled toolsets, so the model can call it — but every call fails silently with "Memory is not available."

Steps to Reproduce

When the 122B model correctly generates a memory tool call, it reaches:

memory_tool.py:452

if store is None:
    return {"success": False, "error": "Memory is not available."}

The tool returns an error, the model sees it failed, and the flush produces no writes.

Expected Behavior

The memory tool works

Actual Behavior

The gateway flush fires on every session reset (idle timeout + daily 4am reset) and is the primary mechanism for persisting memories from Telegram/messaging sessions. With this bug, it is completely non-functional — no memories are ever saved through this path.

Affected Component

Agent Core (conversation loop, context compression, memory)

Messaging Platform (if gateway-related)

No response

Operating System

macos 26.3.1

Python Version

3.14.3

Hermes Version

0.7.0

Relevant Logs / Traceback

Root Cause Analysis (optional)

gateway/run.py:666-672

tmp_agent = AIAgent(
    **runtime_kwargs,
    model=model,
    max_iterations=8,
    quiet_mode=True,
    skip_memory=True,   # <-- prevents _memory_store initialization
    enabled_toolsets=["memory", "skills"],  # <-- memory tool is available
    session_id=old_session_id,
)

run_agent.py:1024-1046

self._memory_store = None       # default
# ...
if not skip_memory:             # skipped when True
    # ...
    self._memory_store = MemoryStore(...)
    self._memory_store.load_from_disk()

When the 122B model correctly generates a memory tool call, it reaches:

memory_tool.py:452

if store is None:
    return {"success": False, "error": "Memory is not available."}

The tool returns an error, the model sees it failed, and the flush produces no writes.

Proposed Fix (optional)

Initialize a MemoryStore on the flush agent without injecting memory into the system prompt. The simplest approach:

tmp_agent = AIAgent(
    **runtime_kwargs,
    model=model,
    max_iterations=8,
    quiet_mode=True,
    skip_memory=False,  # allow _memory_store to initialize
    enabled_toolsets=["memory", "skills"],
    session_id=old_session_id,
)

If the concern was avoiding memory injection into the system prompt (to save tokens), a more targeted fix would be to add a flag like skip_memory_prompt=True that skips format_for_system_prompt() while still initializing the store. However, the flush prompt at line 706 already includes the current memory state read directly from disk, so the system prompt injection is redundant here anyway.

Are you willing to submit a PR for this?

  • I'd like to fix this myself and submit a PR

Metadata

Metadata

Assignees

No one assigned

    Labels

    type/bugSomething isn't working

    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