mirror of
https://github.com/YspCoder/clawgo.git
synced 2026-05-02 07:07:29 +08:00
improve memory source citations and auto-attach recall source hints
This commit is contained in:
@@ -307,9 +307,13 @@ func (al *AgentLoop) processMessage(ctx context.Context, msg bus.InboundMessage)
|
||||
|
||||
history := al.sessions.GetHistory(msg.SessionKey)
|
||||
summary := al.sessions.GetSummary(msg.SessionKey)
|
||||
memoryRecallUsed := false
|
||||
memoryRecallText := ""
|
||||
if shouldRecallMemory(msg.Content) {
|
||||
if recall, err := al.tools.Execute(ctx, "memory_search", map[string]interface{}{"query": msg.Content, "maxResults": 3}); err == nil && strings.TrimSpace(recall) != "" {
|
||||
summary = strings.TrimSpace(summary + "\n\n[Memory Recall]\n" + recall)
|
||||
memoryRecallUsed = true
|
||||
memoryRecallText = strings.TrimSpace(recall)
|
||||
summary = strings.TrimSpace(summary + "\n\n[Memory Recall]\n" + memoryRecallText)
|
||||
}
|
||||
}
|
||||
if explicitPref := ExtractLanguagePreference(msg.Content); explicitPref != "" {
|
||||
@@ -472,6 +476,12 @@ func (al *AgentLoop) processMessage(ctx context.Context, msg bus.InboundMessage)
|
||||
}
|
||||
}
|
||||
|
||||
if memoryRecallUsed && !strings.Contains(strings.ToLower(userContent), "source:") {
|
||||
if src := extractFirstSourceLine(memoryRecallText); src != "" {
|
||||
userContent = strings.TrimSpace(userContent + "\n\n" + src)
|
||||
}
|
||||
}
|
||||
|
||||
al.sessions.AddMessage(msg.SessionKey, "user", msg.Content)
|
||||
|
||||
// 使用 AddMessageFull 存储包含思考过程或工具调用的完整助手消息
|
||||
@@ -847,6 +857,16 @@ func shouldRecallMemory(text string) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func extractFirstSourceLine(text string) string {
|
||||
for _, line := range strings.Split(text, "\n") {
|
||||
t := strings.TrimSpace(line)
|
||||
if strings.HasPrefix(strings.ToLower(t), "source:") {
|
||||
return t
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func alSessionListForTool(sm *session.SessionManager, limit int) []tools.SessionInfo {
|
||||
items := sm.List(limit)
|
||||
out := make([]tools.SessionInfo, 0, len(items))
|
||||
|
||||
Reference in New Issue
Block a user