feat(agent): 经验记忆 - 按任务相关度排序召回,并过期清理待批准记忆
召回按主题、情境和中文双字命中加权;30天未处理的待批准记忆会在记录和压缩调度时过期,成功计数写入运行态以免事件窗口截断后误拦。
This commit is contained in:
@@ -125,6 +125,28 @@ func (r *Repository) CountAgentLessonsByAuthor(userID, status string) (int64, er
|
||||
return count, err
|
||||
}
|
||||
|
||||
func (r *Repository) ExpirePendingAgentLessons(userID string, createdBefore, updatedAt time.Time, limit int) (int64, error) {
|
||||
if limit <= 0 || limit > 1000 {
|
||||
limit = 500
|
||||
}
|
||||
query := r.db.Model(&model.AgentLesson{}).Select("id").
|
||||
Where("status = ? AND created_at <= ?", model.AgentLessonStatusPending, createdBefore)
|
||||
if userID = strings.TrimSpace(userID); userID != "" {
|
||||
query = query.Where("author_user_id = ?", userID)
|
||||
}
|
||||
var ids []string
|
||||
if err := query.Order("created_at ASC").Limit(limit).Pluck("id", &ids).Error; err != nil {
|
||||
return 0, err
|
||||
}
|
||||
if len(ids) == 0 {
|
||||
return 0, nil
|
||||
}
|
||||
update := r.db.Model(&model.AgentLesson{}).
|
||||
Where("id IN ? AND status = ?", ids, model.AgentLessonStatusPending).
|
||||
Updates(map[string]any{"status": model.AgentLessonStatusRejected, "updated_at": updatedAt})
|
||||
return update.RowsAffected, update.Error
|
||||
}
|
||||
|
||||
func (r *Repository) AdminAgentLessons(status, userID, keyword string, limit int) ([]model.AgentLesson, error) {
|
||||
query := r.db.Model(&model.AgentLesson{})
|
||||
if trimmed := strings.TrimSpace(status); trimmed != "" {
|
||||
|
||||
Reference in New Issue
Block a user