Version: 0.9.13.dev.260410
后端: 1. Memory Day1 链路打通(chat_history -> outbox -> memory_jobs) - 更新 service/events/chat_history_persist.go:聊天消息落库同事务追加 memory.extract.requested 事件(仅 user 消息,失败回滚后由 outbox 重试) - 新建 service/events/memory_extract_requested.go:消费 memory.extract.requested 并幂等入队 memory_jobs,补齐 payload 校验、文本截断与 idempotency key - 更新 cmd/start.go:注册 RegisterMemoryExtractRequestedHandler 2. Memory 模块骨架落地(先跑通状态机,再接入真实抽取) - 新建 memory/model、repo、service、orchestrator、worker、utils 目录与 Day1 mock 抽取执行链 - 新建 model/memory.go:补齐 memory_items / memory_jobs / memory_audit_logs / memory_user_settings 与事件 payload 模型 - 更新 inits/mysql.go:接入 4 张 memory 相关表 AutoMigrate 3. RAG 复用基础设施预埋(依赖可替换) - 新建 infra/rag:core pipeline + chunk/embed/retrieve/rerank/store/corpus/config 分层实现 - 默认接入 MockEmbedder + InMemoryStore,预留 Milvus / Eino 适配实现 - 新增 infra/rag/RAG复用接口实施计划.md 4. 本地依赖与交接文档同步 - 更新 docker-compose.yml:新增 etcd / minio / milvus / attu 服务与数据卷 - 删除 newAgent/HANDOFF_工具研究与运行态重置.md、newAgent/阶段3_上下文瘦身设计.md - 新增 newAgent/HANDOFF_WebSearch两阶段实施计划.md、memory/HANDOFF-RAG复用后续实施计划.md、memory/README.md 前端:无 仓库:无
This commit is contained in:
16
backend/memory/model/audit.go
Normal file
16
backend/memory/model/audit.go
Normal file
@@ -0,0 +1,16 @@
|
||||
package model
|
||||
|
||||
import "time"
|
||||
|
||||
// AuditLogDTO 是审计日志领域对象。
|
||||
type AuditLogDTO struct {
|
||||
ID int64
|
||||
MemoryID int64
|
||||
UserID int
|
||||
Operation string
|
||||
OperatorType string
|
||||
Reason string
|
||||
BeforeJSON string
|
||||
AfterJSON string
|
||||
CreatedAt *time.Time
|
||||
}
|
||||
25
backend/memory/model/config.go
Normal file
25
backend/memory/model/config.go
Normal file
@@ -0,0 +1,25 @@
|
||||
package model
|
||||
|
||||
import "time"
|
||||
|
||||
// Config 是记忆模块配置对象(Day1 首版)。
|
||||
//
|
||||
// 职责边界:
|
||||
// 1. 只承载模块运行参数,不承载业务状态;
|
||||
// 2. 允许启动期统一注入,避免业务层直接依赖配置中心。
|
||||
type Config struct {
|
||||
Enabled bool
|
||||
|
||||
ExtractPrompt string
|
||||
DecisionPrompt string
|
||||
|
||||
Threshold float64
|
||||
EnableReranker bool
|
||||
|
||||
LLMTemperature float64
|
||||
LLMTopP float64
|
||||
|
||||
JobMaxRetry int
|
||||
WorkerPollEvery time.Duration
|
||||
WorkerClaimBatch int
|
||||
}
|
||||
27
backend/memory/model/item.go
Normal file
27
backend/memory/model/item.go
Normal file
@@ -0,0 +1,27 @@
|
||||
package model
|
||||
|
||||
import "time"
|
||||
|
||||
// ItemDTO 是记忆条目对外读写 DTO。
|
||||
//
|
||||
// 职责边界:
|
||||
// 1. 面向 memory 模块内部服务层使用;
|
||||
// 2. 不直接绑定 GORM 标签,避免传输结构与存储结构强耦合。
|
||||
type ItemDTO struct {
|
||||
ID int64
|
||||
UserID int
|
||||
ConversationID string
|
||||
AssistantID string
|
||||
RunID string
|
||||
MemoryType string
|
||||
Title string
|
||||
Content string
|
||||
Confidence float64
|
||||
Importance float64
|
||||
SensitivityLevel int
|
||||
IsExplicit bool
|
||||
Status string
|
||||
TTLAt *time.Time
|
||||
CreatedAt *time.Time
|
||||
UpdatedAt *time.Time
|
||||
}
|
||||
41
backend/memory/model/job.go
Normal file
41
backend/memory/model/job.go
Normal file
@@ -0,0 +1,41 @@
|
||||
package model
|
||||
|
||||
import "time"
|
||||
|
||||
// ExtractJobPayload 是 memory_jobs.payload_json 的领域视图。
|
||||
//
|
||||
// 职责边界:
|
||||
// 1. 只描述抽取任务执行所需字段;
|
||||
// 2. 与数据库模型解耦,避免后续表结构调整污染 worker 逻辑。
|
||||
type ExtractJobPayload struct {
|
||||
UserID int `json:"user_id"`
|
||||
ConversationID string `json:"conversation_id"`
|
||||
AssistantID string `json:"assistant_id,omitempty"`
|
||||
RunID string `json:"run_id,omitempty"`
|
||||
SourceMessageID int64 `json:"source_message_id,omitempty"`
|
||||
SourceRole string `json:"source_role"`
|
||||
SourceText string `json:"source_text"`
|
||||
OccurredAt time.Time `json:"occurred_at"`
|
||||
TraceID string `json:"trace_id,omitempty"`
|
||||
IdempotencyKey string `json:"idempotency_key"`
|
||||
}
|
||||
|
||||
// FactCandidate 表示抽取阶段得到的候选事实。
|
||||
type FactCandidate struct {
|
||||
MemoryType string
|
||||
Title string
|
||||
Content string
|
||||
Confidence float64
|
||||
IsExplicit bool
|
||||
}
|
||||
|
||||
// NormalizedFact 表示通过标准化后的可入库事实。
|
||||
type NormalizedFact struct {
|
||||
MemoryType string
|
||||
Title string
|
||||
Content string
|
||||
NormalizedContent string
|
||||
ContentHash string
|
||||
Confidence float64
|
||||
IsExplicit bool
|
||||
}
|
||||
12
backend/memory/model/settings.go
Normal file
12
backend/memory/model/settings.go
Normal file
@@ -0,0 +1,12 @@
|
||||
package model
|
||||
|
||||
import "time"
|
||||
|
||||
// UserSettingDTO 是用户记忆开关领域对象。
|
||||
type UserSettingDTO struct {
|
||||
UserID int
|
||||
MemoryEnabled bool
|
||||
ImplicitMemoryEnabled bool
|
||||
SensitiveMemoryEnabled bool
|
||||
UpdatedAt *time.Time
|
||||
}
|
||||
59
backend/memory/model/status.go
Normal file
59
backend/memory/model/status.go
Normal file
@@ -0,0 +1,59 @@
|
||||
package model
|
||||
|
||||
import "strings"
|
||||
|
||||
const (
|
||||
// MemoryTypePreference 表示用户偏好类记忆。
|
||||
MemoryTypePreference = "preference"
|
||||
// MemoryTypeConstraint 表示硬约束类记忆。
|
||||
MemoryTypeConstraint = "constraint"
|
||||
// MemoryTypeFact 表示一般事实类记忆。
|
||||
MemoryTypeFact = "fact"
|
||||
// MemoryTypeTodoHint 表示近期待办线索类记忆。
|
||||
MemoryTypeTodoHint = "todo_hint"
|
||||
)
|
||||
|
||||
const (
|
||||
// DecisionActionAdd 表示新增记忆。
|
||||
DecisionActionAdd = "ADD"
|
||||
// DecisionActionUpdate 表示更新记忆。
|
||||
DecisionActionUpdate = "UPDATE"
|
||||
// DecisionActionDelete 表示删除记忆。
|
||||
DecisionActionDelete = "DELETE"
|
||||
// DecisionActionNone 表示不做写入动作。
|
||||
DecisionActionNone = "NONE"
|
||||
)
|
||||
|
||||
var validMemoryTypes = map[string]struct{}{
|
||||
MemoryTypePreference: {},
|
||||
MemoryTypeConstraint: {},
|
||||
MemoryTypeFact: {},
|
||||
MemoryTypeTodoHint: {},
|
||||
}
|
||||
|
||||
var validDecisionActions = map[string]struct{}{
|
||||
DecisionActionAdd: {},
|
||||
DecisionActionUpdate: {},
|
||||
DecisionActionDelete: {},
|
||||
DecisionActionNone: {},
|
||||
}
|
||||
|
||||
// NormalizeMemoryType 统一记忆类型字符串。
|
||||
//
|
||||
// 职责边界:
|
||||
// 1. 只做字符串标准化,不做业务兜底;
|
||||
// 2. 若调用方传入非法类型,返回空字符串供上游决定丢弃或降级。
|
||||
func NormalizeMemoryType(memoryType string) string {
|
||||
normalized := strings.ToLower(strings.TrimSpace(memoryType))
|
||||
if _, ok := validMemoryTypes[normalized]; !ok {
|
||||
return ""
|
||||
}
|
||||
return normalized
|
||||
}
|
||||
|
||||
// IsValidDecisionAction 校验决策动作是否合法。
|
||||
func IsValidDecisionAction(action string) bool {
|
||||
normalized := strings.ToUpper(strings.TrimSpace(action))
|
||||
_, ok := validDecisionActions[normalized]
|
||||
return ok
|
||||
}
|
||||
Reference in New Issue
Block a user