Skip to content

fix: respect memory_enabled flag for MEMORY_GUIDANCE injection - #36085

Closed
kjames2001 wants to merge 1 commit into
NousResearch:mainfrom
kjames2001:fix/memory-guidance-respects-memory-enabled
Closed

fix: respect memory_enabled flag for MEMORY_GUIDANCE injection#36085
kjames2001 wants to merge 1 commit into
NousResearch:mainfrom
kjames2001:fix/memory-guidance-respects-memory-enabled

Conversation

@kjames2001

Copy link
Copy Markdown
Contributor

Problem

The stable tier injected MEMORY_GUIDANCE whenever the memory tool was registered in valid_tool_names, ignoring the memory_enabled config flag. This caused contradictory instructions when users set memory_enabled: false — the system prompt told the agent to "Save durable facts using the memory tool" even though memory was explicitly disabled.

This is inconsistent with the volatile tier, which already checks agent._memory_enabled before injecting memory content (MEMORY.md, USER.md blocks).

Use Case

Users running third-party memory providers (MemPalace, Mem0, etc.) via the plugin system set memory_enabled: false to disable the built-in memory. The built-in MEMORY_GUIDANCE instructions contradict the plugin's own instructions, confusing the agent.

Fix

Added and getattr(agent, "_memory_enabled", True) check to the MEMORY_GUIDANCE injection in build_system_prompt_parts(), matching the existing pattern in the volatile tier.

getattr with default True preserves backward compatibility for code paths that don't initialize _memory_enabled.

Tests

  • Updated test_memory_guidance_when_memory_tool_loaded to explicitly set _memory_enabled = True
  • Added test_no_memory_guidance_when_memory_disabled to verify the fix
  • All 3 memory_guidance tests pass

The stable tier injected MEMORY_GUIDANCE whenever the memory tool was
registered, ignoring the memory_enabled config flag. This caused
contradictory instructions when users set memory_enabled=false (e.g.
with third-party memory providers like MemPalace) — the system prompt
told the agent to 'Save durable facts using the memory tool' even though
memory was explicitly disabled.

Now checks agent._memory_enabled before injecting MEMORY_GUIDANCE,
consistent with how the volatile tier already gates memory content.

Closes #XXXX
@alt-glitch alt-glitch added type/bug Something isn't working comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint tool/memory Memory tool and memory providers P2 Medium — degraded but workaround exists labels May 31, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Related to #30814 which also gates MEMORY_GUIDANCE injection (plus additional dead-write guards). This PR is a narrower subset of that fix.

@mxnstrexgl mxnstrexgl left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM — automated review passed. No security, quality, or test coverage issues detected.

@tonydwb tonydwb left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review Summary

Verdict: Approved

Review

fix: respect memory_enabled flag for MEMORY_GUIDANCE injection

Clean, well-reasoned fix. Key observations:

  • Problem: The stable tier injected MEMORY_GUIDANCE based solely on valid_tool_names membership, ignoring the memory_enabled config flag. This created contradictory instructions when users had third-party memory providers with memory_enabled: false.
  • Fix: One-line change adding getattr(agent, "_memory_enabled", True) to the MEMORY_GUIDANCE injection condition. The getattr with default True preserves backward compatibility for code paths that don't initialize _memory_enabled.
  • Consistency: Matches how the volatile tier already checks agent._memory_enabled before injecting memory content.
  • Tests: Updated existing test to explicitly set _memory_enabled = True, added new test for the False case.

Looks Good

  • Minimal change with clear motivation
  • Backward compatible
  • Well-documented in PR description

Reviewed by Hermes Agent

@teknium1

Copy link
Copy Markdown
Contributor

Thanks for the focused fix. The premise still holds on current main: agent/system_prompt.py:221-222 injects MEMORY_GUIDANCE based only on valid_tool_names, while agent/agent_init.py:1358-1366 sets _memory_enabled from memory.memory_enabled. The volatile tier already uses that state to gate built-in memory content at agent/system_prompt.py:460-469.

The proposed condition is narrowly scoped, preserves the missing-attribute compatibility behavior requested in the PR, and the added false-case test directly covers the regression. The related broader work in #30814 does not make this narrower prompt-guidance correction redundant.

Automated hermes-sweeper review.

@teknium1 teknium1 added sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades sweeper:blast-massive Sweeper blast radius: massive — everyone, every turn (invariant surface) labels Jul 13, 2026
@teknium1

Copy link
Copy Markdown
Contributor

Fixed on main via #90559 (salvage of #90413). You were the earliest submitter in this cluster (May 31) to gate MEMORY_GUIDANCE on the config flags — thank you, and credited here. The landed fix also gates the tool itself via check_memory_requirements() and splits the guidance per store (profile-only configs get a narrower block). Closing since main now covers this.

@teknium1 teknium1 closed this Aug 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint P2 Medium — degraded but workaround exists sweeper:blast-massive Sweeper blast radius: massive — everyone, every turn (invariant surface) sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades tool/memory Memory tool and memory providers type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants