hermes - 💡(How to fix) Fix Gateway sessions reset memory nudge counter, so self-improvement review may never trigger

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…

Root Cause

Because the gateway creates a new agent object per message, _turns_since_memory starts at 0 every turn and memory.nudge_interval may never be reached. In practice this means the background Self-improvement review stops appearing and durable user corrections/workflow lessons are not proactively saved.

Fix Action

Fix / Workaround

Local Patch Tested

Code Example

memory:
  memory_enabled: true
  user_profile_enabled: true
  nudge_interval: 10

---

memory:
  memory_enabled: true
  user_profile_enabled: true
  memory_char_limit: 2200
  user_char_limit: 1375
  nudge_interval: 10
  flush_min_turns: 6
skills:
  creation_nudge_interval: 15

---

prior_user_turns = sum(1 for msg in conversation_history if msg.get("role") == "user")
self._turns_since_memory = prior_user_turns % self._memory_nudge_interval

---

tests/run_agent/test_memory_review_counter.py

---

3 passed
python -m py_compile run_agent.py  # ok
RAW_BUFFERClick to expand / collapse

Bug Description

In gateway/messaging-platform usage (observed on Telegram), Hermes appears to create a fresh AIAgent per inbound message while continuing the persisted session history. The periodic self-improvement memory review is gated by the instance variable _turns_since_memory, which is initialized to 0 in AIAgent.__init__.

Because the gateway creates a new agent object per message, _turns_since_memory starts at 0 every turn and memory.nudge_interval may never be reached. In practice this means the background Self-improvement review stops appearing and durable user corrections/workflow lessons are not proactively saved.

This is related to #18369, but the scenario is not only users manually starting /new; it can happen in normal long-running gateway conversations where the conversation history persists but the agent instance does not.

Steps to Reproduce

  1. Configure memory review with the default-ish settings:
memory:
  memory_enabled: true
  user_profile_enabled: true
  nudge_interval: 10
  1. Run Hermes through the gateway (Telegram observed).
  2. Continue a normal conversation for many turns without /new.
  3. Watch for 💾 Self-improvement review: messages or memory/skill background review tool actions.

Expected Behavior

The memory review counter should survive gateway turn boundaries, or be reconstructed from persisted session history, so that memory.nudge_interval still triggers in messaging-platform sessions.

Actual Behavior

The fresh per-message AIAgent resets _turns_since_memory to 0, so the turn-based trigger can be starved indefinitely in gateway mode.

Observed user-facing result:

  • no Self-improvement review messages for a long time despite many turns and obvious durable lessons,
  • important workflow correction was not saved until manually investigated,
  • compact user memory became nearly full, and no automatic memory compaction/Obsidian-style detail fallback occurred.

Environment

  • Hermes Agent: v0.13.0 (2026.5.7)
  • Source checkout: NousResearch/hermes-agent, branch main
  • Platform: Telegram gateway
  • Config snippet:
memory:
  memory_enabled: true
  user_profile_enabled: true
  memory_char_limit: 2200
  user_char_limit: 1375
  nudge_interval: 10
  flush_min_turns: 6
skills:
  creation_nudge_interval: 15

Local Patch Tested

A minimal local fix was tested: hydrate _turns_since_memory from persisted conversation_history when a fresh agent starts with counter 0.

Conceptually:

prior_user_turns = sum(1 for msg in conversation_history if msg.get("role") == "user")
self._turns_since_memory = prior_user_turns % self._memory_nudge_interval

Then the normal per-turn increment can trigger the review when the effective turn count reaches the interval.

Regression test added locally:

tests/run_agent/test_memory_review_counter.py

Result:

3 passed
python -m py_compile run_agent.py  # ok

Notes / Questions

  • This same lifecycle issue may also affect _iters_since_skill and skills.creation_nudge_interval in gateway mode.
  • A more robust upstream solution might persist nudge state in the session DB, derive it from history, or trigger background review on session split/reset.
  • The user expectation is that self-improvement works automatically in messenger mode; users should not have to manually notice that memory is full or that reviews stopped triggering.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING