feat(chat): add the chat module to the archie binary (#2018)

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>
This commit is contained in:
samandCopilot committed 2026-11-19 19:40:44 +11:00
1 parent a0d14090ef
commit cbfcd43018
21 files changed
+2863 -8

No files matched your search

+46
View File
@@ -0,0 +1,46 @@
package store
import (
"context"
"fmt"
"time"
"github.com/google/uuid"
)
// Note is one remembered fact.
type Note struct {
ID uuid.UUID `db:"id"`
Text string `db:"text"`
CreatedAt time.Time `db:"created_at"`
}
// AddNote stores a fact.
func (s *Store) AddNote(ctx context.Context, orgID string, n Note) error {
if _, err := s.db.ExecContext(ctx, `
INSERT INTO memory.notes (id, org_id, text) VALUES ($1, $2, $3)`, n.ID, orgID, n.Text); err != nil {
return fmt.Errorf("remember note: %w", err)
}
return nil
}
// Notes returns the remembered facts, oldest first.
func (s *Store) Notes(ctx context.Context, orgID string, limit int) ([]Note, error) {
var out []Note
if err := s.db.SelectContext(ctx, &out, `
SELECT id, text, created_at FROM memory.notes WHERE org_id = $1
ORDER BY created_at LIMIT $2`, orgID, limit); err != nil {
return nil, fmt.Errorf("list notes: %w", err)
}
return out, nil
}
// DeleteNote forgets a fact and reports whether it existed.
func (s *Store) DeleteNote(ctx context.Context, orgID string, id uuid.UUID) (bool, error) {
res, err := s.db.ExecContext(ctx, `DELETE FROM memory.notes WHERE org_id = $1 AND id = $2`, orgID, id)
if err != nil {
return false, fmt.Errorf("forget note: %w", err)
}
n, err := res.RowsAffected()
return n > 0, err
}
+3 -1
View File
@@ -89,11 +89,13 @@ type ledger interface {
type Module struct {
orgID string
ledger ledger
notes noteStore
}
// NewModule returns the memory module for orgID.
func NewModule(db *sqlx.DB, orgID string) *Module {
return &Module{orgID: orgID, ledger: store.New(db)}
s := store.New(db)
return &Module{orgID: orgID, ledger: s, notes: s}
}
var unsafeCause = regexp.MustCompile(`[^a-z0-9]+`)
+60
View File
@@ -0,0 +1,60 @@
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)
}