feat(ai-core): trace instrumentation, LLM thinker, decay scheduler
- orchestrator: Tracer interface with spans for intent analysis, persona, subsession dispatch, context build, LLM streaming and each tool call; traces finish when the stream completes — the admin Trace waterfall finally receives data - background: Thinker generates real LLM thoughts (post-chat + silence triggers, recent history as context, empty/overlong outputs discarded); thoughts broadcast to web clients as 'thinking' WS messages; pipeline postChatHook triggers post-chat thinking after each round - memory: ApplyDecayAll + ListUserIDs with a 6h decay/purge cron in main (was implemented but never scheduled)
This commit is contained in:
1 parent
8495a4b055
commit
8603839711
8 files changed
+338
-10
No files matched your search
@@ -221,6 +221,24 @@ func (r *Repository) RecordAccess(ctx context.Context, id string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
// ListUserIDs returns distinct user IDs that have memories.
|
||||
func (r *Repository) ListUserIDs(ctx context.Context) ([]string, error) {
|
||||
rows, err := r.db.QueryContext(ctx, `SELECT DISTINCT user_id FROM memories`)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("list user ids: %w", err)
|
||||
}
|
||||
defer rows.Close()
|
||||
var ids []string
|
||||
for rows.Next() {
|
||||
var id string
|
||||
if err := rows.Scan(&id); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
ids = append(ids, id)
|
||||
}
|
||||
return ids, rows.Err()
|
||||
}
|
||||
|
||||
// PurgeDecayed removes memories below the decay threshold.
|
||||
func (r *Repository) PurgeDecayed(ctx context.Context, userID string) (int64, error) {
|
||||
result, err := r.db.ExecContext(ctx,
|
||||
|
||||
@@ -161,6 +161,23 @@ func (s *Service) ApplyDecay(ctx context.Context, userID string) (int, error) {
|
||||
return updated, nil
|
||||
}
|
||||
|
||||
// ApplyDecayAll applies decay for every user that has memories.
|
||||
func (s *Service) ApplyDecayAll(ctx context.Context) (int, error) {
|
||||
users, err := s.repo.ListUserIDs(ctx)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
total := 0
|
||||
for _, uid := range users {
|
||||
n, err := s.ApplyDecay(ctx, uid)
|
||||
if err != nil {
|
||||
return total, err
|
||||
}
|
||||
total += n
|
||||
}
|
||||
return total, nil
|
||||
}
|
||||
|
||||
// --- Keyword extraction (sliding window n-grams) ---
|
||||
|
||||
// extractNGrams extracts all n-gram substrings from text.
|
||||
|
||||
Reference in new issue
Block a user