fix(wechat): guard ambiguous memory recall and scheduled task execution
Skip memory injection for short filler messages, demote page-workflow memory pollution, keep scheduled automation off page.generate, and fail scheduled tasks that only return clarification instead of deliverables. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -208,6 +208,40 @@ export function isMemoryRecallQuestion(text) {
|
||||
return MEMORY_RECALL_PATTERNS.some((pattern) => pattern.test(normalized));
|
||||
}
|
||||
|
||||
const PAGE_WORKFLOW_QUERY_PATTERNS = [
|
||||
/(?:生成|做成|整理|排版|导出|发布).{0,8}(?:页面|网页|html|专题|报告页|推文)/iu,
|
||||
/(?:mindspace|MindSpace)/u,
|
||||
/每日新闻/u,
|
||||
];
|
||||
|
||||
const PAGE_WORKFLOW_MEMORY_PATTERNS = [
|
||||
/(?:做成|生成|整理|排版).{0,8}(?:页面|网页|html|专题|报告)/iu,
|
||||
/每日新闻/u,
|
||||
/(?:mindspace|MindSpace)/u,
|
||||
/页面.{0,8}(?:偏好|习惯|模板)/u,
|
||||
];
|
||||
|
||||
export function queryImpliesPageWorkflow(text) {
|
||||
const normalized = String(text ?? '').trim();
|
||||
if (!normalized) return false;
|
||||
return PAGE_WORKFLOW_QUERY_PATTERNS.some((pattern) => pattern.test(normalized));
|
||||
}
|
||||
|
||||
function isPageWorkflowMemory(text) {
|
||||
const normalized = String(text ?? '').trim();
|
||||
if (!normalized) return false;
|
||||
return PAGE_WORKFLOW_MEMORY_PATTERNS.some((pattern) => pattern.test(normalized));
|
||||
}
|
||||
|
||||
export function shouldSkipAmbiguousMemoryQuery(text) {
|
||||
const normalized = String(text ?? '').trim();
|
||||
if (!normalized) return true;
|
||||
if (isMemoryRecallQuestion(normalized)) return false;
|
||||
if (pgvectorMemoryBackendInternals.extractKeywordTerms(normalized).length > 0) return false;
|
||||
// Short acknowledgements/fillers without a topic anchor (e.g. 「可以」「先不聊了」).
|
||||
return normalized.length <= 4;
|
||||
}
|
||||
|
||||
function memoryItemText(item) {
|
||||
return String(item?.text ?? item?.memory_text ?? item?.content ?? '').trim();
|
||||
}
|
||||
@@ -229,6 +263,13 @@ export function scoreAgentMemoryCandidate(item, query) {
|
||||
}
|
||||
let score = (lexical * 100) + keywordBoost;
|
||||
if (isEpisodicMemoryItem(item) && score > 0) score += 5;
|
||||
if (
|
||||
isPageWorkflowMemory(text)
|
||||
&& !queryImpliesPageWorkflow(query)
|
||||
&& !isMemoryRecallQuestion(query)
|
||||
) {
|
||||
score -= 100;
|
||||
}
|
||||
return score;
|
||||
}
|
||||
|
||||
@@ -1366,6 +1407,11 @@ export function createChatIntentRouter(options = {}) {
|
||||
agentMemoryMetrics.lastReason = 'intervention_skip';
|
||||
return { ...base, reason: 'intervention_skip' };
|
||||
}
|
||||
if (shouldSkipAmbiguousMemoryQuery(text)) {
|
||||
agentMemoryMetrics.skipped += 1;
|
||||
agentMemoryMetrics.lastReason = 'ambiguous_query_skip';
|
||||
return { ...base, reason: 'ambiguous_query_skip' };
|
||||
}
|
||||
const startedAt = Date.now();
|
||||
try {
|
||||
let personalFailed = false;
|
||||
|
||||
Reference in New Issue
Block a user