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:
john
2026-08-01 22:49:52 +08:00
parent dcf83e9b6f
commit 26fe5912a3
9 changed files with 222 additions and 0 deletions
+61
View File
@@ -31,6 +31,7 @@ import {
resolveChatIntentRouterPolicy,
mergeAgentMemoryCandidates,
scoreAgentMemoryCandidate,
shouldSkipAmbiguousMemoryQuery,
} from './chat-intent-router.mjs';
/** Ambiguous user text that should miss FAQ/rules and exercise LLM router paths in tests. */
@@ -1398,6 +1399,66 @@ test('scoreAgentMemoryCandidate boosts episodic matches when topic overlap exist
assert.ok(episodicScore > personalScore);
});
test('shouldSkipAmbiguousMemoryQuery skips filler without topic anchor', () => {
assert.equal(shouldSkipAmbiguousMemoryQuery('可以'), true);
assert.equal(shouldSkipAmbiguousMemoryQuery('我们继续聊聊德川家康'), false);
assert.equal(shouldSkipAmbiguousMemoryQuery('9岁小孩教育'), false);
assert.equal(shouldSkipAmbiguousMemoryQuery('你记得我们聊过什么吗'), false);
});
test('agent memory skips resolve for ambiguous short filler', async () => {
const calls = [];
const router = createChatIntentRouter({
env: {
MEMORY_AGENT_RESOLVE_ENABLED: '1',
MEMORY_AGENT_INJECTION_MODE: 'active',
},
memoryV2: {
async resolve(input) {
calls.push(input);
return { memories: [{ label: 'preference', text: '每日新闻页面偏好' }] };
},
},
});
const result = await router.resolveAgentMemoryContext({
userId: 'user-tang',
text: '可以',
});
assert.equal(result.skipped, true);
assert.equal(result.reason, 'ambiguous_query_skip');
assert.equal(result.memories.length, 0);
assert.equal(calls.length, 0);
});
test('agent memory merge demotes page workflow memories when query is general chat', () => {
const merged = mergeAgentMemoryCandidates({
query: '9岁小孩教育,孩子玩手机超时怎么办',
limit: 2,
personalMemories: [
{ id: 'personal:news', label: 'preference', text: '用户希望整理每日新闻并做成页面发布' },
{ id: 'personal:kid', label: 'experience', text: '用户关心9岁孩子教育与手机使用边界' },
],
});
assert.equal(merged[0].id, 'personal:kid');
});
test('scoreAgentMemoryCandidate penalizes page workflow memories on general chat', () => {
const pageScore = scoreAgentMemoryCandidate({
id: 'personal:news',
label: 'preference',
text: '用户希望整理每日新闻并做成页面发布',
}, '可以,我们继续聊孩子教育');
const topicScore = scoreAgentMemoryCandidate({
id: 'personal:kid',
label: 'experience',
text: '用户关心9岁孩子教育与手机使用边界',
}, '可以,我们继续聊孩子教育');
assert.ok(topicScore > pageScore);
});
test('active agent memory context is hidden from displayText but available to orchestration envelope', () => {
const enriched = applyAgentOrchestrationToUserMessage(
{