#OC for RAG: use memory first

1 messages · Page 1 of 1 (latest)

wise hornet
#

Using openclaw 2026.4.23. I’d like to make an agent for RAG, but I keep having the problem that the LLM tends to use its own “knowledge” before referencing indexed docs. I’ve tried giving AGENT.md instructions stating always memory_search before answering, but the directive seems to be ignored. Can you assist, @muted tree ?

wicked ermineBOT
#

To help others find answers, you can mark your question as solved via Right click solution message -> Apps -> âś… Mark Solution

muted treeBOT
#

Yep — the important bit is: AGENTS.md instructions are guidance, not a hard preflight hook. If the model “decides” it knows the answer, it may skip memory_search unless something else forces retrieval earlier.

A few concrete fixes:

  1. Make sure it’s AGENTS.md plural, not AGENT.md. OpenClaw injects AGENTS.md every session; arbitrary filenames won’t be loaded automatically.

  2. For “search before answer” behavior, use Active Memory. It runs a small blocking memory pass before the main reply and injects relevant memory into the answer context, so the main LLM doesn’t have to remember to call memory_search itself.

Minimal-ish config:

{
  plugins: {
    entries: {
      "active-memory": {
        enabled: true,
#
        config: {
          enabled: true,
          agents: ["main"],
          allowedChatTypes: ["direct", "channel"], // include "group" too if needed
          queryMode: "recent",
          promptStyle: "balanced",
          timeoutMs: 15000,
          maxSummaryChars: 500,
          logging: true
        }
      }
    }
  }
}
#

If this is only for one Discord thread/channel, narrow it with allowedChatIds rather than enabling every channel.

  1. Verify memory is actually indexed:
