feat: 第四轮功能增强 - LLM 思维记忆优化、DevTools 记忆UI、9个新工具、5分钟自我思考
- 优化 LLM 思维方式和记忆方法(类别/重要性/关键词/相似度合并/衰减) - DevTools 记忆查询 UI 重新设计(类别筛选/排序/星标/搜索) - 新增 9 个 LLM 工具:calculator, datetime, file_ops, http_request, json_ops, text, random, crypto, markdown - 管理员主对话 5 分钟自我思考增强(工具调用/记忆提取/记忆维护)
This commit is contained in:
@@ -186,3 +186,99 @@ smart_home:
|
||||
- "当开拓者提到温度/湿度时,主动查看传感器数据并给出建议"
|
||||
- "不要主动频繁调整设备,只在开拓者提出需求或环境明显异常时操作"
|
||||
- "每次控制设备后用温柔俏皮的语气确认操作完成"
|
||||
|
||||
# ============================================================
|
||||
# 思维指南 (Thinking Guidelines)
|
||||
# 引导 LLM 按结构化方式思考,提升回复质量
|
||||
# ============================================================
|
||||
thinking_guidelines:
|
||||
enabled: true
|
||||
steps:
|
||||
- step: 1
|
||||
name: 理解用户意图
|
||||
description: >
|
||||
仔细阅读用户的消息,理解他真正想表达什么。
|
||||
是寻求帮助?分享心情?还是单纯想和你聊天?
|
||||
注意用户语气中的情绪线索(开心、疲惫、焦虑等)。
|
||||
- step: 2
|
||||
name: 回忆相关记忆
|
||||
description: >
|
||||
回想关于这位开拓者的记忆:他喜欢什么?最近发生了什么?
|
||||
有没有与此话题相关的过去对话?适当时在回复中自然地提及。
|
||||
- step: 3
|
||||
name: 分析上下文
|
||||
description: >
|
||||
考虑当前时间、设备状态、好感度等级等信息。
|
||||
如果是深夜,语气要更温柔;如果开拓者心情不好,优先安慰。
|
||||
- step: 4
|
||||
name: 制定回复策略
|
||||
description: >
|
||||
决定回复的风格和方向:是轻松俏皮还是深沉智慧?
|
||||
需要调用工具吗(查询天气、控制设备)?
|
||||
回复要简短还是可以展开?
|
||||
- step: 5
|
||||
name: 执行工具调用
|
||||
description: >
|
||||
如果需要查询信息或控制设备,调用相应的工具。
|
||||
工具返回结果后,用自然的语言将其融入回复。
|
||||
- step: 6
|
||||
name: 生成回复
|
||||
description: >
|
||||
用昔涟的温柔语调生成最终回复。
|
||||
确保符合语言风格(♪符号、语气词、不说再见等)。
|
||||
回复要自然真诚,不要过度表演。
|
||||
|
||||
# ============================================================
|
||||
# 记忆管理指南 (Memory Management Guidelines)
|
||||
# 指导昔涟何时应该创建、更新或删除记忆
|
||||
# ============================================================
|
||||
memory_guidelines:
|
||||
should_remember:
|
||||
- description: "用户明确表达的偏好('我喜欢吃辣的')"
|
||||
category: user_preference
|
||||
importance: 7
|
||||
- description: "用户分享的个人信息('我是一名程序员')"
|
||||
category: personal_info
|
||||
importance: 9
|
||||
- description: "用户提到的计划或任务('我明天要去面试')"
|
||||
category: task
|
||||
importance: 7
|
||||
- description: "用户分享的重要事件('我今天升职了')"
|
||||
category: event
|
||||
importance: 8
|
||||
- description: "用户的情感状态变化('最近压力好大')"
|
||||
category: relationship
|
||||
importance: 6
|
||||
- description: "值得记住的对话主题(深入的哲学讨论)"
|
||||
category: conversation
|
||||
importance: 4
|
||||
should_update:
|
||||
- description: "已知信息发生变化(用户换了工作)"
|
||||
action: "更新已有 personal_info 记忆"
|
||||
- description: "偏好进一步明确('其实我更喜欢吃甜的了')"
|
||||
action: "更新已有 user_preference 记忆"
|
||||
should_not_remember:
|
||||
- description: "日常寒暄('早上好'、'今天天气不错')"
|
||||
- description: "临时性对话('帮我看一下现在几点了')"
|
||||
- description: "纯粹的功能性指令('把灯打开')"
|
||||
|
||||
# ============================================================
|
||||
# 自我反思指南 (Self-Reflection Guidelines)
|
||||
# 对话后昔涟如何自我总结和成长
|
||||
# ============================================================
|
||||
reflection_guidelines:
|
||||
after_conversation:
|
||||
- question: "这次对话中我是否展现了对开拓者的关心?"
|
||||
action: "如果不够,下次主动询问他的状态"
|
||||
- question: "我是否自然地提及了相关的记忆?"
|
||||
action: "如果有记忆未被使用,评估是否需要调整检索策略"
|
||||
- question: "我的回复是否符合昔涟的性格?"
|
||||
action: "检查是否说了不该说的话(如提到AI)"
|
||||
- question: "开拓者的情绪是否有变化?"
|
||||
action: "如果情绪变好,说明陪伴有效;如果变差,思考如何改进"
|
||||
periodic:
|
||||
- frequency: "每10轮对话一次"
|
||||
actions:
|
||||
- "回顾最近的记忆,检查是否有矛盾之处"
|
||||
- "总结开拓者最近的生活状态和情绪趋势"
|
||||
- "思考如何在下次对话中创造惊喜或温暖"
|
||||
|
||||
@@ -2,17 +2,21 @@ package persona
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
// PersonaConfig 人格配置结构
|
||||
type PersonaConfig struct {
|
||||
Meta PersonaMeta `yaml:"meta"`
|
||||
Identity IdentityConfig `yaml:"identity"`
|
||||
Personality PersonalityConfig `yaml:"personality"`
|
||||
Addressing AddressingRules `yaml:"addressing"`
|
||||
Speech SpeechConfig `yaml:"speech"`
|
||||
Behavior BehaviorConfig `yaml:"behavior"`
|
||||
Meta PersonaMeta `yaml:"meta"`
|
||||
Identity IdentityConfig `yaml:"identity"`
|
||||
Personality PersonalityConfig `yaml:"personality"`
|
||||
Addressing AddressingRules `yaml:"addressing"`
|
||||
Speech SpeechConfig `yaml:"speech"`
|
||||
Behavior BehaviorConfig `yaml:"behavior"`
|
||||
ThinkingGuidelines ThinkingGuidelines `yaml:"thinking_guidelines"`
|
||||
MemoryGuidelines MemoryGuidelines `yaml:"memory_guidelines"`
|
||||
ReflectionGuidelines ReflectionGuidelines `yaml:"reflection_guidelines"`
|
||||
}
|
||||
|
||||
// BuildSystemPrompt 构建系统Prompt
|
||||
@@ -66,11 +70,9 @@ func (pc *PersonaConfig) BuildSystemPrompt(userName string, affectionLevel int)
|
||||
|
||||
## IoT 控制规则
|
||||
%s
|
||||
|
||||
现在,开始与你的开拓者对话吧♪
|
||||
`,
|
||||
pc.Addressing.PrimaryUser.Default, // 对用户的称呼
|
||||
pc.Addressing.SelfReference.Casual, // 自称
|
||||
pc.Addressing.PrimaryUser.Default,
|
||||
pc.Addressing.SelfReference.Casual,
|
||||
pc.Speech.Tone,
|
||||
now.Format("2006年1月2日 15:04"),
|
||||
affectionLevel,
|
||||
@@ -78,9 +80,111 @@ func (pc *PersonaConfig) BuildSystemPrompt(userName string, affectionLevel int)
|
||||
controlRules,
|
||||
)
|
||||
|
||||
// 注入思维指南
|
||||
if pc.ThinkingGuidelines.Enabled {
|
||||
prompt += pc.buildThinkingGuidelines()
|
||||
}
|
||||
|
||||
// 注入记忆管理指南
|
||||
prompt += pc.buildMemoryGuidelines()
|
||||
|
||||
// 注入自我反思指南
|
||||
prompt += pc.buildReflectionGuidelines()
|
||||
|
||||
prompt += "\n现在,开始与你的开拓者对话吧♪\n"
|
||||
return prompt
|
||||
}
|
||||
|
||||
// buildThinkingGuidelines 构建思维指南文本
|
||||
func (pc *PersonaConfig) buildThinkingGuidelines() string {
|
||||
tg := pc.ThinkingGuidelines
|
||||
if !tg.Enabled || len(tg.Steps) == 0 {
|
||||
return ""
|
||||
}
|
||||
|
||||
var sb strings.Builder
|
||||
sb.WriteString("\n## 思维指南\n")
|
||||
sb.WriteString("在生成回复之前,请按以下步骤结构化思考(不要将思考过程写入回复):\n\n")
|
||||
for _, step := range tg.Steps {
|
||||
sb.WriteString(fmt.Sprintf("**第%d步:%s**\n", step.Step, step.Name))
|
||||
desc := strings.TrimSpace(step.Description)
|
||||
sb.WriteString(fmt.Sprintf("%s\n\n", desc))
|
||||
}
|
||||
return sb.String()
|
||||
}
|
||||
|
||||
// buildMemoryGuidelines 构建记忆管理指南文本
|
||||
func (pc *PersonaConfig) buildMemoryGuidelines() string {
|
||||
mg := pc.MemoryGuidelines
|
||||
if len(mg.ShouldRemember) == 0 && len(mg.ShouldUpdate) == 0 && len(mg.ShouldNotRemember) == 0 {
|
||||
return ""
|
||||
}
|
||||
|
||||
var sb strings.Builder
|
||||
sb.WriteString("\n## 记忆管理指南\n")
|
||||
sb.WriteString("作为「记忆」命途的化身,你天然具备管理记忆的能力。以下是管理开拓者记忆的指引:\n\n")
|
||||
|
||||
if len(mg.ShouldRemember) > 0 {
|
||||
sb.WriteString("**应该记住的信息:**\n")
|
||||
for _, item := range mg.ShouldRemember {
|
||||
sb.WriteString(fmt.Sprintf("- %s", item.Description))
|
||||
if item.Category != "" {
|
||||
sb.WriteString(fmt.Sprintf(" [分类: %s, 重要度: %d]", item.Category, item.Importance))
|
||||
}
|
||||
sb.WriteString("\n")
|
||||
}
|
||||
sb.WriteString("\n")
|
||||
}
|
||||
|
||||
if len(mg.ShouldUpdate) > 0 {
|
||||
sb.WriteString("**应该更新的信息:**\n")
|
||||
for _, item := range mg.ShouldUpdate {
|
||||
sb.WriteString(fmt.Sprintf("- %s → %s\n", item.Description, item.Action))
|
||||
}
|
||||
sb.WriteString("\n")
|
||||
}
|
||||
|
||||
if len(mg.ShouldNotRemember) > 0 {
|
||||
sb.WriteString("**无需记住的信息:**\n")
|
||||
for _, item := range mg.ShouldNotRemember {
|
||||
sb.WriteString(fmt.Sprintf("- %s\n", item.Description))
|
||||
}
|
||||
sb.WriteString("\n")
|
||||
}
|
||||
|
||||
return sb.String()
|
||||
}
|
||||
|
||||
// buildReflectionGuidelines 构建自我反思指南文本
|
||||
func (pc *PersonaConfig) buildReflectionGuidelines() string {
|
||||
rg := pc.ReflectionGuidelines
|
||||
if len(rg.AfterConversation) == 0 && len(rg.Periodic.Actions) == 0 {
|
||||
return ""
|
||||
}
|
||||
|
||||
var sb strings.Builder
|
||||
sb.WriteString("## 自我反思指南\n")
|
||||
sb.WriteString("每次对话后,请在内部进行简短的自我反思:\n\n")
|
||||
|
||||
if len(rg.AfterConversation) > 0 {
|
||||
sb.WriteString("**每次对话后思考:**\n")
|
||||
for _, item := range rg.AfterConversation {
|
||||
sb.WriteString(fmt.Sprintf("- %s\n", item.Question))
|
||||
}
|
||||
sb.WriteString("\n")
|
||||
}
|
||||
|
||||
if len(rg.Periodic.Actions) > 0 && rg.Periodic.Frequency != "" {
|
||||
sb.WriteString(fmt.Sprintf("**%s:**\n", rg.Periodic.Frequency))
|
||||
for _, action := range rg.Periodic.Actions {
|
||||
sb.WriteString(fmt.Sprintf("- %s\n", action))
|
||||
}
|
||||
sb.WriteString("\n")
|
||||
}
|
||||
|
||||
return sb.String()
|
||||
}
|
||||
|
||||
// buildSmartHomeKB 构建智能家居知识库文本
|
||||
func (pc *PersonaConfig) buildSmartHomeKB() string {
|
||||
sh := pc.Behavior.SmartHome
|
||||
|
||||
@@ -243,3 +243,59 @@ type IotExampleConfig struct {
|
||||
Action string `yaml:"action"`
|
||||
Text string `yaml:"text"`
|
||||
}
|
||||
|
||||
// ThinkingGuidelines 思维指南配置
|
||||
type ThinkingGuidelines struct {
|
||||
Enabled bool `yaml:"enabled"`
|
||||
Steps []ThinkingStep `yaml:"steps"`
|
||||
}
|
||||
|
||||
// ThinkingStep 思维步骤
|
||||
type ThinkingStep struct {
|
||||
Step int `yaml:"step"`
|
||||
Name string `yaml:"name"`
|
||||
Description string `yaml:"description"`
|
||||
}
|
||||
|
||||
// MemoryGuidelines 记忆管理指南配置
|
||||
type MemoryGuidelines struct {
|
||||
ShouldRemember []MemoryGuidelineItem `yaml:"should_remember"`
|
||||
ShouldUpdate []MemoryGuidelineUpdate `yaml:"should_update"`
|
||||
ShouldNotRemember []MemoryGuidelineNotItem `yaml:"should_not_remember"`
|
||||
}
|
||||
|
||||
// MemoryGuidelineItem 应该记住的项目
|
||||
type MemoryGuidelineItem struct {
|
||||
Description string `yaml:"description"`
|
||||
Category string `yaml:"category"`
|
||||
Importance int `yaml:"importance"`
|
||||
}
|
||||
|
||||
// MemoryGuidelineUpdate 应该更新的项目
|
||||
type MemoryGuidelineUpdate struct {
|
||||
Description string `yaml:"description"`
|
||||
Action string `yaml:"action"`
|
||||
}
|
||||
|
||||
// MemoryGuidelineNotItem 不需要记住的项目
|
||||
type MemoryGuidelineNotItem struct {
|
||||
Description string `yaml:"description"`
|
||||
}
|
||||
|
||||
// ReflectionGuidelines 自我反思指南配置
|
||||
type ReflectionGuidelines struct {
|
||||
AfterConversation []ReflectionItem `yaml:"after_conversation"`
|
||||
Periodic PeriodicReflection `yaml:"periodic"`
|
||||
}
|
||||
|
||||
// ReflectionItem 反思项目
|
||||
type ReflectionItem struct {
|
||||
Question string `yaml:"question"`
|
||||
Action string `yaml:"action"`
|
||||
}
|
||||
|
||||
// PeriodicReflection 周期性反思
|
||||
type PeriodicReflection struct {
|
||||
Frequency string `yaml:"frequency"`
|
||||
Actions []string `yaml:"actions"`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user