llm mail integration
This commit is contained in:
56
internal/agents/memory/agent.go
Normal file
56
internal/agents/memory/agent.go
Normal file
@@ -0,0 +1,56 @@
|
||||
// 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)}
|
||||
}
|
||||
Reference in New Issue
Block a user