openclaw memory status --deep --agent main
openclaw memory index --force --agent main
  1. If your RAG docs live outside MEMORY.md / memory/*.md, add them via agents.defaults.memorySearch.extraPaths:
{
  agents: {
    defaults: {
      memorySearch: {
#
        provider: "openai", // or gemini / voyage / mistral / local / ollama, etc.
        extraPaths: ["/path/to/your/docs"]
      }
    }
  }
}
  1. In AGENTS.md, phrase the rule as an answer contract, not just a tool preference:
## RAG answer contract
Before answering factual/domain questions, rely on indexed docs first.
If no relevant memory/search result is available, say: “I don’t have that in the indexed docs.”
Do not answer from general model knowledge unless the user explicitly asks for a general answer.
#
When possible, cite the retrieved file/path or say what source was used.

For debugging, turn on:

/verbose on
/trace on
/active-memory status

Docs: https://docs.openclaw.ai/concepts/active-memory, https://docs.openclaw.ai/concepts/memory-search, https://docs.openclaw.ai/reference/memory-config, https://docs.openclaw.ai/concepts/agent-workspace

So my recommendation: don’t fight the model with only AGENTS.md; enable Active Memory + tighten the answer contract. That’s the OpenClaw-native way to make RAG happen before the main response. 🦞

wise hornet
muted treeBOT
#

Short version: I’d call Active Memory in 2026.4.23 usable, but not something I’d treat as a hard RAG correctness guarantee.

The distinction matters:

  • For “make the agent more likely to bring indexed context in before answering” → Active Memory is the right feature to try.
  • For “the agent must never answer unless docs were searched and cited” → Active Memory alone is still soft. You’ll want the answer contract + /trace verification, or a stricter custom workflow/tooling layer.

The likely instability people mention is around the blocking pre-reply recall path: latency, timeouts, empty/noisy recall, embedding provider weirdness, or it not running because the session isn’t eligible. The current docs even call out cold-start behavior: before v2026.5.2, which includes your 2026.4.23, Active Memory silently added an extra 30s cold-start grace to the configured timeout. Later versions made that explicit with setupGraceTimeoutMs.

So for 2026.4.23, I’d test it safely like this:

{
  plugins: {
    entries: {
      "active-memory": {
#
        enabled: true,
        config: {
          enabled: true,
          agents: ["main"],
          allowedChatTypes: ["direct"],
          queryMode: "recent",
          timeoutMs: 15000,
          maxSummaryChars: 220,
          logging: true
        }
      }
    }
  }
}
#

Then in the test chat:

/verbose on
/trace on
/active-memory status

If you see Active Memory: status=ok plus a useful debug summary, great. If you see timeouts/empty summaries, first check openclaw memory status --deep --agent main — most “Active Memory is flaky” cases are actually memory index/provider issues.

If this is important RAG infra, I’d also consider upgrading past 2026.4.23 once convenient, because the newer docs/config around cold-start behavior are clearer. But for an evening experiment: yes, try it — just roll it out narrowly and verify with trace before trusting it. 🦞

Docs: https://docs.openclaw.ai/concepts/active-memory

wise hornet
muted treeBOT
#

Yes — that’s actually the rollout I’d recommend.

Active Memory is scoped by agent id with:

plugins: {
  entries: {
    "active-memory": {
      enabled: true,
      config: {
        enabled: true,
        agents: ["librarian"], // only this agent gets Active Memory
        allowedChatTypes: ["direct", "channel"],
        queryMode: "recent",
        timeoutMs: 15000,
        maxSummaryChars: 220,
#
        logging: true
      }
    }
  }
}

Then define a separate librarian agent in your agents.list and give it the RAG-specific workspace/instructions/model/tools you want. Other agents won’t run Active Memory unless their ids are included in config.agents.

The pattern I’d use:

  • main agent: normal assistant behavior, no Active Memory
  • librarian agent: RAG-first contract, indexed docs, citations, Active Memory enabled
  • route only your RAG channel/thread/DM to librarian, or explicitly switch to it when asking doc-grounded questions

One caveat: Active Memory uses that agent’s configured memory/search setup, so make sure the librarian’s workspace/docs are indexed for that agent:

#
openclaw memory status --deep --agent librarian
openclaw memory index --force --agent librarian

That “librarian” split is cleaner than trying to make your everyday agent behave like a strict retrieval system all the time. 🦞

wise hornet
#

Nice. While I’m learning so much from you, is it possible to get my main agent to invoke this librarian agent for me? So I might ask my main agent something like “ask librarian about such and such” and then when librarian was done, my main agent would give me the full answer?

muted treeBOT
#

Yes — that’s exactly what sub-agents are for.

You can make main a coordinator and let it spawn librarian as a child run. The flow is:

  1. You ask: “ask librarian about X”
  2. main calls sessions_spawn with agentId: "librarian"
  3. librarian does the RAG/Active Memory/search work in its own isolated session
  4. when it finishes, OpenClaw hands the result back to main
  5. main synthesizes and replies to you

Config-wise, two things matter:

{
  tools: {
    // or use a profile that already includes sessions tools
#
    alsoAllow: ["sessions_spawn", "sessions_yield", "subagents"]
  },
  agents: {
    list: [
      {
        id: "main",
        subagents: {
          allowAgents: ["librarian"],
          delegationMode: "prefer"
        }
      },
      {
        id: "librarian"
        // workspace/model/memorySearch/Active Memory config here
      }
#
    ]
  }
}

Then put a standing rule in main’s AGENTS.md, something like:

## Librarian delegation
When the user asks to “ask librarian”, “check the docs”, or asks a domain question that should be answered from indexed docs, spawn the `librarian` agent with `sessions_spawn`.
Give librarian a precise question and ask it to cite retrieved sources/paths.
After spawning, wait for the completion event and synthesize the final answer for the user.
Do not answer from general knowledge if the user asked for librarian/doc-grounded retrieval.

And in librarian’s AGENTS.md:

#
You are the librarian/RAG agent. Search indexed docs before answering. If the indexed docs do not support an answer, say so. Include source paths/snippets when available.

Useful checks:

openclaw agents list --bindings
openclaw memory status --deep --agent librarian

And from the chat, /tools should show that main has sessions_spawn. If not, the main agent can want to delegate all day and still not have the tool to do it. Tiny claw trap. 🦞

Docs: https://docs.openclaw.ai/tools/subagents, https://docs.openclaw.ai/concepts/multi-agent

wise hornet
#

You’re awesome. Thank you. I wish I could email this thread to myself.

muted treeBOT
#

Aw, thank you — glad this helped. 🦞

I can’t email it for you from here, but easiest options:

  • use Discord’s thread menu / browser print → Save as PDF
  • copy the thread URL into your notes
  • or ask me: “summarize this thread into an email I can send myself” and I’ll turn it into a clean copy-paste version.