mirror of
https://github.com/Ed1s0nZ/CyberStrikeAI.git
synced 2026-10-21 23:01:37 +02:00
feat: scope automatic working memory to the current conversation
This commit is contained in:
1 parent
1d2e900e88
commit
6b8bbbe91b
14 files changed
+443
-40
No files matched your search
@@ -216,7 +216,7 @@ func newEinoAgenticSummarizationMiddleware(
|
||||
}
|
||||
out = mergeMessageIntoLeadingSystem(out, userLedger)
|
||||
if appCfg != nil {
|
||||
out = refreshFactIndexInMessages(out, db, projectID, appCfg.Project, logger)
|
||||
out = refreshFactIndexInMessages(out, db, projectID, appCfg.Project, logger, conversationID)
|
||||
}
|
||||
return EinoMessagesToAgentic(out), nil
|
||||
},
|
||||
|
||||
@@ -134,6 +134,10 @@ func TestSummarizationMiddlewaresAutomaticallySaveCheckpoint(t *testing.T) {
|
||||
for _, native := range []bool{false, true} {
|
||||
t.Run(fmt.Sprintf("native=%v", native), func(t *testing.T) {
|
||||
db, pid, cid := checkpointTestProject(t)
|
||||
_, err := db.UpsertProjectFact(&database.ProjectFact{ProjectID: pid, FactKey: "note/context-other", SourceConversationID: "different-conversation", Summary: "FOREIGN_PROGRESS", Body: "FOREIGN_COOKIE", Pinned: true})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
cfg := &config.Config{Project: config.ProjectConfig{Enabled: true}}
|
||||
cfg.Database.Path = filepath.Join(t.TempDir(), "runtime.db")
|
||||
cfg.OpenAI.Model = "gpt-4o"
|
||||
@@ -177,14 +181,20 @@ func TestSummarizationMiddlewaresAutomaticallySaveCheckpoint(t *testing.T) {
|
||||
after = state.Messages
|
||||
}
|
||||
facts, err := db.ListProjectFacts(pid, database.ProjectFactListFilter{}, 100, 0)
|
||||
if err != nil || len(facts) != 1 {
|
||||
if err != nil || len(facts) != 2 {
|
||||
t.Fatalf("automatic checkpoint missing: %v %#v", err, facts)
|
||||
}
|
||||
if !strings.Contains(facts[0].Body, "/api/check") || strings.Contains(facts[0].Body, "scratchpad") {
|
||||
t.Fatalf("wrong working memory: %s", facts[0].Body)
|
||||
var checkpoint *database.ProjectFact
|
||||
for _, f := range facts {
|
||||
if f.SourceConversationID == cid {
|
||||
checkpoint = f
|
||||
}
|
||||
}
|
||||
if checkpoint == nil || !strings.Contains(checkpoint.Body, "/api/check") || strings.Contains(checkpoint.Body, "scratchpad") {
|
||||
t.Fatalf("wrong working memory: %#v", checkpoint)
|
||||
}
|
||||
joined := joinClassicMessageContent(after)
|
||||
if !strings.Contains(joined, facts[0].FactKey) || strings.Contains(joined, "(暂无事实)") {
|
||||
if !strings.Contains(joined, checkpoint.FactKey) || strings.Contains(joined, "(暂无事实)") || strings.Contains(joined, "FOREIGN_PROGRESS") || strings.Contains(joined, "note/context-other") {
|
||||
t.Fatalf("live index did not refresh after save: %s", joined)
|
||||
}
|
||||
snapshots, err := filepath.Glob(filepath.Join(filepath.Dir(cfg.Database.Path), "conversation_artifacts", cid, "summarization", "snapshots", "*.txt"))
|
||||
|
||||
@@ -268,7 +268,7 @@ func newEinoSummarizationMiddleware(
|
||||
}
|
||||
out = mergeMessageIntoLeadingSystem(out, userLedger)
|
||||
if appCfg != nil {
|
||||
out = refreshFactIndexInMessages(out, db, projectID, appCfg.Project, logger)
|
||||
out = refreshFactIndexInMessages(out, db, projectID, appCfg.Project, logger, conversationID)
|
||||
}
|
||||
return out, nil
|
||||
},
|
||||
@@ -473,7 +473,7 @@ func buildPlaintextSummarizationInput(
|
||||
}
|
||||
|
||||
// refreshFactIndexInMessages 在 summarization 压缩后,用 DB 最新索引替换 system 中已有的项目黑板索引段。
|
||||
func refreshFactIndexInMessages(msgs []adk.Message, db *database.DB, projectID string, cfg config.ProjectConfig, logger *zap.Logger) []adk.Message {
|
||||
func refreshFactIndexInMessages(msgs []adk.Message, db *database.DB, projectID string, cfg config.ProjectConfig, logger *zap.Logger, conversationIDs ...string) []adk.Message {
|
||||
if db == nil || !cfg.Enabled {
|
||||
return msgs
|
||||
}
|
||||
@@ -481,7 +481,7 @@ func refreshFactIndexInMessages(msgs []adk.Message, db *database.DB, projectID s
|
||||
if projectID == "" {
|
||||
return msgs
|
||||
}
|
||||
freshIndex, err := project.BuildFactIndexBlock(db, projectID, cfg)
|
||||
freshIndex, err := project.BuildFactIndexBlock(db, projectID, cfg, conversationIDs...)
|
||||
if err != nil {
|
||||
if logger != nil {
|
||||
logger.Warn("summarization: 刷新项目黑板索引失败", zap.String("projectId", projectID), zap.Error(err))
|
||||
|
||||
@@ -406,7 +406,7 @@ func RunDeepAgent(
|
||||
var taskBlackboardSupplement string
|
||||
if appCfg.Project.Enabled && db != nil {
|
||||
if pid := strings.TrimSpace(projectID); pid != "" {
|
||||
if block, err := project.BuildFactIndexBlock(db, pid, appCfg.Project); err == nil {
|
||||
if block, err := project.BuildFactIndexBlock(db, pid, appCfg.Project, conversationID); err == nil {
|
||||
taskBlackboardSupplement = strings.TrimSpace(block)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user