Repository navigation
feat(openclaw-plugin): add topic-judge pre-filter to skip auto-recall on topic continuation - #1379
duoyidavid-eng wants to merge 3 commits into
Conversation
977a4a9 to
a28b435
Compare
… on topic continuation Add a lightweight LLM-based pre-filter before auto-recall search to avoid unnecessary embedding + vector search + LLM filter calls when the user is continuing the current conversation. - Extract topicJudgePreFilter() as a standalone function returning 'skip'|'proceed' - Configurable via recall.topicJudgeRounds (default: 4, set 0 to disable) - Uses existing Summarizer.judgeNewTopic() (already implemented in all providers) - Graceful fallback: too-few-lines → skip; LLM error → proceed with recall - Only 1 small LLM call (max_tokens=10) vs full search pipeline saved on SAME
a28b435 to
57aaafd
Compare
shinetata
left a comment
There was a problem hiding this comment.
Thanks @duoyidavid-eng — the underlying problem is real (per-turn auto-recall carries non-trivial cost/latency) and reusing the already-present judgeNewTopic() is a clever idea. My feedback is mostly about the shape of the solution, not the goal. I'd suggest reshaping this before merge rather than landing as-is.
1. Please don't enable it by default. topicJudgeRounds: 4 puts a synchronous LLM round-trip on the critical path of every turn. That works against #1452 (auto-recall blocking gateway startup / first-turn health checks): on a first turn / new topic, judgeNewTopic returns NEW and we still run recall — so it's strictly +1 LLM call on the slowest path. Suggest defaulting to 0 (opt-in).
2. The saving is smaller than it looks. The dominant cost is the LLM round-trip, not the local embedding + search. On a continuation turn we still pay one round-trip (judgeNewTopic instead of filterRelevant); on a new-topic turn it's pure overhead. So it's "swap one LLM call for a slightly smaller one + skip local search," not "save the ~2-3s pipeline."
3. The motivating cases are largely covered already. "ok" / typos / short follow-ups are already short-circuited by recall.autoRecallMinQueryLength (#1347), which runs before this pre-filter. After a rebase, judgeNewTopic only fires on longer same-topic messages — a narrower slice than the description implies.
4. Product tension. "Same topic" != "no memory needed" — same-topic deepening is often exactly when a memory from another past session helps. A coarse topic gate risks suppressing useful cross-session recall, which is the plugin's headline behavior; filterRelevant is more precise because it inspects the actual candidates.
If we keep it (as an opt-in fallback layered after the cheap gates), a few implementation must-dos:
- Rebase — the hook was rewritten since March (#1311 / #1347 / #1514 / #1532). The patch anchor
engine.search({ ... maxResults: 10 ... })no longer exists; it's now a parallel local + hub search followed by a singlefilterRelevant. The PR is currently CONFLICTING. - Tests — none yet. Note the green checks here are the Python build matrix; they do not run the
apps/memos-local-openclawvitest suite, so this change isn't actually exercised by CI. Please add unit tests (SAME / NEW / null branches, metadata stripping, parse-failure fallback), following e.g.topic-judge-minimax-1315.test.ts/auto-recall-cron-gate.test.ts. - Extract the pure logic into
src/recall/(mirroringsession-policy.ts) instead of a ~100-line nested function inindex.ts, and avoid the hardcoded injected-prompt string stripping — those markers are defined elsewhere and will drift. - Fail open — too-few-lines / parse error should
proceed(recall), notskip; for a memory system, skipping is the aggressive choice, and this also matches your own "LLM error -> proceed" rule. - Minor: the description says
before_agent_start, but the hook isbefore_prompt_build.
Happy to help with the rebase, or with an extracted src/recall/topic-judge.ts + tests, if that's useful.
🤖 Open Code ReviewTarget: PR #1379 🔍 OpenCodeReview found 5 issue(s) in this PR. 1.
|
✅ Automated Test Results: PASSEDAll tests passed (21/21 executed). memos_local_openclaw/unit: 21/21. Duration: 3s Branch: |
|
Resolved the conflicts against the current
Current head: |
|
The issue is valid as a cost/latency optimization, but the proposed topic-based gating may be unnecessarily complex and risks missing relevant memories during same-topic follow-ups. Users who prefer fully agent-driven retrieval can already disable automatic recall with |
Problem
The
before_prompt_buildauto-recall hook can run a candidate search and relevance-filter LLM call even when a longer user message is clearly continuing the current topic.Solution
Add an opt-in topic-judge pre-filter using the existing
Summarizer.judgeNewTopic()implementation. It runs after the existing cheap session and short-query gates, and before the current parallel local + Hub search flow.Flow:
Config
recall.topicJudgeRoundsdefaults to0, so the extra LLM call is disabled unless explicitly enabled:{ "plugins": { "entries": { "memos-local-openclaw-plugin": { "config": { "recall": { "topicJudgeRounds": 4 } } } } } }0(default)N > 0Implementation
src/recall/topic-judge.ts.stripInboundMetadata()instead of duplicating injection markers.filterRelevantpass.