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>
88 lines
3.3 KiB
SQL
88 lines
3.3 KiB
SQL
-- +goose Up
|
|
CREATE SCHEMA chat;
|
|
|
|
-- A session is one conversation between the operator and Archie.
|
|
CREATE TABLE chat.sessions (
|
|
id uuid PRIMARY KEY,
|
|
org_id text NOT NULL,
|
|
title text NOT NULL DEFAULT '',
|
|
created_at timestamptz NOT NULL DEFAULT now(),
|
|
updated_at timestamptz NOT NULL DEFAULT now()
|
|
);
|
|
|
|
CREATE INDEX sessions_by_org ON chat.sessions (org_id, updated_at DESC);
|
|
|
|
-- A turn is one message from the operator and Archie's reply to it. It is
|
|
-- stored before it is acknowledged and queued until the turn before it in the
|
|
-- same session has ended. A turn's id is the run id judgement and approvals
|
|
-- record its actions under.
|
|
CREATE TABLE chat.turns (
|
|
seq bigserial PRIMARY KEY,
|
|
id uuid NOT NULL UNIQUE,
|
|
org_id text NOT NULL,
|
|
session_id uuid NOT NULL REFERENCES chat.sessions (id) ON DELETE CASCADE,
|
|
state text NOT NULL CHECK (state IN ('queued', 'running', 'succeeded', 'failed', 'cancelled')),
|
|
text text NOT NULL,
|
|
page text NOT NULL DEFAULT '',
|
|
page_label text NOT NULL DEFAULT '',
|
|
reply text NOT NULL DEFAULT '',
|
|
reasoning text NOT NULL DEFAULT '',
|
|
error text NOT NULL DEFAULT '',
|
|
cancel boolean NOT NULL DEFAULT false,
|
|
created_at timestamptz NOT NULL DEFAULT now(),
|
|
started_at timestamptz,
|
|
finished_at timestamptz
|
|
);
|
|
|
|
CREATE INDEX turns_by_session ON chat.turns (session_id, seq);
|
|
CREATE INDEX turns_queued ON chat.turns (seq) WHERE state IN ('queued', 'running');
|
|
|
|
-- An event is one thing a turn streamed: thinking, reply text, a tool call or
|
|
-- its result, an approval asked, or how the turn ended. A reader replays them
|
|
-- after its cursor.
|
|
CREATE TABLE chat.events (
|
|
seq bigserial PRIMARY KEY,
|
|
turn_id uuid NOT NULL REFERENCES chat.turns (id) ON DELETE CASCADE,
|
|
kind text NOT NULL,
|
|
data jsonb NOT NULL,
|
|
created_at timestamptz NOT NULL DEFAULT now()
|
|
);
|
|
|
|
CREATE INDEX events_by_turn ON chat.events (turn_id, seq);
|
|
|
|
-- An action is one a turn's agent called that judgement held for approval.
|
|
-- Its answer comes back through approvals; an approved action runs once.
|
|
CREATE TABLE chat.actions (
|
|
id uuid PRIMARY KEY,
|
|
org_id text NOT NULL,
|
|
turn_id uuid NOT NULL REFERENCES chat.turns (id) ON DELETE CASCADE,
|
|
key text NOT NULL,
|
|
decision jsonb NOT NULL,
|
|
request_id uuid NOT NULL,
|
|
path jsonb NOT NULL,
|
|
step int NOT NULL DEFAULT 0,
|
|
step_due timestamptz NOT NULL,
|
|
state text NOT NULL CHECK (state IN ('waiting', 'approved', 'running', 'succeeded', 'failed', 'unknown', 'denied', 'expired')),
|
|
answer jsonb,
|
|
result text NOT NULL DEFAULT '',
|
|
created_at timestamptz NOT NULL DEFAULT now(),
|
|
UNIQUE (turn_id, key)
|
|
);
|
|
|
|
CREATE INDEX actions_open ON chat.actions (state) WHERE state IN ('waiting', 'approved', 'running');
|
|
|
|
-- A note is a fact the operator asked Archie to remember across
|
|
-- conversations.
|
|
CREATE TABLE memory.notes (
|
|
id uuid PRIMARY KEY,
|
|
org_id text NOT NULL,
|
|
text text NOT NULL,
|
|
created_at timestamptz NOT NULL DEFAULT now()
|
|
);
|
|
|
|
CREATE INDEX notes_by_org ON memory.notes (org_id, created_at);
|
|
|
|
-- +goose Down
|
|
DROP TABLE memory.notes;
|
|
DROP SCHEMA chat CASCADE;
|