feat(runtime): sync experience bus and learner stack into main

This commit is contained in:
Apple
2026-03-05 11:30:17 -08:00
parent edd0427c61
commit ef6ebe3583
22 changed files with 2837 additions and 22 deletions

View File

@@ -0,0 +1,38 @@
-- Phase-1: Router Experience Bus event store (append-only)
CREATE TABLE IF NOT EXISTS agent_experience_events (
id BIGSERIAL PRIMARY KEY,
event_id UUID NOT NULL UNIQUE,
ts TIMESTAMPTZ NOT NULL,
node_id TEXT NOT NULL,
source TEXT NOT NULL,
agent_id TEXT NOT NULL,
task_type TEXT NOT NULL,
request_id TEXT NULL,
channel TEXT NOT NULL DEFAULT 'unknown',
inputs_hash TEXT NOT NULL,
provider TEXT NOT NULL,
model TEXT NOT NULL,
profile TEXT NULL,
latency_ms INT NOT NULL,
tokens_in INT NULL,
tokens_out INT NULL,
ok BOOLEAN NOT NULL,
error_class TEXT NULL,
error_msg_redacted TEXT NULL,
http_status INT NOT NULL,
raw JSONB NOT NULL,
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
);
CREATE INDEX IF NOT EXISTS idx_agent_experience_events_agent_ts
ON agent_experience_events (agent_id, ts DESC);
CREATE INDEX IF NOT EXISTS idx_agent_experience_events_task_ts
ON agent_experience_events (task_type, ts DESC);
CREATE INDEX IF NOT EXISTS idx_agent_experience_events_hash_ts
ON agent_experience_events (inputs_hash, ts DESC);
CREATE INDEX IF NOT EXISTS idx_agent_experience_events_ok_ts
ON agent_experience_events (ok, ts DESC);

View File

@@ -0,0 +1,27 @@
-- Phase-2: Experience Learner lessons store (append-only)
CREATE TABLE IF NOT EXISTS agent_lessons (
id BIGSERIAL PRIMARY KEY,
lesson_id UUID NOT NULL UNIQUE,
lesson_key TEXT NOT NULL UNIQUE,
ts TIMESTAMPTZ NOT NULL,
scope TEXT NOT NULL,
agent_id TEXT NULL,
task_type TEXT NOT NULL,
trigger TEXT NOT NULL,
action TEXT NOT NULL,
avoid TEXT NOT NULL,
signals JSONB NOT NULL,
evidence JSONB NOT NULL,
raw JSONB NOT NULL,
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
);
CREATE INDEX IF NOT EXISTS idx_agent_lessons_scope_ts
ON agent_lessons (scope, ts DESC);
CREATE INDEX IF NOT EXISTS idx_agent_lessons_agent_ts
ON agent_lessons (agent_id, ts DESC);
CREATE INDEX IF NOT EXISTS idx_agent_lessons_task_ts
ON agent_lessons (task_type, ts DESC);