Merge branch 'feature/goose-v149-local-canary'
Memind CI / Test, build, and release guards (push) Has been cancelled
Memind CI / Test, build, and release guards (push) Has been cancelled
This commit is contained in:
+58
-7
@@ -9,6 +9,11 @@ import {
|
||||
isProductCampaignIntent,
|
||||
PAGE_DATA_COLLECT_SKILL_NAME,
|
||||
} from './chat-skills.mjs';
|
||||
import { applyContextBudgetToOrchestration } from './context-budget.mjs';
|
||||
import {
|
||||
applyRecallFusionToMemoryMerge,
|
||||
buildRecallFusionResolvedEvent,
|
||||
} from './recall-fusion.mjs';
|
||||
import { isDirectChatSessionId } from './direct-chat-service.mjs';
|
||||
import {
|
||||
memoryLimitForIntervention,
|
||||
@@ -85,6 +90,9 @@ const OBVIOUS_AGENT_PATTERNS = [
|
||||
/(?:H5|h5|HTML|html|网页|页面).{0,24}(?:生成|创建|制作|做|写|设计|发布)/u,
|
||||
/(?:写|做|生成|制作|设计).{0,16}主题(?:页面|文章)/u,
|
||||
/主题(?:页面|文章).{0,16}(?:写|做|生成|制作|设计)/u,
|
||||
/(?:帮我.{0,12})?(?:做|写|生成|整理).{0,48}(?:游玩|旅行|旅游)?(?:攻略|指南|行程)/u,
|
||||
/(?:我要|我想|想要|需要).{0,16}(?:游玩|旅行|旅游)?(?:攻略|指南|行程|线路图|路线图|行程图)/u,
|
||||
/(?:帮我|给我).{0,12}(?:做|生成|制作).{0,24}(?:线路图|路线图|行程图|行程表)/u,
|
||||
];
|
||||
|
||||
const OBVIOUS_DIRECT_PATTERNS = [
|
||||
@@ -643,6 +651,7 @@ function buildRouterSystemPrompt(grantedSkills = []) {
|
||||
'判断原则:',
|
||||
'- 用户只要文字回答,不要求“做出来/发布/生成链接/改文件” → direct_chat',
|
||||
'- 用户要产出可访问页面、文件、链接,或需要工具/skills → agent_orchestration',
|
||||
'- 用户要「做攻略/行程/线路图/游记」或粘贴多日自驾/旅行行程(即使未说「页面」)→ agent_orchestration + static-page-publish,不要只回文字',
|
||||
'- 用户询问实时赛况、新闻、天气、行情等需要联网查询的问题 → agent_orchestration,suggested_skill 填 web(不要填 search)',
|
||||
'- 不确定时优先 agent_orchestration,避免漏执行',
|
||||
'- 若 [Active Task] 显示上一轮 Agent 任务失败或进行中,用户当前消息是在纠正、补充、追问进度或要求按前文继续 → agent_orchestration,不要判成 direct_chat',
|
||||
@@ -1172,20 +1181,56 @@ export function buildAgentOrchestrationAgentText({
|
||||
return lines.join('\n');
|
||||
}
|
||||
|
||||
export function applyAgentOrchestrationToUserMessage(
|
||||
export function prepareAgentOrchestrationContext(
|
||||
userMessage,
|
||||
classification,
|
||||
{ grantedSkills = [], memoryContext = null, goalContext = null, runtimeContext = null } = {},
|
||||
) {
|
||||
const displayText = messageDisplayText(userMessage);
|
||||
const skillPrompt = resolveSkillPrompt(classification?.suggestedSkill, grantedSkills, displayText);
|
||||
const agentText = buildAgentOrchestrationAgentText({
|
||||
displayText,
|
||||
classification,
|
||||
skillPrompt,
|
||||
const budgeted = applyContextBudgetToOrchestration({
|
||||
memoryContext,
|
||||
goalContext,
|
||||
runtimeContext,
|
||||
skillPrompt,
|
||||
userTask: displayText,
|
||||
});
|
||||
return {
|
||||
displayText,
|
||||
classification,
|
||||
skillPrompt: budgeted.skillPrompt,
|
||||
memoryContext: budgeted.memoryContext,
|
||||
goalContext: budgeted.goalContext,
|
||||
runtimeContext: budgeted.runtimeContext,
|
||||
budgetPlan: budgeted.plan,
|
||||
budgetApplied: budgeted.applied,
|
||||
};
|
||||
}
|
||||
|
||||
export function applyAgentOrchestrationToUserMessage(
|
||||
userMessage,
|
||||
classification,
|
||||
{
|
||||
grantedSkills = [],
|
||||
memoryContext = null,
|
||||
goalContext = null,
|
||||
runtimeContext = null,
|
||||
preparedContext = null,
|
||||
} = {},
|
||||
) {
|
||||
const prepared = preparedContext ?? prepareAgentOrchestrationContext(userMessage, classification, {
|
||||
grantedSkills,
|
||||
memoryContext,
|
||||
goalContext,
|
||||
runtimeContext,
|
||||
});
|
||||
const agentText = buildAgentOrchestrationAgentText({
|
||||
displayText: prepared.displayText,
|
||||
classification: prepared.classification,
|
||||
skillPrompt: prepared.skillPrompt,
|
||||
memoryContext: prepared.memoryContext,
|
||||
goalContext: prepared.goalContext,
|
||||
runtimeContext: prepared.runtimeContext,
|
||||
});
|
||||
const content = Array.isArray(userMessage?.content)
|
||||
? userMessage.content.map((item, index) => {
|
||||
@@ -1197,7 +1242,7 @@ export function applyAgentOrchestrationToUserMessage(
|
||||
: [{ type: 'text', text: agentText }];
|
||||
const metadata = {
|
||||
...(userMessage?.metadata ?? {}),
|
||||
displayText: displayText || undefined,
|
||||
displayText: prepared.displayText || undefined,
|
||||
chatIntentRoute: CHAT_INTENT_ROUTE.AGENT,
|
||||
chatIntentSource: classification?.source ?? null,
|
||||
userVisible: userMessage?.metadata?.userVisible ?? true,
|
||||
@@ -1669,12 +1714,14 @@ export function createChatIntentRouter(options = {}) {
|
||||
agentMemoryPolicy.timeoutMs,
|
||||
'Memory V2 agent resolve',
|
||||
);
|
||||
const memories = mergeAgentMemoryCandidates({
|
||||
const fused = applyRecallFusionToMemoryMerge({
|
||||
personalMemories: personalResolved?.memories,
|
||||
episodicMemories: episodicResolved?.memories,
|
||||
query: text,
|
||||
limit,
|
||||
legacyMerge: mergeAgentMemoryCandidates,
|
||||
});
|
||||
const memories = fused.memories;
|
||||
const degraded = personalFailed
|
||||
|| episodicFailed
|
||||
|| Boolean(personalResolved?.degraded)
|
||||
@@ -1690,6 +1737,8 @@ export function createChatIntentRouter(options = {}) {
|
||||
? (memories.length ? 'partial_memory_resolve_failed' : 'memory_resolve_failed')
|
||||
: (memories.length ? null : (episodicResolved?.reason ?? personalResolved?.reason ?? null)),
|
||||
memories,
|
||||
recallFusion: buildRecallFusionResolvedEvent(fused.fusion),
|
||||
recallFusionApplied: fused.applied,
|
||||
latencyMs: Date.now() - startedAt,
|
||||
};
|
||||
agentMemoryMetrics.resolved += 1;
|
||||
@@ -1898,6 +1947,7 @@ export function createChatIntentRouter(options = {}) {
|
||||
classifySessionAction,
|
||||
resolveAgentMemoryContext,
|
||||
applyAgentOrchestration: applyAgentOrchestrationToUserMessage,
|
||||
prepareAgentOrchestrationContext,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -2002,5 +2052,6 @@ export function createManagedChatIntentRouter({
|
||||
},
|
||||
|
||||
applyAgentOrchestration: applyAgentOrchestrationToUserMessage,
|
||||
prepareAgentOrchestrationContext,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user