Closes archie-core-1786637499114 (persistent session-memory curator), the last open item in the curator engine epic. docs/prds/session-memory-curator.md records the decisions this needed before coding, most notably: Observation.Identity is the session ID, not a user or cross-session identity. migration-decisions.md#5's memory-scope mapping (global/agent-wide/user-wide/agent-user relationship) is still explicitly open, and this issue has no business deciding it unilaterally -- session-as-identity is the narrowest unambiguous scope available today and is forward-compatible with a later, properly-decided identity resolution. curator gains ConversationSource (RecentSessions/Messages), gated in Registry.validateDeclared/filter exactly like Skills/MemoryEngines, plus Manifest.Conversations. internal/infrastructure/sessioncurator/adapter.go adapts gateway.SessionStore's full CRUD/branch/search surface down to those two read-only methods -- curator must not import gateway.Message, so role derivation (message.From == botUser -> assistant) is copied from gateway.compressTurnHistory's existing logic, not shared. sessioncurator.go: Check is a cheap RecentSessions bool. Pass takes each session's last 40 messages, asks the model for a JSON array of durable facts (capped at 5/session), and writes each through Registrar.MemoryEngines.Get(name) -- resolved by name at call time, the same trust model every other curator capability already uses. A response that fails to parse degrades to "nothing extracted" for that session (not a Pass error); a real model-call failure propagates as one (these were originally conflated into the same swallowed-error path -- caught by TestPassPropagatesALLMFailure, fixed by splitting the model call from the parse step). PassInput.Since zero resolves to a 24h lookback, not the beginning of time, so a cold-start first pass can't read a session's entire history. Manifest.OnInput = true wakes it via the existing WakeOnPrimaryInput wiring (events.KindTurnCompleted), which already excludes every curator-derived event kind from the forwarded set -- the trigger- accounting invariant (archie-core-1786637489768) needed no new code to hold here. Wired into bootstrap.go:setupCurators via a new curatorLLMRunner adapter (main.go) over the shared ai-sdk runtime, and sessioncurator.NewAdapter over b.chatSessionStore/b.cfg.BotUser. Model resolves from b.chatModels.ActiveModel() -- not b.defaultChatIdentity, which names a task-routing identity, not a model reference (the same source telegram_setup.go's sendChatTurn already uses for a real chat turn). task check is green (full Go suite + dashboard tests).
64 lines
2.1 KiB
Go
64 lines
2.1 KiB
Go
// Package sessioncurator implements domain/curator.CuratorEngine for
|
|
// session memory extraction. See docs/prds/session-memory-curator.md for
|
|
// what a pass does and why, and the scope this package deliberately does
|
|
// not cover.
|
|
package sessioncurator
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"time"
|
|
|
|
"github.com/samcharles93/archie-core/internal/domain/curator"
|
|
"github.com/samcharles93/archie-core/internal/gateway"
|
|
)
|
|
|
|
// Adapter implements curator.ConversationSource over a real
|
|
// gateway.SessionStore, narrowed to the two read-only operations a
|
|
// curator needs -- never the full session CRUD/branch/search surface a
|
|
// chat gateway exposes. See docs/prds/session-memory-curator.md.
|
|
type Adapter struct {
|
|
store gateway.SessionStore
|
|
botUser string
|
|
}
|
|
|
|
// NewAdapter builds an Adapter. botUser is compared against
|
|
// gateway.Message.From to derive role ("assistant" when it matches, else
|
|
// "user"), the same derivation gateway.compressTurnHistory already uses
|
|
// -- copied logic, not shared code, since curator must not import
|
|
// gateway.Message.
|
|
func NewAdapter(store gateway.SessionStore, botUser string) *Adapter {
|
|
return &Adapter{store: store, botUser: botUser}
|
|
}
|
|
|
|
func (a *Adapter) RecentSessions(ctx context.Context, since time.Time) ([]curator.SessionSummary, error) {
|
|
sessions, err := a.store.List(ctx)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("sessioncurator: listing sessions: %w", err)
|
|
}
|
|
var out []curator.SessionSummary
|
|
for _, s := range sessions {
|
|
if s.LastActiveAt.Before(since) {
|
|
continue
|
|
}
|
|
out = append(out, curator.SessionSummary{ID: s.SessionID, LastActive: s.LastActiveAt})
|
|
}
|
|
return out, nil
|
|
}
|
|
|
|
func (a *Adapter) Messages(ctx context.Context, sessionID string, n int) ([]curator.ConversationMessage, error) {
|
|
msgs, err := a.store.RecentMessages(ctx, sessionID, n)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("sessioncurator: reading session %s: %w", sessionID, err)
|
|
}
|
|
out := make([]curator.ConversationMessage, 0, len(msgs))
|
|
for _, m := range msgs {
|
|
role := "user"
|
|
if m.From == a.botUser {
|
|
role = "assistant"
|
|
}
|
|
out = append(out, curator.ConversationMessage{Role: role, Content: m.Text, At: m.At})
|
|
}
|
|
return out, nil
|
|
}
|