openclaw - 💡(How to fix) Fix Feature: Auto-LCM recall enforcement after context compaction [1 comments, 2 participants]

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…
GitHub stats
openclaw/openclaw#51459Fetched 2026-04-08 01:10:56
View on GitHub
Comments
1
Participants
2
Timeline
2
Reactions
0
Author
Participants
Timeline (top)
commented ×1subscribed ×1

Root Cause

Text-based rules in workspace files are suggestions, not constraints. The agent:

  1. Has rules loaded in initial context
  2. Doesn't actively check them mid-turn
  3. Works from summaries after compaction instead of querying LCM
  4. Has no enforcement mechanism to prevent this

Fix Action

Fix / Workaround

Workarounds (Current)

All workarounds are reactive, not preventive.

Code Example

// In LCM plugin or core
async function afterCompaction(userMessage: string, summaries: Summary[]) {
  // Detect if user is referencing prior work
  const priorWorkKeywords = [
    'you did', 'we talked about', 'before', 'earlier',
    'last time', 'remember when', 'you said', 'we built'
  ];
  
  const hasPriorRef = priorWorkKeywords.some(kw => 
    userMessage.toLowerCase().includes(kw)
  );
  
  if (hasPriorRef) {
    // Auto-run grep and inject results into agent context
    const results = await lcm_grep({
      pattern: extractKeyTerms(userMessage),
      mode: 'full_text',
      limit: 5
    });
    
    // Prepend to agent's next turn
    return {
      forcedContext: `[Auto-LCM Results]: ${results}`,
      reminder: 'Context was compacted. LCM results above show actual history.'
    };
  }
}

---

IMPORTANT: Context was just compacted. Before responding:
1. Check if user is referencing prior work
2. If yes, FIRST call lcm_grep(pattern="<key terms>")
3. Use results to inform your response
4. Do NOT guess from summaries alone

---

plugins:
  lossless-claw:
    enabled: true
    autoRecall:
      enabled: true  # New option
      triggerKeywords:
        - "you did"
        - "we talked about"
        - "before"
        # ... etc
      injectResults: true
      maxResults: 5

---

agents:
  main:
    enforceLcmRecall: true  # Auto-trigger after compaction
  experimental:
    enforceLcmRecall: false  # Let agent decide
RAW_BUFFERClick to expand / collapse

Feature Request: Auto-LCM Recall Enforcement After Compaction

Problem

Agents frequently fail to use LCM tools (lcm_grep, lcm_expand_query) after context compaction, even when explicit rules exist in AGENTS.md. This leads to:

  • Incorrect responses based on incomplete summaries
  • Repeated mistakes that were documented in prior conversation
  • Lost institutional knowledge despite LCM storing everything

Real example (2026-03-20): Agent destroyed working trading bot by not checking LCM for "how to close positions" code that had been used successfully multiple times before. Lost hours of work.

Root Cause

Text-based rules in workspace files are suggestions, not constraints. The agent:

  1. Has rules loaded in initial context
  2. Doesn't actively check them mid-turn
  3. Works from summaries after compaction instead of querying LCM
  4. Has no enforcement mechanism to prevent this

Proposed Solution

Option 1: Auto-LCM Hook (Preferred)

Add plugin hook that automatically triggers after compaction:

// In LCM plugin or core
async function afterCompaction(userMessage: string, summaries: Summary[]) {
  // Detect if user is referencing prior work
  const priorWorkKeywords = [
    'you did', 'we talked about', 'before', 'earlier',
    'last time', 'remember when', 'you said', 'we built'
  ];
  
  const hasPriorRef = priorWorkKeywords.some(kw => 
    userMessage.toLowerCase().includes(kw)
  );
  
  if (hasPriorRef) {
    // Auto-run grep and inject results into agent context
    const results = await lcm_grep({
      pattern: extractKeyTerms(userMessage),
      mode: 'full_text',
      limit: 5
    });
    
    // Prepend to agent's next turn
    return {
      forcedContext: `[Auto-LCM Results]: ${results}`,
      reminder: 'Context was compacted. LCM results above show actual history.'
    };
  }
}

