Conversations are the chat module's own tables. A turn is stored before it is acknowledged, runs after the turns before it in its session, and records everything it streams, so a reader replays it from a cursor. The agent uses the configured agent model, the same connector tools as a run and the dashboard's own reads; every action is judged, and one judgement holds is put to people through approvals and run once when approved. A restart fails the turns it interrupted visibly and never restarts a started action. Conversation memory is a set of notes in the memory module. The chat prompts are copied from internal/prompts (chat-system.tmpl, soul.md, session-title.md) into internal/platform/prompts while the gateway still reads them; the tool parameter redaction is copied from internal/domain/messaging/tool_parameters.go. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
61 lines
1.6 KiB
Go
61 lines
1.6 KiB
Go
package memory
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"strings"
|
|
"time"
|
|
|
|
"github.com/google/uuid"
|
|
|
|
"github.com/samcharles93/archie-core/modules/memory/internal/store"
|
|
)
|
|
|
|
// maxNotes bounds the facts a conversation is given, so memory can't crowd
|
|
// out the conversation itself.
|
|
const maxNotes = 200
|
|
|
|
// Note is a fact the operator asked Archie to remember across conversations.
|
|
type Note struct {
|
|
ID uuid.UUID `json:"id"`
|
|
Text string `json:"text"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
}
|
|
|
|
type noteStore interface {
|
|
AddNote(ctx context.Context, orgID string, n store.Note) error
|
|
Notes(ctx context.Context, orgID string, limit int) ([]store.Note, error)
|
|
DeleteNote(ctx context.Context, orgID string, id uuid.UUID) (bool, error)
|
|
}
|
|
|
|
// Remember stores a fact and returns it.
|
|
func (m *Module) Remember(ctx context.Context, text string) (Note, error) {
|
|
text = strings.TrimSpace(text)
|
|
if text == "" {
|
|
return Note{}, errors.New("a note needs text")
|
|
}
|
|
n := store.Note{ID: uuid.New(), Text: text, CreatedAt: time.Now().UTC()}
|
|
if err := m.notes.AddNote(ctx, m.orgID, n); err != nil {
|
|
return Note{}, err
|
|
}
|
|
return Note(n), nil
|
|
}
|
|
|
|
// Notes returns the remembered facts, oldest first.
|
|
func (m *Module) Notes(ctx context.Context) ([]Note, error) {
|
|
rows, err := m.notes.Notes(ctx, m.orgID, maxNotes)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
out := make([]Note, 0, len(rows))
|
|
for _, r := range rows {
|
|
out = append(out, Note(r))
|
|
}
|
|
return out, nil
|
|
}
|
|
|
|
// Forget removes a fact and reports whether there was one.
|
|
func (m *Module) Forget(ctx context.Context, id uuid.UUID) (bool, error) {
|
|
return m.notes.DeleteNote(ctx, m.orgID, id)
|
|
}
|