Files
vibn-agent-runner/vibn-frontend/lib/db/agent-telemetry-schema.sql

33 lines
1.3 KiB
SQL

-- =====================================================================
-- agent_telemetry table: stores full AI turn telemetry for diagnostics
-- and as training data for fine-tuning.
-- =====================================================================
--
-- Each row captures one model turn: the exact context the model saw
-- (system prompt + chat history) and the exact output it produced
-- (text, thoughts, tool calls), plus token/latency metrics.
--
-- JSONB columns let you export clean fine-tuning datasets later, e.g.
-- SELECT input_context, target_output FROM agent_telemetry;
CREATE TABLE IF NOT EXISTS agent_telemetry (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
project_id VARCHAR(255),
model_used VARCHAR(255) NOT NULL,
system_prompt TEXT NOT NULL,
chat_history JSONB NOT NULL,
response_text TEXT,
response_thoughts TEXT,
tool_calls JSONB,
prompt_tokens INTEGER,
completion_tokens INTEGER,
total_tokens INTEGER,
duration_ms INTEGER NOT NULL
);
-- Index for fast querying by project
CREATE INDEX IF NOT EXISTS idx_agent_telemetry_project ON agent_telemetry(project_id);
-- Index for chronological sorting
CREATE INDEX IF NOT EXISTS idx_agent_telemetry_created_at ON agent_telemetry(created_at DESC);