feat(intelligence): Phase 5 主动行为激活 — 注入格式 + 跨会话连续性 + 触发持久化
Some checks failed
CI / Lint & TypeCheck (push) Has been cancelled
CI / Unit Tests (push) Has been cancelled
CI / Build Frontend (push) Has been cancelled
CI / Rust Check (push) Has been cancelled
CI / Security Scan (push) Has been cancelled
CI / E2E Tests (push) Has been cancelled

Task 5.1+5.4: ButlerRouter/experience 注入格式升级为 <butler-context> XML fencing
- butler_router: [路由上下文] → <butler-context><routing>...</routing></butler-context>
- experience: [过往经验] → <butler-context><experience>...</experience></butler-context>
- 统一 system-note 提示,引导 LLM 自然运用上下文

Task 5.2: 跨会话连续性 — pre_conversation_hook 注入活跃痛点 + 相关经验
- 从 VikingStorage 检索相关记忆(相似度>=0.3)
- 从 pain_aggregator 获取 High severity 痛点(top 3)

Task 5.3: 触发信号持久化 — post_conversation_hook 将触发信号存入 VikingStorage
- store_trigger_experience(): 模板提取,零 LLM 成本
- 为未来 LLM 深度反思积累数据基础
This commit is contained in:
iven
2026-04-12 18:31:37 +08:00
parent edf66ab8e6
commit b357916d97
3 changed files with 152 additions and 15 deletions

View File

@@ -201,12 +201,15 @@ impl ButlerRouterMiddleware {
}
/// Domain context to inject into system prompt based on routing hint.
///
/// Uses structured `<butler-context>` XML fencing (Hermes-inspired) for
/// reliable prompt cache preservation across turns.
fn build_context_injection(hint: &RoutingHint) -> String {
// Semantic skill routing
if hint.category == "semantic_skill" {
if let Some(ref skill_id) = hint.skill_id {
return format!(
"\n\n[语义路由] 匹配技能: {} (置信度: {:.0}%)\n系统检测到用户的意图与已注册技能高度相关,请在回答中充分利用该技能的能力。",
"\n\n<butler-context>\n<routing>匹配技能: {} (置信度: {:.0}%)</routing>\n<system-note>系统检测到用户的意图与已注册技能高度相关,请在回答中充分利用该技能的能力。</system-note>\n</butler-context>",
skill_id,
hint.confidence * 100.0
);
@@ -230,11 +233,11 @@ impl ButlerRouterMiddleware {
}
let skill_info = hint.skill_id.as_ref().map_or(String::new(), |id| {
format!("\n关联技能: {}", id)
format!("\n<skill>{}</skill>", id)
});
format!(
"\n\n[路由上下文] (置信度: {:.0}%)\n{}{}",
"\n\n<butler-context>\n<routing confidence=\"{:.0}%\">{}</routing>{}<system-note>以上是管家系统对您当前意图的分析。在对话中自然运用这些信息,主动提供有帮助的建议。</system-note>\n</butler-context>",
hint.confidence * 100.0,
domain_context,
skill_info
@@ -357,7 +360,7 @@ mod tests {
domain_prompt: None,
};
let injection = ButlerRouterMiddleware::build_context_injection(&hint);
assert!(injection.contains("路由上下文"));
assert!(injection.contains("butler-context"));
assert!(injection.contains("医院"));
assert!(injection.contains("80%"));
}
@@ -435,7 +438,7 @@ mod tests {
let decision = mw.before_completion(&mut ctx).await.unwrap();
assert!(matches!(decision, MiddlewareDecision::Continue));
assert!(ctx.system_prompt.contains("路由上下文"));
assert!(ctx.system_prompt.contains("butler-context"));
assert!(ctx.system_prompt.contains("医院"));
}
@@ -464,7 +467,7 @@ mod tests {
let decision = mw.before_completion(&mut ctx).await.unwrap();
assert!(matches!(decision, MiddlewareDecision::Continue));
assert!(ctx.system_prompt.contains("路由上下文"));
assert!(ctx.system_prompt.contains("butler-context"));
assert!(ctx.system_prompt.contains("电商运营管家"));
}