optimize:优化记忆格式化逻辑,确保完整记忆内容不被截断,同时更新工具定义中的描述,增强用户对记忆回想器的理解和使用指导。

This commit is contained in:
sean
2025-06-17 16:06:45 +08:00
parent f88860233f
commit fb9540fd4a
3 changed files with 141 additions and 152 deletions

View File

@ -263,28 +263,17 @@ ${formattedMemories}
*/
formatRetrievedKnowledge (memories, query) {
return memories.map((memory, index) => {
// 多行内容处理:如果内容包含换行,保持原始格式,但限制总长度
// 保持完整的记忆内容,不进行截断
// 陈述性记忆的完整性对于系统价值至关重要
let content = memory.content
if (content.length > 200) {
// 保持换行结构但截断过长内容
const lines = content.split('\n')
let truncated = ''
let currentLength = 0
for (const line of lines) {
if (currentLength + line.length + 1 > 180) {
truncated += '...'
break
}
truncated += (truncated ? '\n' : '') + line
currentLength += line.length + 1
}
content = truncated
}
// 只对格式进行优化,但不截断内容
// 确保换行符正确显示
content = content.trim()
return `📝 ${index + 1}. **记忆** (${memory.timestamp})
${content}
${memory.tags.slice(0, 5).join(' ')}
${memory.tags.slice(0, 8).join(' ')}
---`
}).join('\n')
}