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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user