MCPcopy Create free account
hub / github.com/astercloud/aster / buildMemorySection

Method buildMemorySection

pkg/middleware/logic_memory.go:386–417  ·  view source on GitHub ↗

buildMemorySection 构建 Memory 注入文本

(memories []*logic.LogicMemory)

Source from the content-addressed store, hash-verified

384
385// buildMemorySection 构建 Memory 注入文本
386func (m *LogicMemoryMiddleware) buildMemorySection(memories []*logic.LogicMemory) string {
387 if len(memories) == 0 {
388 return ""
389 }
390
391 var builder strings.Builder
392 builder.WriteString("## User Preferences and Memory\n\n")
393 builder.WriteString("Based on past interactions, I've learned the following about this user:\n\n")
394
395 for i, mem := range memories {
396 // 格式化每个 Memory
397 confidence := 0.0
398 if mem.Provenance != nil {
399 confidence = mem.Provenance.Confidence
400 }
401
402 builder.WriteString(fmt.Sprintf("%d. **%s** (%s)\n", i+1, mem.Type, mem.Key))
403 builder.WriteString(fmt.Sprintf(" - %s\n", mem.Description))
404 builder.WriteString(fmt.Sprintf(" - Confidence: %.0f%%\n", confidence*100))
405
406 // 如果有分类,也显示
407 if mem.Category != "" {
408 builder.WriteString(fmt.Sprintf(" - Category: %s\n", mem.Category))
409 }
410
411 builder.WriteString("\n")
412 }
413
414 builder.WriteString("**Please apply these preferences naturally in your response.** Do not explicitly mention these memories unless directly relevant.\n")
415
416 return fmt.Sprintf(m.config.SystemPromptTemplate, builder.String())
417}
418
419// extractSourceFromToolContext 从工具上下文中提取 source
420func (m *LogicMemoryMiddleware) extractSourceFromToolContext(req *ToolCallRequest) string {

Callers 2

TestBuildMemorySectionFunction · 0.95
WrapModelCallMethod · 0.95

Calls 1

StringMethod · 0.45

Tested by 1

TestBuildMemorySectionFunction · 0.76