Skip to content

feat: add autoRecallExcludeAgents to suppress memory injection for background agents#307

Open
clawdbot520 wants to merge 1 commit intoCortexReach:masterfrom
clawdbot520:fix/autorecall-exclude-background-agents
Open

feat: add autoRecallExcludeAgents to suppress memory injection for background agents#307
clawdbot520 wants to merge 1 commit intoCortexReach:masterfrom
clawdbot520:fix/autorecall-exclude-background-agents

Conversation

@clawdbot520
Copy link

Problem

Background agents (e.g. a memory-distiller, cron workers) that receive structured task prompts have their output degraded when <relevant-memories> is injected by the before_agent_start hook.

Concrete failure mode: a memory-distiller agent whose job is to read raw session JSONL and extract new memories receives injected old-memory summaries alongside the fresh session content. The LLM then echoes or recomposes existing memories instead of distilling genuinely new insights. The distilled output is meaningless — it is a paraphrase of what was already known, not a synthesis of what happened in the session.

Why existing skip patterns don't cover this:
The shouldSkipRetrieval() function in adaptive-retrieval.ts handles prompt-level heuristics (HEARTBEAT, cron prefix [cron:…] run …, short greetings, etc.). However custom background-agent prompts that don't match these patterns — for example, a distiller cron whose prompt is Read HEARTBEAT.md if it exists. Follow it strictly… or any other structured instruction — fall through and get injected.

This is the root of the class of issues described in #137.

Solution

Add autoRecallExcludeAgents?: string[] to PluginConfig.

When an agent's ID appears in this list, before_agent_start returns immediately before any embedding call or injection occurs. A single info-level log line is emitted so the skip is observable in gateway logs.

{
  "autoRecall": true,
  "autoRecallExcludeAgents": ["memory-distiller", "my-cron-agent"]
}

What this is NOT

This is not a scope restriction (unlike agentAccess: { "memory-distiller": [] } which works but is undocumented and operates at the store-read level). autoRecallExcludeAgents is a clean, intentional, documented config opt-out at the injection layer.

Changes

File Change
index.ts Add autoRecallExcludeAgents?: string[] to PluginConfig interface; early-return guard in before_agent_start; parse in parsePluginConfig
README.md Add Option B to "injected memories show up in replies" troubleshooting section explaining the use case

Test plan

  • Set autoRecallExcludeAgents: ["test-agent"] and verify gateway logs show auto-recall skipped for excluded agent 'test-agent' on cron trigger
  • Verify other agents (not in the list) still receive injection normally
  • tsc --noEmit passes (confirmed locally)
  • Empty string entries in the array are filtered out by parsePluginConfig

Related

🤖 Generated with Claude Code

…ckground agents

Background agents (e.g. memory-distiller, cron workers) that receive
structured task prompts can have their output quality degraded when
<relevant-memories> is injected alongside the raw input — the LLM may
echo or recompose old memories instead of distilling fresh content.

The existing prompt-level skip patterns (HEARTBEAT, cron prefix) do not
cover every background-agent prompt format, leaving a gap for custom
pipeline agents.

This PR adds `autoRecallExcludeAgents?: string[]` to PluginConfig:
- Listed agent IDs bypass `before_agent_start` injection entirely
- A log line is emitted at info level so the skip is observable
- Zero impact on agents not in the list

Config example:
  "autoRecallExcludeAgents": ["memory-distiller", "my-cron-agent"]

README updated with Option B in the "injected memories show up" section,
explaining the use case and tradeoff.

Fixes the class of issues described in CortexReach#137 (background/cron agent
context bloat) with a targeted per-agent opt-out rather than a global
autoRecall disable.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
AliceLJY added a commit to AliceLJY/memory-lancedb-pro that referenced this pull request Mar 23, 2026
…ntrol

Adds a new `recallMode` configuration option that provides finer control
over auto-recall behavior than the existing boolean `autoRecall` flag:

- "full": existing behavior — inject matching memories into context
- "summary": lightweight hint only — tells agent how many memories matched
  without consuming context budget; agent can call memory_recall on demand
- "off": disable auto-recall entirely

When `recallMode` is set, it takes precedence over `autoRecall`.
When neither is set, auto-recall remains off by default (no breaking change).

Motivation: in complex development sessions, auto-recall competes with
compact/compression for limited context budget, reducing signal-to-noise
ratio. Summary mode gives agents awareness of available memories without
the context cost. See Anthropic's "Effective Context Engineering" and
OpenAI's "Harness Engineering" for the underlying design principles.

Related: CortexReach#307 (autoRecallExcludeAgents), CortexReach#254 (auto-recall circuit breaker)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@AliceLJY
Copy link
Collaborator

autoRecallExcludeAgents 这个功能有实际需求,背景 agent 不该被注入记忆。

不过这个 PR 的实现是基于 beta.9 的,有几个问题:

  1. hook 路径过时:beta.10 的 auto-recall 已经从 before_agent_start 迁移到 before_prompt_build(index.ts:2149-2167),当前实现接不上。
  2. 缺 schema 支持openclaw.plugin.json 里没有加这个配置项,用户在 UI 里看不到也配不了。
  3. 缺测试:需要一个 hook 级回归测试,证明被排除的 agent 确实不会 retrieve 和 inject 记忆。

建议基于最新 master 重写,对齐 before_prompt_build 路径 + 补 schema + 补测试。工作量不大,主要是对齐新的 hook 入口。期待更新 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants