Files
2026-03-19 21:46:12 +01:00

57 lines
1.5 KiB
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// memory/agent.go Memory-Agent: wraps brain.RunIngest und brain.IngestChatMessage
package memory
import (
"fmt"
"strings"
"my-brain-importer/internal/agents"
"my-brain-importer/internal/brain"
"my-brain-importer/internal/config"
)
// Agent verwaltet das Einspeichern von Wissen.
type Agent struct{}
func New() *Agent { return &Agent{} }
// Handle unterstützt zwei Aktionen:
// - "store": Speichert Text als Chat-Nachricht
// - "ingest": Startet den Markdown-Ingest aus brain_root
func (a *Agent) Handle(req agents.Request) agents.Response {
switch req.Action {
case agents.ActionStore:
return a.store(req)
case agents.ActionIngest:
return a.ingest(req)
default:
return agents.Response{Text: "❌ Unbekannte Memory-Aktion. Verfügbar: store, ingest"}
}
}
func (a *Agent) store(req agents.Request) agents.Response {
if len(req.Args) == 0 {
return agents.Response{Text: "❌ Kein Text zum Speichern angegeben."}
}
text := strings.Join(req.Args, " ")
author := req.Author
if author == "" {
author = "unknown"
}
source := req.Source
if source == "" {
source = "agent"
}
err := brain.IngestChatMessage(text, author, source)
if err != nil {
return agents.Response{Error: err, Text: fmt.Sprintf("❌ Fehler beim Speichern: %v", err)}
}
return agents.Response{Text: fmt.Sprintf("✅ Gespeichert: _%s_", text)}
}
func (a *Agent) ingest(_ agents.Request) agents.Response {
brain.RunIngest(config.Cfg.BrainRoot)
return agents.Response{Text: fmt.Sprintf("✅ Ingest abgeschlossen! Quelle: `%s`", config.Cfg.BrainRoot)}
}