Option 2: Hard Constraint

Block agent response if:

  • Context was compacted (summary tags present)
  • User message references prior work
  • Agent hasn't called lcm_grep or lcm_expand_query yet

Force agent to query LCM before proceeding.

Option 3: Prompt Rewriting

After compaction, automatically inject into system prompt:

IMPORTANT: Context was just compacted. Before responding:
1. Check if user is referencing prior work
2. If yes, FIRST call lcm_grep(pattern="<key terms>")
3. Use results to inform your response
4. Do NOT guess from summaries alone

Benefits

  • Prevents catastrophic mistakes from incomplete summaries
  • Leverages LCM investment (users installed it for a reason)
  • Reduces user frustration (no more "you forgot again")
  • Maintains agent reliability across long conversations

Configuration

plugins:
  lossless-claw:
    enabled: true
    autoRecall:
      enabled: true  # New option
      triggerKeywords:
        - "you did"
        - "we talked about"
        - "before"
        # ... etc
      injectResults: true
      maxResults: 5

Alternative: Agent-Level Setting

Some users may want this behavior, others may not. Could be per-agent config:

agents:
  main:
    enforceLcmRecall: true  # Auto-trigger after compaction
  experimental:
    enforceLcmRecall: false  # Let agent decide

Implementation Priority

High. This is a reliability issue that causes real damage:

  • Lost work (hours of coding reverted)
  • Lost money (trading bot mistakes)
  • Lost trust (agent repeatedly fails same way)

Text rules don't work. Need architectural enforcement.


Related Issues

  • Agents not following AGENTS.md rules mid-conversation
  • Context compaction causing knowledge regression
  • LCM tools available but underutilized

Workarounds (Current)

  1. User manually catches agent when it doesn't use LCM
  2. Add more text rules (doesn't work)
  3. Hope agent remembers (unreliable)

All workarounds are reactive, not preventive.

extent analysis

Fix Plan

To address the issue of agents not using LCM tools after context compaction, we will implement the Auto-LCM Hook solution. This involves adding a plugin hook that automatically triggers after compaction and detects if the user is referencing prior work.

Steps:

  1. Implement the afterCompaction function:

async function afterCompaction(userMessage: string, summaries: Summary[]) { const priorWorkKeywords = [ 'you did', 'we talked about', 'before', 'earlier', 'last time', 'remember when', 'you said', 'we built' ];

const hasPriorRef = priorWorkKeywords.some(kw => userMessage.toLowerCase().includes(kw) );

if (hasPriorRef) { const results = await lcm_grep({ pattern: extractKeyTerms(userMessage), mode: 'full_text', limit: 5 });

return {
  forcedContext: `[Auto-LCM Results]: ${results}`,
  reminder: 'Context was compacted. LCM results above show actual history.'
};

} }

2. **Configure the plugin**:
   ```yaml
plugins:
  lossless-claw:
    enabled: true
    autoRecall:
      enabled: true
      triggerKeywords:
        - "you did"
        - "we talked about"
        - "before"
      injectResults: true
      maxResults: 5
  1. Optionally, add agent-level configuration:

agents: main: enforceLcmRecall: true experimental: enforceLcmRecall: false


### Verification
To verify that the fix worked, test the following scenarios:
* Trigger the `afterCompaction` hook by referencing prior work in a user message after context compaction.
* Verify that the agent's response includes the forced context with LCM results.
* Test with different trigger keywords and ensure the hook is triggered correctly.

### Extra Tips
* Monitor the effectiveness of the Auto-LCM Hook and adjust the trigger keywords and configuration as needed.
* Consider adding more advanced logic to the `afterCompaction` function to handle edge cases and improve the accuracy of LCM results.

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