mirror of
https://github.com/Ed1s0nZ/CyberStrikeAI.git
synced 2026-10-20 06:27:53 +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
@@ -60,7 +60,7 @@ func (h *AgentHandler) projectBlackboardBlock(conversationID string) string {
|
||||
if err != nil || projectID == "" {
|
||||
return ""
|
||||
}
|
||||
block, err := project.BuildProjectBlackboardBlock(h.db, projectID, h.config.Project)
|
||||
block, err := project.BuildProjectBlackboardBlock(h.db, projectID, h.config.Project, conversationID)
|
||||
if err != nil {
|
||||
h.logger.Warn("构建项目黑板索引失败", zap.String("conversationId", conversationID), zap.Error(err))
|
||||
return ""
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"cyberstrike-ai/internal/config"
|
||||
"cyberstrike-ai/internal/database"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
func TestProjectBlackboardInitialInjectionUsesCurrentConversation(t *testing.T) {
|
||||
db, err := database.NewDB(filepath.Join(t.TempDir(), "injection.db"), zap.NewNop())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer db.Close()
|
||||
p, err := db.CreateProject(&database.Project{Name: "same project"})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
a, err := db.CreateConversation("a", database.ConversationCreateMeta{ProjectID: p.ID})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
b, err := db.CreateConversation("b", database.ConversationCreateMeta{ProjectID: p.ID})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, f := range []*database.ProjectFact{
|
||||
{ProjectID: p.ID, FactKey: "note/context-a", SourceConversationID: a.ID, Summary: "own continuation"},
|
||||
{ProjectID: p.ID, FactKey: "note/context-b", SourceConversationID: b.ID, Summary: "other continuation"},
|
||||
{ProjectID: p.ID, FactKey: "finding/shared", Category: "finding", Summary: "shared result", Confidence: "confirmed"},
|
||||
} {
|
||||
if _, err := db.UpsertProjectFact(f); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
h := &AgentHandler{db: db, config: &config.Config{Project: config.ProjectConfig{Enabled: true}}, logger: zap.NewNop()}
|
||||
block := h.projectBlackboardBlock(a.ID)
|
||||
if !strings.Contains(block, "note/context-a") || !strings.Contains(block, "finding/shared") || strings.Contains(block, "note/context-b") {
|
||||
t.Fatalf("initial prompt mixed sessions: %s", block)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user