feat: add autoRecallExcludeAgents to suppress memory injection for background agents#307
Open
clawdbot520 wants to merge 1 commit intoCortexReach:masterfrom
Open
Conversation
…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>
4 tasks
Collaborator
|
autoRecallExcludeAgents 这个功能有实际需求,背景 agent 不该被注入记忆。 不过这个 PR 的实现是基于 beta.9 的,有几个问题:
建议基于最新 master 重写,对齐 before_prompt_build 路径 + 补 schema + 补测试。工作量不大,主要是对齐新的 hook 入口。期待更新 🙏 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 thebefore_agent_starthook.Concrete failure mode: a
memory-distilleragent 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 inadaptive-retrieval.tshandles 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 isRead 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[]toPluginConfig.When an agent's ID appears in this list,
before_agent_startreturns immediately before any embedding call or injection occurs. A singleinfo-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).autoRecallExcludeAgentsis a clean, intentional, documented config opt-out at the injection layer.Changes
index.tsautoRecallExcludeAgents?: string[]toPluginConfiginterface; early-return guard inbefore_agent_start; parse inparsePluginConfigREADME.mdTest plan
autoRecallExcludeAgents: ["test-agent"]and verify gateway logs showauto-recall skipped for excluded agent 'test-agent'on cron triggertsc --noEmitpasses (confirmed locally)parsePluginConfigRelated
<relevant-memories>appearing in conversation history🤖 Generated with Claude Code