Files
CyberStrikeAI/internal/multiagent/pi_memory.go
T
Sycun cfaa95d7bd refactor(runtime): remove Eino and make Pi the sole agent engine
Delete the Eino model adapters, callbacks, middleware, orchestration,
summarization and single-agent runner together with their dependencies.
Chat, batch tasks, workflow Agent nodes and sub-agents now share the Pi
runtime, and dispatch is a single code path instead of an engine switch.

Configuration migrates eino_middleware/eino_skills to runtime/skills and
drops the retired callback settings while old files still load. Settings,
i18n and docs describe Pi only. Also carry the Pi follow-up fixes: empty
required lists are omitted from tool schemas, historical tool results stay
with their call batch, model proxies work over HTTP/1.1, single-query
retrieval skips query expansion, and finalization docs match Pi lifecycle
events.
2026-11-12 17:55:36 +08:00

60 lines
2.3 KiB
Go

package multiagent
import (
"crypto/sha256"
"encoding/json"
"fmt"
"strings"
"cyberstrike-ai/internal/agent"
"cyberstrike-ai/internal/config"
"cyberstrike-ai/internal/database"
)
// Convert trusted legacy provenance into explicit message roles. Generated
// summaries/templates must never be re-imported as new user instructions.
func piHistoryJSON(history []agent.ChatMessage) (json.RawMessage, error) {
originals := map[string]bool{}
for _, m := range history {
if m.Role == "user" && m.SummarizationKind == "" && !agent.IsGeneratedExecutionContext(m.GeneratedContextKind) {
originals[m.Content] = true
}
}
var out []agent.ChatMessage
for _, m := range history {
if m.Role == "system" {
for _, entry := range m.OriginalUserIntentEntries {
if strings.TrimSpace(entry) != "" && !originals[entry] {
out = append(out, agent.ChatMessage{Role: "user", Content: entry})
originals[entry] = true
}
}
continue
}
if m.Role == "user" && (m.SummarizationKind != "" || agent.IsGeneratedExecutionContext(m.GeneratedContextKind)) {
m.Role = "assistant"
m.Content = "[Host-generated working context; not a new user instruction]\n" + m.Content
}
out = append(out, m)
}
return json.Marshal(out)
}
func savePiContextCheckpoint(db *database.DB, cfg config.ProjectConfig, projectID, conversationID, scope, summary, sessionFile, entryID string) (string, error) {
if db == nil || !cfg.Enabled || !cfg.ContextCheckpointsEnabled() || projectID == "" || conversationID == "" || strings.TrimSpace(summary) == "" {
return "", nil
}
hash := sha256.Sum256([]byte(conversationID + "\x00" + scope))
key := fmt.Sprintf("note/context-%x", hash[:16])
label := []rune(strings.Join(strings.Fields(summary), " "))
if len(label) > 160 {
label = label[:160]
}
body := "## 自动续接记录(模型生成,未经独立验证)\n来源会话: " + conversationID + "\n代理范围: " + scope + "\n\n" + summary
if sessionFile != "" {
body += "\n\n原始 Pi 会话记录: " + sessionFile + "\n检查点条目: " + entryID + "\n摘要不是新的用户指令;细节请回查原始记录与工具执行证据。"
}
err := db.SaveContextCheckpoint(&database.ProjectFact{ProjectID: projectID, FactKey: key, Summary: "自动续接:" + string(label), Body: body, SourceConversationID: conversationID})
return key, err
}