merge: semantic WeChat session actions
Memind CI / Test, build, and release guards (push) Successful in 2m39s
Memind CI / Test, build, and release guards (push) Successful in 2m39s
This commit is contained in:
@@ -543,6 +543,23 @@ function parseRouterJson(reply) {
|
||||
}
|
||||
}
|
||||
|
||||
const WECHAT_SESSION_ACTIONS = new Set(['continue', 'reset', 'ignore_previous', 'unclear']);
|
||||
|
||||
function buildWechatSessionActionPrompt(text) {
|
||||
return [
|
||||
'你是微信聊天会话动作分类器,只判断用户是否要切换上下文。',
|
||||
'只输出 JSON,不要 markdown:',
|
||||
'{"action":"continue|reset|ignore_previous|unclear","confidence":0.0,"reason":"一句话"}',
|
||||
'reset:用户要开启全新会话、重新开始、换一个完全不同的对话。',
|
||||
'ignore_previous:用户只要求不要参考之前某段内容,但不一定要创建新会话。',
|
||||
'continue:用户明确要沿用当前话题或继续上文。',
|
||||
'unclear:无法确定,不要擅自切换。',
|
||||
'',
|
||||
'[User]',
|
||||
String(text ?? '').trim() || '(empty)',
|
||||
].join('\n');
|
||||
}
|
||||
|
||||
function normalizeRoute(value) {
|
||||
const normalized = String(value ?? '').trim().toLowerCase();
|
||||
if (normalized === CHAT_INTENT_ROUTE.DIRECT_CHAT || normalized === ROUTER_DECISION_ROUTE.CHAT) {
|
||||
@@ -1275,10 +1292,44 @@ export function createChatIntentRouter(options = {}) {
|
||||
}, { source: 'fallback' }));
|
||||
}
|
||||
|
||||
async function classifySessionAction({ text } = {}) {
|
||||
// The general H5 router intentionally remains rule/skill-only. Session
|
||||
// action classification is separately opt-in because it runs before every
|
||||
// WeChat Agent request that contains a context hint.
|
||||
if (!policy.enabled || typeof llmProviderService?.createChatCompletion !== 'function') return null;
|
||||
try {
|
||||
const completion = await withTimeout(
|
||||
llmProviderService.createChatCompletion({
|
||||
providerKeyId: policy.modelProviderKeyId || undefined,
|
||||
model: policy.model || undefined,
|
||||
temperature: 0,
|
||||
messages: [
|
||||
{ role: 'system', content: buildWechatSessionActionPrompt(text) },
|
||||
],
|
||||
}),
|
||||
Math.min(policy.timeoutMs, 1200),
|
||||
'WeChat session action classifier',
|
||||
);
|
||||
if (!completion?.ok) return null;
|
||||
const parsed = parseRouterJson(completion.reply);
|
||||
const action = String(parsed?.action ?? '').trim().toLowerCase();
|
||||
if (!WECHAT_SESSION_ACTIONS.has(action)) return null;
|
||||
return {
|
||||
action,
|
||||
confidence: Number(parsed?.confidence),
|
||||
reason: String(parsed?.reason ?? '').trim(),
|
||||
};
|
||||
} catch (err) {
|
||||
logger?.warn?.('[chat-intent-router] WeChat session action classification skipped:', err);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
getStatus,
|
||||
isEnabled,
|
||||
classify,
|
||||
classifySessionAction,
|
||||
resolveAgentMemoryContext,
|
||||
applyAgentOrchestration: applyAgentOrchestrationToUserMessage,
|
||||
};
|
||||
@@ -1374,6 +1425,11 @@ export function createManagedChatIntentRouter({
|
||||
return router.classify(input);
|
||||
},
|
||||
|
||||
async classifySessionAction(input = {}) {
|
||||
const router = await ensureRouter();
|
||||
return router.classifySessionAction(input);
|
||||
},
|
||||
|
||||
async resolveAgentMemoryContext(input = {}) {
|
||||
const router = await ensureRouter();
|
||||
return router.resolveAgentMemoryContext(input);
|
||||
|
||||
Reference in New Issue
Block a user