🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
✨ feat(database): add LobeBench environments and isolated Memory storage (#22157)
Robin Zhang6d5b54b57a13
diff --git a/docs/development/database-schema.dbml b/docs/development/database-schema.dbmlindex 04ac7def035..cb541777837 100644--- a/docs/development/database-schema.dbml+++ b/docs/development/database-schema.dbml@@ -300,6 +300,42 @@ table agent_documents {}}+table agent_eval_memories {+ id uuid [pk, not null, default: `gen_random_uuid()`]+ user_id text [not null]+ workspace_id text+ run_id text [not null]+ topic_id text+ thread_id text+ attempt_id text [not null]+ layer text [not null]+ source text [not null]+ fixture_hash text+ title text+ summary text+ details text+ memory_category text+ memory_type text+ tags jsonb+ payload jsonb [not null]+ embedding vector(1024)+ captured_at "timestamp with time zone" [not null]+ removed_reason text+ metadata jsonb+ accessed_at "timestamp with time zone" [not null, default: `now()`]+ created_at "timestamp with time zone" [not null, default: `now()`]+ updated_at "timestamp with time zone" [not null, default: `now()`]++ indexes {+ attempt_id [name: 'agent_eval_memories_attempt_id_idx']+ run_id [name: 'agent_eval_memories_run_id_idx']+ topic_id [name: 'agent_eval_memories_topic_id_idx']+ thread_id [name: 'agent_eval_memories_thread_id_idx']+ user_id [name: 'agent_eval_memories_user_id_idx']+ workspace_id [name: 'agent_eval_memories_workspace_id_idx']+ }+}+table agent_eval_benchmarks {id text [pk, not null]identifier text [not null]@@ -350,6 +386,27 @@ table agent_eval_datasets {}}+table agent_eval_environments {+ id uuid [pk, not null, default: `gen_random_uuid()`]+ user_id text+ workspace_id text+ identifier text+ name text [not null]+ description text+ config jsonb [not null]+ metadata jsonb+ accessed_at "timestamp with time zone" [not null, default: `now()`]+ created_at "timestamp with time zone" [not null, default: `now()`]+ updated_at "timestamp with time zone" [not null, default: `now()`]++ indexes {+ user_id [name: 'agent_eval_environments_user_id_idx']+ workspace_id [name: 'agent_eval_environments_workspace_id_idx']+ (identifier, user_id) [name: 'agent_eval_environments_identifier_user_id_unique', unique]+ (identifier, workspace_id) [name: 'agent_eval_environments_identifier_workspace_id_unique', unique]+ }+}+table agent_eval_experiment_benchmarks {experiment_id text [not null]benchmark_id text [not null]@@ -434,9 +491,10 @@ table agent_eval_runs {table agent_eval_test_cases {id text [pk, not null]- user_id text [not null]+ user_id textworkspace_id textdataset_id text [not null]+ environment_id uuidcontent jsonb [not null]eval_mode texteval_config jsonb@@ -449,6 +507,7 @@ table agent_eval_test_cases {indexes {user_id [name: 'agent_eval_test_cases_user_id_idx']dataset_id [name: 'agent_eval_test_cases_dataset_id_idx']+ environment_id [name: 'agent_eval_test_cases_environment_id_idx']sort_order [name: 'agent_eval_test_cases_sort_order_idx']workspace_id [name: 'agent_eval_test_cases_workspace_id_idx']}diff --git a/packages/database/migrations/0205_lobe_bench_environments_and_memory.sql b/packages/database/migrations/0205_lobe_bench_environments_and_memory.sqlnew file mode 100644index 00000000000..ce3b226865c--- /dev/null+++ b/packages/database/migrations/0205_lobe_bench_environments_and_memory.sql@@ -0,0 +1,98 @@+CREATE TABLE IF NOT EXISTS "agent_eval_memories" (+ "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,+ "user_id" text NOT NULL,+ "workspace_id" text,+ "run_id" text NOT NULL,+ "topic_id" text,+ "thread_id" text,+ "attempt_id" text NOT NULL,+ "layer" text NOT NULL,+ "source" text NOT NULL,+ "fixture_hash" text,+ "title" text,+ "summary" text,+ "details" text,+ "memory_category" text,+ "memory_type" text,+ "tags" jsonb,+ "payload" jsonb NOT NULL,+ "embedding" vector(1024),+ "captured_at" timestamp with time zone NOT NULL,+ "removed_reason" text,+ "metadata" jsonb,+ "accessed_at" timestamp with time zone DEFAULT now() NOT NULL,+ "created_at" timestamp with time zone DEFAULT now() NOT NULL,+ "updated_at" timestamp with time zone DEFAULT now() NOT NULL+);+--> statement-breakpoint+CREATE TABLE IF NOT EXISTS "agent_eval_environments" (+ "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,+ "user_id" text,+ "workspace_id" text,+ "identifier" text,+ "name" text NOT NULL,+ "description" text,+ "config" jsonb NOT NULL,+ "metadata" jsonb,+ "accessed_at" timestamp with time zone DEFAULT now() NOT NULL,+ "created_at" timestamp with time zone DEFAULT now() NOT NULL,+ "updated_at" timestamp with time zone DEFAULT now() NOT NULL+);+--> statement-breakpoint+ALTER TABLE "agent_eval_test_cases" ALTER COLUMN "user_id" DROP NOT NULL;--> statement-breakpoint+ALTER TABLE "agent_eval_test_cases" ADD COLUMN IF NOT EXISTS "environment_id" uuid;--> statement-breakpoint+ALTER TABLE "agent_eval_memories" DROP CONSTRAINT IF EXISTS "agent_eval_memories_user_id_users_id_fk";--> statement-breakpoint+ALTER TABLE "agent_eval_memories" ADD CONSTRAINT "agent_eval_memories_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint+ALTER TABLE "agent_eval_memories" DROP CONSTRAINT IF EXISTS "agent_eval_memories_workspace_id_workspaces_id_fk";--> statement-breakpoint+ALTER TABLE "agent_eval_memories" ADD CONSTRAINT "agent_eval_memories_workspace_id_workspaces_id_fk" FOREIGN KEY ("workspace_id") REFERENCES "public"."workspaces"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint+ALTER TABLE "agent_eval_memories" DROP CONSTRAINT IF EXISTS "agent_eval_memories_run_id_agent_eval_runs_id_fk";--> statement-breakpoint+ALTER TABLE "agent_eval_memories" ADD CONSTRAINT "agent_eval_memories_run_id_agent_eval_runs_id_fk" FOREIGN KEY ("run_id") REFERENCES "public"."agent_eval_runs"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint+ALTER TABLE "agent_eval_memories" DROP CONSTRAINT IF EXISTS "agent_eval_memories_topic_id_topics_id_fk";--> statement-breakpoint+ALTER TABLE "agent_eval_memories" ADD CONSTRAINT "agent_eval_memories_topic_id_topics_id_fk" FOREIGN KEY ("topic_id") REFERENCES "public"."topics"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint+ALTER TABLE "agent_eval_memories" DROP CONSTRAINT IF EXISTS "agent_eval_memories_thread_id_threads_id_fk";--> statement-breakpoint+ALTER TABLE "agent_eval_memories" ADD CONSTRAINT "agent_eval_memories_thread_id_threads_id_fk" FOREIGN KEY ("thread_id") REFERENCES "public"."threads"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint+ALTER TABLE "agent_eval_environments" DROP CONSTRAINT IF EXISTS "agent_eval_environments_user_id_users_id_fk";--> statement-breakpoint+ALTER TABLE "agent_eval_environments" ADD CONSTRAINT "agent_eval_environments_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint+ALTER TABLE "agent_eval_environments" DROP CONSTRAINT IF EXISTS "agent_eval_environments_workspace_id_workspaces_id_fk";--> statement-breakpoint+ALTER TABLE "agent_eval_environments" ADD CONSTRAINT "agent_eval_environments_workspace_id_workspaces_id_fk" FOREIGN KEY ("workspace_id") REFERENCES "public"."workspaces"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint+CREATE INDEX IF NOT EXISTS "agent_eval_memories_attempt_id_idx" ON "agent_eval_memories" USING btree ("attempt_id");--> statement-breakpoint+CREATE INDEX IF NOT EXISTS "agent_eval_memories_run_id_idx" ON "agent_eval_memories" USING btree ("run_id");--> statement-breakpoint+CREATE INDEX IF NOT EXISTS "agent_eval_memories_topic_id_idx" ON "agent_eval_memories" USING btree ("topic_id");--> statement-breakpoint+CREATE INDEX IF NOT EXISTS "agent_eval_memories_thread_id_idx" ON "agent_eval_memories" USING btree ("thread_id");--> statement-breakpoint+CREATE INDEX IF NOT EXISTS "agent_eval_memories_user_id_idx" ON "agent_eval_memories" USING btree ("user_id");--> statement-breakpoint+CREATE INDEX IF NOT EXISTS "agent_eval_memories_workspace_id_idx" ON "agent_eval_memories" USING btree ("workspace_id");--> statement-breakpoint+CREATE INDEX IF NOT EXISTS "agent_eval_environments_user_id_idx" ON "agent_eval_environments" USING btree ("user_id");--> statement-breakpoint+CREATE INDEX IF NOT EXISTS "agent_eval_environments_workspace_id_idx" ON "agent_eval_environments" USING btree ("workspace_id");--> statement-breakpoint+CREATE UNIQUE INDEX IF NOT EXISTS "agent_eval_environments_identifier_user_id_unique" ON "agent_eval_environments" USING btree ("identifier","user_id") WHERE "agent_eval_environments"."identifier" IS NOT NULL AND "agent_eval_environments"."workspace_id" IS NULL;--> statement-breakpoint+CREATE UNIQUE INDEX IF NOT EXISTS "agent_eval_environments_identifier_workspace_id_unique" ON "agent_eval_environments" USING btree ("identifier","workspace_id") WHERE "agent_eval_environments"."identifier" IS NOT NULL AND "agent_eval_environments"."workspace_id" IS NOT NULL;--> statement-breakpoint+ALTER TABLE "agent_eval_test_cases" DROP CONSTRAINT IF EXISTS "agent_eval_test_cases_environment_id_agent_eval_environments_id_fk";--> statement-breakpoint+ALTER TABLE "agent_eval_test_cases" ADD CONSTRAINT "agent_eval_test_cases_environment_id_agent_eval_environments_id_fk" FOREIGN KEY ("environment_id") REFERENCES "public"."agent_eval_environments"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint+CREATE INDEX IF NOT EXISTS "agent_eval_test_cases_environment_id_idx" ON "agent_eval_test_cases" USING btree ("environment_id");+--> statement-breakpoint+-- The attempt Memory's lexical index. An eval attempt's Memory tool runs the account+-- Memory's search over `agent_eval_memories`: the same paradedb.match conjunction, with+-- the same tokenizer as 0093, over the headline columns and the layer fields that live+-- inside `payload`. Created only when pg_search is installed, like every BM25 index.+DO $$+BEGIN+ IF EXISTS (SELECT 1 FROM pg_extension WHERE extname = 'pg_search') THEN+ EXECUTE $bm25$+ CREATE INDEX IF NOT EXISTS agent_eval_memories_bm25_idx ON agent_eval_memories+ USING bm25 (id, title, summary, details, payload, layer, user_id, attempt_id)+ WITH (+ key_field = 'id',+ text_fields = '{+ "title": {"tokenizer": {"type": "icu", "stemmer": "English", "stopwords_language": "English"}},+ "summary": {"tokenizer": {"type": "icu", "stemmer": "English", "stopwords_language": "English"}},+ "details": {"tokenizer": {"type": "icu", "stemmer": "English", "stopwords_language": "English"}},+ "layer": {"fast": true, "tokenizer": {"type": "keyword"}},+ "user_id": {"fast": true, "tokenizer": {"type": "keyword"}},+ "attempt_id": {"fast": true, "tokenizer": {"type": "keyword"}}+ }',+ json_fields = '{+ "payload": {"tokenizer": {"type": "icu", "stemmer": "English", "stopwords_language": "English"}}+ }'+ )+ $bm25$;+ END IF;+END $$;diff --git a/packages/database/migrations/meta/0195_snapshot.json b/packages/database/migrations/meta/0205_snapshot.jsonsimilarity index 97%rename from packages/database/migrations/meta/0195_snapshot.jsonrename to packages/database/migrations/meta/0205_snapshot.jsonindex 853b37ff250..72290d57e8a 100644--- a/packages/database/migrations/meta/0195_snapshot.json+++ b/packages/database/migrations/meta/0205_snapshot.json@@ -6,9 +6,9 @@},"dialect": "postgresql","enums": {},- "id": "e3a1c4e0-5843-4258-a9a8-28636daa0ed7",+ "id": "62c4182f-5344-4639-b52c-21d0b1e61ea1","policies": {},- "prevId": "180656bc-dfba-4351-8bba-5c66cd31a299",+ "prevId": "f22d5caf-0104-4f65-9ab8-8f6823ea199e","roles": {},"schemas": {},"sequences": {@@ -2755,6 +2755,304 @@"checkConstraints": {},"isRLSEnabled": false},+ "public.agent_eval_memories": {+ "name": "agent_eval_memories",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "uuid",+ "primaryKey": true,+ "notNull": true,+ "default": "gen_random_uuid()"+ },+ "user_id": {+ "name": "user_id",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "workspace_id": {+ "name": "workspace_id",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "run_id": {+ "name": "run_id",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "topic_id": {+ "name": "topic_id",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "thread_id": {+ "name": "thread_id",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "attempt_id": {+ "name": "attempt_id",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "layer": {+ "name": "layer",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "source": {+ "name": "source",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "fixture_hash": {+ "name": "fixture_hash",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "title": {+ "name": "title",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "summary": {+ "name": "summary",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "details": {+ "name": "details",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "memory_category": {+ "name": "memory_category",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "memory_type": {+ "name": "memory_type",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "tags": {+ "name": "tags",+ "type": "jsonb",+ "primaryKey": false,+ "notNull": false+ },+ "payload": {+ "name": "payload",+ "type": "jsonb",+ "primaryKey": false,+ "notNull": true+ },+ "embedding": {+ "name": "embedding",+ "type": "vector(1024)",+ "primaryKey": false,+ "notNull": false+ },+ "captured_at": {+ "name": "captured_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true+ },+ "removed_reason": {+ "name": "removed_reason",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "metadata": {+ "name": "metadata",+ "type": "jsonb",+ "primaryKey": false,+ "notNull": false+ },+ "accessed_at": {+ "name": "accessed_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ },+ "created_at": {+ "name": "created_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ },+ "updated_at": {+ "name": "updated_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ }+ },+ "indexes": {+ "agent_eval_memories_attempt_id_idx": {+ "name": "agent_eval_memories_attempt_id_idx",+ "columns": [+ {+ "expression": "attempt_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "agent_eval_memories_run_id_idx": {+ "name": "agent_eval_memories_run_id_idx",+ "columns": [+ {+ "expression": "run_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "agent_eval_memories_topic_id_idx": {+ "name": "agent_eval_memories_topic_id_idx",+ "columns": [+ {+ "expression": "topic_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "agent_eval_memories_thread_id_idx": {+ "name": "agent_eval_memories_thread_id_idx",+ "columns": [+ {+ "expression": "thread_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "agent_eval_memories_user_id_idx": {+ "name": "agent_eval_memories_user_id_idx",+ "columns": [+ {+ "expression": "user_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "agent_eval_memories_workspace_id_idx": {+ "name": "agent_eval_memories_workspace_id_idx",+ "columns": [+ {+ "expression": "workspace_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "foreignKeys": {+ "agent_eval_memories_user_id_users_id_fk": {+ "name": "agent_eval_memories_user_id_users_id_fk",+ "tableFrom": "agent_eval_memories",+ "tableTo": "users",+ "columnsFrom": ["user_id"],+ "columnsTo": ["id"],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "agent_eval_memories_workspace_id_workspaces_id_fk": {+ "name": "agent_eval_memories_workspace_id_workspaces_id_fk",+ "tableFrom": "agent_eval_memories",+ "tableTo": "workspaces",+ "columnsFrom": ["workspace_id"],+ "columnsTo": ["id"],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "agent_eval_memories_run_id_agent_eval_runs_id_fk": {+ "name": "agent_eval_memories_run_id_agent_eval_runs_id_fk",+ "tableFrom": "agent_eval_memories",+ "tableTo": "agent_eval_runs",+ "columnsFrom": ["run_id"],+ "columnsTo": ["id"],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "agent_eval_memories_topic_id_topics_id_fk": {+ "name": "agent_eval_memories_topic_id_topics_id_fk",+ "tableFrom": "agent_eval_memories",+ "tableTo": "topics",+ "columnsFrom": ["topic_id"],+ "columnsTo": ["id"],+ "onDelete": "set null",+ "onUpdate": "no action"+ },+ "agent_eval_memories_thread_id_threads_id_fk": {+ "name": "agent_eval_memories_thread_id_threads_id_fk",+ "tableFrom": "agent_eval_memories",+ "tableTo": "threads",+ "columnsFrom": ["thread_id"],+ "columnsTo": ["id"],+ "onDelete": "set null",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },"public.agent_eval_benchmarks": {"name": "agent_eval_benchmarks","schema": "",@@ -3201,6 +3499,183 @@"checkConstraints": {},"isRLSEnabled": false},+ "public.agent_eval_environments": {+ "name": "agent_eval_environments",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "uuid",+ "primaryKey": true,+ "notNull": true,+ "default": "gen_random_uuid()"+ },+ "user_id": {+ "name": "user_id",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "workspace_id": {+ "name": "workspace_id",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "identifier": {+ "name": "identifier",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "name": {+ "name": "name",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "description": {+ "name": "description",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "config": {+ "name": "config",+ "type": "jsonb",+ "primaryKey": false,+ "notNull": true+ },+ "metadata": {+ "name": "metadata",+ "type": "jsonb",+ "primaryKey": false,+ "notNull": false+ },+ "accessed_at": {+ "name": "accessed_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ },+ "created_at": {+ "name": "created_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ },+ "updated_at": {+ "name": "updated_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ }+ },+ "indexes": {+ "agent_eval_environments_user_id_idx": {+ "name": "agent_eval_environments_user_id_idx",+ "columns": [+ {+ "expression": "user_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "agent_eval_environments_workspace_id_idx": {+ "name": "agent_eval_environments_workspace_id_idx",+ "columns": [+ {+ "expression": "workspace_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "agent_eval_environments_identifier_user_id_unique": {+ "name": "agent_eval_environments_identifier_user_id_unique",+ "columns": [+ {+ "expression": "identifier",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "user_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": true,+ "where": "\"agent_eval_environments\".\"identifier\" IS NOT NULL AND \"agent_eval_environments\".\"workspace_id\" IS NULL",+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "agent_eval_environments_identifier_workspace_id_unique": {+ "name": "agent_eval_environments_identifier_workspace_id_unique",+ "columns": [+ {+ "expression": "identifier",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "workspace_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": true,+ "where": "\"agent_eval_environments\".\"identifier\" IS NOT NULL AND \"agent_eval_environments\".\"workspace_id\" IS NOT NULL",+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "foreignKeys": {+ "agent_eval_environments_user_id_users_id_fk": {+ "name": "agent_eval_environments_user_id_users_id_fk",+ "tableFrom": "agent_eval_environments",+ "tableTo": "users",+ "columnsFrom": ["user_id"],+ "columnsTo": ["id"],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "agent_eval_environments_workspace_id_workspaces_id_fk": {+ "name": "agent_eval_environments_workspace_id_workspaces_id_fk",+ "tableFrom": "agent_eval_environments",+ "tableTo": "workspaces",+ "columnsFrom": ["workspace_id"],+ "columnsTo": ["id"],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },"public.agent_eval_experiment_benchmarks": {"name": "agent_eval_experiment_benchmarks","schema": "",@@ -3921,7 +4396,7 @@"name": "user_id","type": "text","primaryKey": false,- "notNull": true+ "notNull": false},"workspace_id": {"name": "workspace_id",@@ -3935,6 +4410,12 @@"primaryKey": false,"notNull": true},+ "environment_id": {+ "name": "environment_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": false+ },"content": {"name": "content","type": "jsonb",@@ -4018,6 +4499,21 @@"method": "btree","with": {}},+ "agent_eval_test_cases_environment_id_idx": {+ "name": "agent_eval_test_cases_environment_id_idx",+ "columns": [+ {+ "expression": "environment_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },"agent_eval_test_cases_sort_order_idx": {"name": "agent_eval_test_cases_sort_order_idx","columns": [@@ -4076,6 +4572,15 @@"columnsTo": ["id"],"onDelete": "cascade","onUpdate": "no action"+ },+ "agent_eval_test_cases_environment_id_agent_eval_environments_id_fk": {+ "name": "agent_eval_test_cases_environment_id_agent_eval_environments_id_fk",+ "tableFrom": "agent_eval_test_cases",+ "tableTo": "agent_eval_environments",+ "columnsFrom": ["environment_id"],+ "columnsTo": ["id"],+ "onDelete": "set null",+ "onUpdate": "no action"}},"compositePrimaryKeys": {},@@ -10759,13 +11264,6 @@"primaryKey": false,"notNull": true},- "delivery_key": {- "name": "delivery_key",- "type": "text",- "primaryKey": false,- "notNull": true,- "default": "'initial'"- },"status": {"name": "status","type": "text",@@ -10907,12 +11405,6 @@"isExpression": false,"asc": true,"nulls": "last"- },- {- "expression": "delivery_key",- "isExpression": false,- "asc": true,- "nulls": "last"}],"isUnique": true,@@ -12116,6 +12608,12 @@"notNull": true,"default": "'private'"},+ "config": {+ "name": "config",+ "type": "jsonb",+ "primaryKey": false,+ "notNull": false+ },"metadata": {"name": "metadata","type": "jsonb",@@ -20248,6 +20746,19 @@"primaryKey": false,"notNull": false},+ "archived_at": {+ "name": "archived_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": false+ },+ "visibility": {+ "name": "visibility",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "default": "'public'"+ },"deleted_at": {"name": "deleted_at","type": "timestamp with time zone",@@ -20306,6 +20817,33 @@"method": "btree","with": {}},+ "goals_workspace_visibility_idx": {+ "name": "goals_workspace_visibility_idx",+ "columns": [+ {+ "expression": "workspace_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "visibility",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "user_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },"goals_agent_id_idx": {"name": "goals_agent_id_idx","columns": [@@ -28976,6 +29514,12 @@"primaryKey": false,"notNull": false},+ "last_seen_at": {+ "name": "last_seen_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": false+ },"accessed_at": {"name": "accessed_at","type": "timestamp with time zone",@@ -36782,6 +37326,370 @@"checkConstraints": {},"isRLSEnabled": false},+ "public.task_label_links": {+ "name": "task_label_links",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "uuid",+ "primaryKey": true,+ "notNull": true,+ "default": "gen_random_uuid()"+ },+ "task_id": {+ "name": "task_id",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "label_id": {+ "name": "label_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": true+ },+ "user_id": {+ "name": "user_id",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "workspace_id": {+ "name": "workspace_id",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "created_at": {+ "name": "created_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ }+ },+ "indexes": {+ "task_label_links_task_id_label_id_unique": {+ "name": "task_label_links_task_id_label_id_unique",+ "columns": [+ {+ "expression": "task_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "label_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": true,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "task_label_links_label_id_idx": {+ "name": "task_label_links_label_id_idx",+ "columns": [+ {+ "expression": "label_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "task_label_links_user_id_idx": {+ "name": "task_label_links_user_id_idx",+ "columns": [+ {+ "expression": "user_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "task_label_links_workspace_id_idx": {+ "name": "task_label_links_workspace_id_idx",+ "columns": [+ {+ "expression": "workspace_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "foreignKeys": {+ "task_label_links_task_id_tasks_id_fk": {+ "name": "task_label_links_task_id_tasks_id_fk",+ "tableFrom": "task_label_links",+ "tableTo": "tasks",+ "columnsFrom": ["task_id"],+ "columnsTo": ["id"],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "task_label_links_label_id_task_labels_id_fk": {+ "name": "task_label_links_label_id_task_labels_id_fk",+ "tableFrom": "task_label_links",+ "tableTo": "task_labels",+ "columnsFrom": ["label_id"],+ "columnsTo": ["id"],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "task_label_links_user_id_users_id_fk": {+ "name": "task_label_links_user_id_users_id_fk",+ "tableFrom": "task_label_links",+ "tableTo": "users",+ "columnsFrom": ["user_id"],+ "columnsTo": ["id"],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "task_label_links_workspace_id_workspaces_id_fk": {+ "name": "task_label_links_workspace_id_workspaces_id_fk",+ "tableFrom": "task_label_links",+ "tableTo": "workspaces",+ "columnsFrom": ["workspace_id"],+ "columnsTo": ["id"],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.task_labels": {+ "name": "task_labels",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "uuid",+ "primaryKey": true,+ "notNull": true,+ "default": "gen_random_uuid()"+ },+ "user_id": {+ "name": "user_id",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "workspace_id": {+ "name": "workspace_id",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "parent_id": {+ "name": "parent_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": false+ },+ "is_group": {+ "name": "is_group",+ "type": "boolean",+ "primaryKey": false,+ "notNull": true,+ "default": false+ },+ "name": {+ "name": "name",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "description": {+ "name": "description",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "color": {+ "name": "color",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "sort_order": {+ "name": "sort_order",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "default": 0+ },+ "accessed_at": {+ "name": "accessed_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ },+ "created_at": {+ "name": "created_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ },+ "updated_at": {+ "name": "updated_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ }+ },+ "indexes": {+ "task_labels_user_id_idx": {+ "name": "task_labels_user_id_idx",+ "columns": [+ {+ "expression": "user_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "task_labels_workspace_id_idx": {+ "name": "task_labels_workspace_id_idx",+ "columns": [+ {+ "expression": "workspace_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "task_labels_parent_id_idx": {+ "name": "task_labels_parent_id_idx",+ "columns": [+ {+ "expression": "parent_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "task_labels_user_id_name_unique": {+ "name": "task_labels_user_id_name_unique",+ "columns": [+ {+ "expression": "user_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "lower(\"name\")",+ "asc": true,+ "isExpression": true,+ "nulls": "last"+ }+ ],+ "isUnique": true,+ "where": "\"task_labels\".\"workspace_id\" IS NULL",+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "task_labels_workspace_id_name_unique": {+ "name": "task_labels_workspace_id_name_unique",+ "columns": [+ {+ "expression": "workspace_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "lower(\"name\")",+ "asc": true,+ "isExpression": true,+ "nulls": "last"+ }+ ],+ "isUnique": true,+ "where": "\"task_labels\".\"workspace_id\" IS NOT NULL",+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "foreignKeys": {+ "task_labels_user_id_users_id_fk": {+ "name": "task_labels_user_id_users_id_fk",+ "tableFrom": "task_labels",+ "tableTo": "users",+ "columnsFrom": ["user_id"],+ "columnsTo": ["id"],+ "onDelete": "set null",+ "onUpdate": "no action"+ },+ "task_labels_workspace_id_workspaces_id_fk": {+ "name": "task_labels_workspace_id_workspaces_id_fk",+ "tableFrom": "task_labels",+ "tableTo": "workspaces",+ "columnsFrom": ["workspace_id"],+ "columnsTo": ["id"],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "task_labels_parent_id_task_labels_id_fk": {+ "name": "task_labels_parent_id_task_labels_id_fk",+ "tableFrom": "task_labels",+ "tableTo": "task_labels",+ "columnsFrom": ["parent_id"],+ "columnsTo": ["id"],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },"public.threads": {"name": "threads","schema": "",@@ -37961,6 +38869,305 @@"checkConstraints": {},"isRLSEnabled": false},+ "public.topic_analyses": {+ "name": "topic_analyses",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "uuid",+ "primaryKey": true,+ "notNull": true,+ "default": "gen_random_uuid()"+ },+ "topic_id": {+ "name": "topic_id",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "user_id": {+ "name": "user_id",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "workspace_id": {+ "name": "workspace_id",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "taxonomy_version": {+ "name": "taxonomy_version",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "category": {+ "name": "category",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "secondary_category": {+ "name": "secondary_category",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "intent": {+ "name": "intent",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "outcome": {+ "name": "outcome",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "labels": {+ "name": "labels",+ "type": "jsonb",+ "primaryKey": false,+ "notNull": false+ },+ "metadata": {+ "name": "metadata",+ "type": "jsonb",+ "primaryKey": false,+ "notNull": false+ },+ "model": {+ "name": "model",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "provider": {+ "name": "provider",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "topic_model": {+ "name": "topic_model",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "topic_provider": {+ "name": "topic_provider",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "total_tokens": {+ "name": "total_tokens",+ "type": "integer",+ "primaryKey": false,+ "notNull": false+ },+ "total_input_tokens": {+ "name": "total_input_tokens",+ "type": "integer",+ "primaryKey": false,+ "notNull": false+ },+ "total_output_tokens": {+ "name": "total_output_tokens",+ "type": "integer",+ "primaryKey": false,+ "notNull": false+ },+ "total_cost": {+ "name": "total_cost",+ "type": "numeric(20, 6)",+ "primaryKey": false,+ "notNull": false+ },+ "llm_calls": {+ "name": "llm_calls",+ "type": "integer",+ "primaryKey": false,+ "notNull": false+ },+ "tool_calls": {+ "name": "tool_calls",+ "type": "integer",+ "primaryKey": false,+ "notNull": false+ },+ "user_messages": {+ "name": "user_messages",+ "type": "integer",+ "primaryKey": false,+ "notNull": false+ },+ "assistant_messages": {+ "name": "assistant_messages",+ "type": "integer",+ "primaryKey": false,+ "notNull": false+ },+ "last_message_id": {+ "name": "last_message_id",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "last_message_updated_at": {+ "name": "last_message_updated_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": false+ },+ "accessed_at": {+ "name": "accessed_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ },+ "created_at": {+ "name": "created_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ },+ "updated_at": {+ "name": "updated_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ }+ },+ "indexes": {+ "topic_analyses_topic_version_unique": {+ "name": "topic_analyses_topic_version_unique",+ "columns": [+ {+ "expression": "topic_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "taxonomy_version",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": true,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "topic_analyses_user_id_created_at_idx": {+ "name": "topic_analyses_user_id_created_at_idx",+ "columns": [+ {+ "expression": "user_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "created_at",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "topic_analyses_workspace_id_created_at_idx": {+ "name": "topic_analyses_workspace_id_created_at_idx",+ "columns": [+ {+ "expression": "workspace_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "created_at",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "where": "\"topic_analyses\".\"workspace_id\" IS NOT NULL",+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "topic_analyses_version_category_idx": {+ "name": "topic_analyses_version_category_idx",+ "columns": [+ {+ "expression": "taxonomy_version",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "category",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "foreignKeys": {+ "topic_analyses_topic_id_topics_id_fk": {+ "name": "topic_analyses_topic_id_topics_id_fk",+ "tableFrom": "topic_analyses",+ "tableTo": "topics",+ "columnsFrom": ["topic_id"],+ "columnsTo": ["id"],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "topic_analyses_user_id_users_id_fk": {+ "name": "topic_analyses_user_id_users_id_fk",+ "tableFrom": "topic_analyses",+ "tableTo": "users",+ "columnsFrom": ["user_id"],+ "columnsTo": ["id"],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "topic_analyses_workspace_id_workspaces_id_fk": {+ "name": "topic_analyses_workspace_id_workspaces_id_fk",+ "tableFrom": "topic_analyses",+ "tableTo": "workspaces",+ "columnsFrom": ["workspace_id"],+ "columnsTo": ["id"],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },"public.topic_comment_mentions": {"name": "topic_comment_mentions","schema": "",@@ -39325,6 +40532,22 @@"concurrently": false,"method": "btree","with": {}+ },+ "user_memories_activities_dossier_id_index": {+ "name": "user_memories_activities_dossier_id_index",+ "columns": [+ {+ "expression": "dossier_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "where": "\"user_memories_activities\".\"dossier_id\" IS NOT NULL",+ "concurrently": false,+ "method": "btree",+ "with": {}}},"foreignKeys": {@@ -39964,6 +41187,42 @@"concurrently": false,"method": "gin","with": {}+ },+ "user_memories_contexts_user_memory_id_index": {+ "name": "user_memories_contexts_user_memory_id_index",+ "columns": [+ {+ "expression": "user_memory_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "user_memories_contexts_user_id_last_evidence_at_index": {+ "name": "user_memories_contexts_user_id_last_evidence_at_index",+ "columns": [+ {+ "expression": "user_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "last_evidence_at",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}}},"foreignKeys": {@@ -41168,43 +42427,237 @@}},"indexes": {- "user_memories_experiences_situation_vector_index": {- "name": "user_memories_experiences_situation_vector_index",- "columns": [- {- "expression": "situation_vector",- "isExpression": false,- "asc": true,- "nulls": "last",- "opclass": "vector_cosine_ops"- }- ],- "isUnique": false,- "concurrently": false,- "method": "hnsw",- "with": {}- },- "user_memories_experiences_action_vector_index": {- "name": "user_memories_experiences_action_vector_index",- "columns": [- {- "expression": "action_vector",- "isExpression": false,- "asc": true,- "nulls": "last",- "opclass": "vector_cosine_ops"- }- ],- "isUnique": false,- "concurrently": false,- "method": "hnsw",- "with": {}- },- "user_memories_experiences_key_learning_vector_index": {- "name": "user_memories_experiences_key_learning_vector_index",+ "user_memories_experiences_situation_vector_index": {+ "name": "user_memories_experiences_situation_vector_index",+ "columns": [+ {+ "expression": "situation_vector",+ "isExpression": false,+ "asc": true,+ "nulls": "last",+ "opclass": "vector_cosine_ops"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "hnsw",+ "with": {}+ },+ "user_memories_experiences_action_vector_index": {+ "name": "user_memories_experiences_action_vector_index",+ "columns": [+ {+ "expression": "action_vector",+ "isExpression": false,+ "asc": true,+ "nulls": "last",+ "opclass": "vector_cosine_ops"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "hnsw",+ "with": {}+ },+ "user_memories_experiences_key_learning_vector_index": {+ "name": "user_memories_experiences_key_learning_vector_index",+ "columns": [+ {+ "expression": "key_learning_vector",+ "isExpression": false,+ "asc": true,+ "nulls": "last",+ "opclass": "vector_cosine_ops"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "hnsw",+ "with": {}+ },+ "user_memories_experiences_type_index": {+ "name": "user_memories_experiences_type_index",+ "columns": [+ {+ "expression": "type",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "user_memories_experiences_user_id_index": {+ "name": "user_memories_experiences_user_id_index",+ "columns": [+ {+ "expression": "user_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "user_memories_experiences_user_memory_id_index": {+ "name": "user_memories_experiences_user_memory_id_index",+ "columns": [+ {+ "expression": "user_memory_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "foreignKeys": {+ "user_memories_experiences_user_id_users_id_fk": {+ "name": "user_memories_experiences_user_id_users_id_fk",+ "tableFrom": "user_memories_experiences",+ "tableTo": "users",+ "columnsFrom": ["user_id"],+ "columnsTo": ["id"],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "user_memories_experiences_user_memory_id_user_memories_id_fk": {+ "name": "user_memories_experiences_user_memory_id_user_memories_id_fk",+ "tableFrom": "user_memories_experiences",+ "tableTo": "user_memories",+ "columnsFrom": ["user_memory_id"],+ "columnsTo": ["id"],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.user_memories_identities": {+ "name": "user_memories_identities",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "varchar(255)",+ "primaryKey": true,+ "notNull": true+ },+ "user_id": {+ "name": "user_id",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "user_memory_id": {+ "name": "user_memory_id",+ "type": "varchar(255)",+ "primaryKey": false,+ "notNull": false+ },+ "metadata": {+ "name": "metadata",+ "type": "jsonb",+ "primaryKey": false,+ "notNull": false+ },+ "tags": {+ "name": "tags",+ "type": "text[]",+ "primaryKey": false,+ "notNull": false+ },+ "type": {+ "name": "type",+ "type": "varchar(255)",+ "primaryKey": false,+ "notNull": false+ },+ "description": {+ "name": "description",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "description_vector": {+ "name": "description_vector",+ "type": "vector(1024)",+ "primaryKey": false,+ "notNull": false+ },+ "episodic_date": {+ "name": "episodic_date",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": false+ },+ "relationship": {+ "name": "relationship",+ "type": "varchar(255)",+ "primaryKey": false,+ "notNull": false+ },+ "role": {+ "name": "role",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "entity_id": {+ "name": "entity_id",+ "type": "varchar(255)",+ "primaryKey": false,+ "notNull": false+ },+ "captured_at": {+ "name": "captured_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ },+ "accessed_at": {+ "name": "accessed_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ },+ "created_at": {+ "name": "created_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ },+ "updated_at": {+ "name": "updated_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ }+ },+ "indexes": {+ "user_memories_identities_description_vector_index": {+ "name": "user_memories_identities_description_vector_index","columns": [{- "expression": "key_learning_vector",+ "expression": "description_vector","isExpression": false,"asc": true,"nulls": "last",@@ -41216,8 +42669,8 @@"method": "hnsw","with": {}},- "user_memories_experiences_type_index": {- "name": "user_memories_experiences_type_index",+ "user_memories_identities_type_index": {+ "name": "user_memories_identities_type_index","columns": [{"expression": "type",@@ -41231,8 +42684,8 @@"method": "btree","with": {}},- "user_memories_experiences_user_id_index": {- "name": "user_memories_experiences_user_id_index",+ "user_memories_identities_user_id_index": {+ "name": "user_memories_identities_user_id_index","columns": [{"expression": "user_id",@@ -41246,8 +42699,8 @@"method": "btree","with": {}},- "user_memories_experiences_user_memory_id_index": {- "name": "user_memories_experiences_user_memory_id_index",+ "user_memories_identities_user_memory_id_index": {+ "name": "user_memories_identities_user_memory_id_index","columns": [{"expression": "user_memory_id",@@ -41260,191 +42713,12 @@"concurrently": false,"method": "btree","with": {}- }- },- "foreignKeys": {- "user_memories_experiences_user_id_users_id_fk": {- "name": "user_memories_experiences_user_id_users_id_fk",- "tableFrom": "user_memories_experiences",- "tableTo": "users",- "columnsFrom": ["user_id"],- "columnsTo": ["id"],- "onDelete": "cascade",- "onUpdate": "no action"- },- "user_memories_experiences_user_memory_id_user_memories_id_fk": {- "name": "user_memories_experiences_user_memory_id_user_memories_id_fk",- "tableFrom": "user_memories_experiences",- "tableTo": "user_memories",- "columnsFrom": ["user_memory_id"],- "columnsTo": ["id"],- "onDelete": "cascade",- "onUpdate": "no action"- }- },- "compositePrimaryKeys": {},- "uniqueConstraints": {},- "policies": {},- "checkConstraints": {},- "isRLSEnabled": false- },- "public.user_memories_identities": {- "name": "user_memories_identities",- "schema": "",- "columns": {- "id": {- "name": "id",- "type": "varchar(255)",- "primaryKey": true,- "notNull": true- },- "user_id": {- "name": "user_id",- "type": "text",- "primaryKey": false,- "notNull": false- },- "user_memory_id": {- "name": "user_memory_id",- "type": "varchar(255)",- "primaryKey": false,- "notNull": false- },- "metadata": {- "name": "metadata",- "type": "jsonb",- "primaryKey": false,- "notNull": false- },- "tags": {- "name": "tags",- "type": "text[]",- "primaryKey": false,- "notNull": false- },- "type": {- "name": "type",- "type": "varchar(255)",- "primaryKey": false,- "notNull": false- },- "description": {- "name": "description",- "type": "text",- "primaryKey": false,- "notNull": false- },- "description_vector": {- "name": "description_vector",- "type": "vector(1024)",- "primaryKey": false,- "notNull": false- },- "episodic_date": {- "name": "episodic_date",- "type": "timestamp with time zone",- "primaryKey": false,- "notNull": false- },- "relationship": {- "name": "relationship",- "type": "varchar(255)",- "primaryKey": false,- "notNull": false- },- "role": {- "name": "role",- "type": "text",- "primaryKey": false,- "notNull": false- },- "entity_id": {- "name": "entity_id",- "type": "varchar(255)",- "primaryKey": false,- "notNull": false- },- "captured_at": {- "name": "captured_at",- "type": "timestamp with time zone",- "primaryKey": false,- "notNull": true,- "default": "now()"- },- "accessed_at": {- "name": "accessed_at",- "type": "timestamp with time zone",- "primaryKey": false,- "notNull": true,- "default": "now()"- },- "created_at": {- "name": "created_at",- "type": "timestamp with time zone",- "primaryKey": false,- "notNull": true,- "default": "now()"- },- "updated_at": {- "name": "updated_at",- "type": "timestamp with time zone",- "primaryKey": false,- "notNull": true,- "default": "now()"- }- },- "indexes": {- "user_memories_identities_description_vector_index": {- "name": "user_memories_identities_description_vector_index",- "columns": [- {- "expression": "description_vector",- "isExpression": false,- "asc": true,- "nulls": "last",- "opclass": "vector_cosine_ops"- }- ],- "isUnique": false,- "concurrently": false,- "method": "hnsw",- "with": {}- },- "user_memories_identities_type_index": {- "name": "user_memories_identities_type_index",- "columns": [- {- "expression": "type",- "isExpression": false,- "asc": true,- "nulls": "last"- }- ],- "isUnique": false,- "concurrently": false,- "method": "btree",- "with": {}- },- "user_memories_identities_user_id_index": {- "name": "user_memories_identities_user_id_index",- "columns": [- {- "expression": "user_id",- "isExpression": false,- "asc": true,- "nulls": "last"- }- ],- "isUnique": false,- "concurrently": false,- "method": "btree",- "with": {}},- "user_memories_identities_user_memory_id_index": {- "name": "user_memories_identities_user_memory_id_index",+ "user_memories_identities_entity_id_index": {+ "name": "user_memories_identities_entity_id_index","columns": [{- "expression": "user_memory_id",+ "expression": "entity_id","isExpression": false,"asc": true,"nulls": "last"@@ -42214,6 +43488,36 @@"concurrently": false,"method": "btree","with": {}+ },+ "user_memories_preferences_holder_entity_id_index": {+ "name": "user_memories_preferences_holder_entity_id_index",+ "columns": [+ {+ "expression": "holder_entity_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "user_memories_preferences_applies_to_entity_id_index": {+ "name": "user_memories_preferences_applies_to_entity_id_index",+ "columns": [+ {+ "expression": "applies_to_entity_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}}},"foreignKeys": {@@ -46418,11 +47722,18 @@"notNull": true,"default": "'pending'"},+ "reusable": {+ "name": "reusable",+ "type": "boolean",+ "primaryKey": false,+ "notNull": true,+ "default": false+ },"expires_at": {"name": "expires_at","type": "timestamp with time zone","primaryKey": false,- "notNull": true+ "notNull": false},"created_at": {"name": "created_at",@@ -46530,7 +47841,12 @@}},"policies": {},- "checkConstraints": {},+ "checkConstraints": {+ "workspace_invitations_expiry_required": {+ "name": "workspace_invitations_expiry_required",+ "value": "\"workspace_invitations\".\"reusable\" OR \"workspace_invitations\".\"expires_at\" IS NOT NULL"+ }+ },"isRLSEnabled": false},"public.workspace_members": {diff --git a/packages/database/migrations/meta/_journal.json b/packages/database/migrations/meta/_journal.jsonindex a5520ca0f50..394d8b50565 100644--- a/packages/database/migrations/meta/_journal.json+++ b/packages/database/migrations/meta/_journal.json@@ -1435,6 +1435,13 @@"when": 1793869041794,"tag": "0204_workspace_invitation_link","breakpoints": true+ },+ {+ "idx": 205,+ "version": "7",+ "when": 1793930690156,+ "tag": "0205_lobe_bench_environments_and_memory",+ "breakpoints": true}],"version": "6"diff --git a/packages/database/src/schemas/agentEvalMemory.ts b/packages/database/src/schemas/agentEvalMemory.tsnew file mode 100644index 00000000000..362aec71473--- /dev/null+++ b/packages/database/src/schemas/agentEvalMemory.ts@@ -0,0 +1,68 @@+import type { EvalMemoryLayer, EvalMemorySource } from '@lobechat/types';+import { index, jsonb, pgTable, text, uuid, vector } from 'drizzle-orm/pg-core';++import { timestamps, timestamptz } from './_helpers';+import { agentEvalRuns } from './agentEvals';+import { threads, topics } from './topic';+import { users } from './user';+import { workspaces } from './workspace';++/**+ * The Memory of one eval attempt (a run's topic, or one pass@k thread of it):+ * the case fixture seeded at the start plus whatever the Agent wrote. The+ * Memory tool of an attempt reads and writes only these rows, so attempts+ * never see each other and never touch the caller's own memories. Rows are+ * evidence: they stay until their run or owner is deleted. Conversation deletion+ * clears topic/thread pointers; attemptId preserves the original attempt identity.+ */+export const agentEvalMemories = pgTable(+ 'agent_eval_memories',+ {+ id: uuid('id').defaultRandom().primaryKey(),+ userId: text('user_id')+ .references(() => users.id, { onDelete: 'cascade' })+ .notNull(),+ /** The run's workspace; null for a personal run. */+ workspaceId: text('workspace_id').references(() => workspaces.id, { onDelete: 'cascade' }),+ runId: text('run_id')+ .references(() => agentEvalRuns.id, { onDelete: 'cascade' })+ .notNull(),+ topicId: text('topic_id').references(() => topics.id, { onDelete: 'set null' }),+ threadId: text('thread_id').references(() => threads.id, { onDelete: 'set null' }),+ /** `runId_topicId[_threadId]`: the key the mock service also groups by. */+ attemptId: text('attempt_id').notNull(),++ layer: text('layer').$type<EvalMemoryLayer>().notNull(),+ source: text('source').$type<EvalMemorySource>().notNull(),+ /** Set on seeded rows: a resumed attempt must bring the same fixture. */+ fixtureHash: text('fixture_hash'),++ title: text('title'),+ summary: text('summary'),+ details: text('details'),+ memoryCategory: text('memory_category'),+ memoryType: text('memory_type'),+ tags: jsonb('tags').$type<string[]>(),+ /** The layer-specific part of the entry, as the Memory tool received it. */+ payload: jsonb('payload').$type<Record<string, unknown>>().notNull(),+ embedding: vector('embedding', { dimensions: 1024 }),++ /** The fixture's seededAt for seeded rows; the wall clock for the Agent's writes. */+ capturedAt: timestamptz('captured_at').notNull(),+ /** The Agent removed the entry (identities); kept as evidence, hidden from search. */+ removedReason: text('removed_reason'),+ metadata: jsonb('metadata').$type<Record<string, unknown>>(),+ ...timestamps,+ },+ (t) => [+ index('agent_eval_memories_attempt_id_idx').on(t.attemptId),+ index('agent_eval_memories_run_id_idx').on(t.runId),+ index('agent_eval_memories_topic_id_idx').on(t.topicId),+ index('agent_eval_memories_thread_id_idx').on(t.threadId),+ index('agent_eval_memories_user_id_idx').on(t.userId),+ index('agent_eval_memories_workspace_id_idx').on(t.workspaceId),+ ],+);++export type AgentEvalMemoryItem = typeof agentEvalMemories.$inferSelect;+export type NewAgentEvalMemory = typeof agentEvalMemories.$inferInsert;diff --git a/packages/database/src/schemas/agentEvals.ts b/packages/database/src/schemas/agentEvals.tsindex 1db6d930e86..4a25c3e9441 100644--- a/packages/database/src/schemas/agentEvals.ts+++ b/packages/database/src/schemas/agentEvals.ts@@ -1,5 +1,6 @@import type {EvalBenchmarkRubric,+ EvalCaseEnvironment,EvalConfig,EvalRunConfig,EvalRunMetrics,@@ -7,7 +8,7 @@ import type {EvalTestCaseContent,EvalTestCaseMetadata,} from '@lobechat/types';-import { isNotNull, isNull } from 'drizzle-orm';+import { isNotNull, isNull, sql } from 'drizzle-orm';import {boolean,foreignKey,@@ -19,6 +20,7 @@ import {real,text,uniqueIndex,+ uuid,} from 'drizzle-orm/pg-core';import { idGenerator } from '../utils/idGenerator';@@ -212,6 +214,49 @@ export const agentEvalDatasets = pgTable(export type NewAgentEvalDataset = typeof agentEvalDatasets.$inferInsert;export type AgentEvalDatasetItem = typeof agentEvalDatasets.$inferSelect;+// ============================================+// 2b. agent_eval_environments (Reusable Case Environments)+// ============================================+/**+ * The environment many cases share: the Agent setup (persona, tools, memory+ * switch), the Memory fixture, the clock and the mock connectors. A case+ * points at one through `environment_id`, so one environment can back five,+ * ten or a hundred cases instead of each case carrying its own copy.+ */+export const agentEvalEnvironments = pgTable(+ 'agent_eval_environments',+ {+ id: uuid('id').defaultRandom().primaryKey(),++ // Nullable for system-owned rows; imported packages belong to their owner.+ userId: text('user_id').references(() => users.id, { onDelete: 'cascade' }),+ workspaceId: text('workspace_id').references(() => workspaces.id, { onDelete: 'cascade' }),++ /** Optional stable import handle, unique within its user or workspace scope. */+ identifier: text('identifier'),+ name: text('name').notNull(),+ description: text('description'),++ config: jsonb('config').$type<EvalCaseEnvironment>().notNull(),+ metadata: jsonb('metadata').$type<Record<string, unknown>>(),++ ...timestamps,+ },+ (t) => [+ index('agent_eval_environments_user_id_idx').on(t.userId),+ index('agent_eval_environments_workspace_id_idx').on(t.workspaceId),+ uniqueIndex('agent_eval_environments_identifier_user_id_unique')+ .on(t.identifier, t.userId)+ .where(sql`${t.identifier} IS NOT NULL AND ${t.workspaceId} IS NULL`),+ uniqueIndex('agent_eval_environments_identifier_workspace_id_unique')+ .on(t.identifier, t.workspaceId)+ .where(sql`${t.identifier} IS NOT NULL AND ${t.workspaceId} IS NOT NULL`),+ ],+);++export type NewAgentEvalEnvironment = typeof agentEvalEnvironments.$inferInsert;+export type AgentEvalEnvironmentItem = typeof agentEvalEnvironments.$inferSelect;+// ============================================// 3. agent_eval_test_cases (Evaluation Test Cases)// ============================================@@ -222,15 +267,19 @@ export const agentEvalTestCases = pgTable(.$defaultFn(() => idGenerator('evalTestCases')).primaryKey(),- userId: text('user_id')- .references(() => users.id, { onDelete: 'cascade' })- .notNull(),+ // Nullable for system-owned rows; imported packages belong to their owner.+ userId: text('user_id').references(() => users.id, { onDelete: 'cascade' }),workspaceId: text('workspace_id').references(() => workspaces.id, { onDelete: 'cascade' }),datasetId: text('dataset_id').references(() => agentEvalDatasets.id, { onDelete: 'cascade' }).notNull(),+ /** Shared runtime configuration; case content can override individual fields. */+ environmentId: uuid('environment_id').references(() => agentEvalEnvironments.id, {+ onDelete: 'set null',+ }),+content: jsonb('content').$type<EvalTestCaseContent>().notNull(),evalMode: text('eval_mode', { enum: evalModes }),@@ -245,6 +294,7 @@ export const agentEvalTestCases = pgTable((t) => [index('agent_eval_test_cases_user_id_idx').on(t.userId),index('agent_eval_test_cases_dataset_id_idx').on(t.datasetId),+ index('agent_eval_test_cases_environment_id_idx').on(t.environmentId),index('agent_eval_test_cases_sort_order_idx').on(t.sortOrder),index('agent_eval_test_cases_workspace_id_idx').on(t.workspaceId),],diff --git a/packages/database/src/schemas/index.ts b/packages/database/src/schemas/index.tsindex bf5fb2b6b20..9dd350acbb5 100644--- a/packages/database/src/schemas/index.ts+++ b/packages/database/src/schemas/index.ts@@ -5,6 +5,7 @@ export * from './agentAccount';export * from './agentBotProvider';export * from './agentCronJob';export * from './agentDocuments';+export * from './agentEvalMemory';export * from './agentEvals';export * from './agentHistoryJob';export * from './agentInboxMessage';diff --git a/packages/database/tests/lobeBenchMigration.test.ts b/packages/database/tests/lobeBenchMigration.test.tsnew file mode 100644index 00000000000..2439928a73f--- /dev/null+++ b/packages/database/tests/lobeBenchMigration.test.ts@@ -0,0 +1,341 @@+// @vitest-environment node+import { copyFile, mkdir, mkdtemp, rm, writeFile } from 'node:fs/promises';+import { tmpdir } from 'node:os';+import path from 'node:path';++import { PGlite } from '@electric-sql/pglite';+import { vector } from '@electric-sql/pglite/vector';+import { readMigrationFiles } from 'drizzle-orm/migrator';+import { drizzle } from 'drizzle-orm/pglite';+import { migrate } from 'drizzle-orm/pglite/migrator';+import { afterAll, describe, expect, it } from 'vitest';++import journal from '../migrations/meta/_journal.json';+import { agentEvalMemories } from '../src/schemas/agentEvalMemory';+import { agentEvalEnvironments } from '../src/schemas/agentEvals';++const migrationsFolder = path.join(__dirname, '../migrations');+const migrationTag = '0205_lobe_bench_environments_and_memory';+const temporaryFolders: string[] = [];++async function canaryMigrationsFolder() {+ const folder = await mkdtemp(path.join(tmpdir(), 'lobe-bench-migration-'));+ temporaryFolders.push(folder);+ await mkdir(path.join(folder, 'meta'));+ const migrationIndex = journal.entries.findIndex(({ tag }) => tag === migrationTag);+ expect(migrationIndex).toBeGreaterThanOrEqual(0);+ const entries = journal.entries.slice(0, migrationIndex);+ await writeFile(path.join(folder, 'meta/_journal.json'), JSON.stringify({ ...journal, entries }));+ await Promise.all(+ entries.map(({ tag }) =>+ copyFile(path.join(migrationsFolder, `${tag}.sql`), path.join(folder, `${tag}.sql`)),+ ),+ );+ return folder;+}++const evidenceTables = [+ 'agent_eval_datasets',+ 'agent_eval_test_cases',+ 'agent_eval_environments',+ 'agent_eval_runs',+ 'agent_eval_run_topics',+ 'agent_eval_memories',+ 'topics',+ 'messages',+ 'users',+];++async function evidence(client: PGlite) {+ return Promise.all(+ evidenceTables.map(+ async (table) =>+ (+ await client.query(+ `SELECT to_jsonb(t) AS value FROM ${table} t ORDER BY to_jsonb(t)::text`,+ )+ ).rows,+ ),+ );+}++describe('LobeBench migration integration', () => {+ afterAll(async () => {+ await Promise.all(+ temporaryFolders.map((folder) => rm(folder, { recursive: true, force: true })),+ );+ });++ it('creates empty environment and memory tables with reusable links and preserves evidence on SQL replay', async () => {+ const client = new PGlite({ extensions: { vector } });+ const db = drizzle({ client });+ try {+ await migrate(db, { migrationsFolder });+ expect((await client.query('SELECT * FROM agent_eval_environments')).rows).toHaveLength(0);+ expect((await client.query('SELECT * FROM agent_eval_memories')).rows).toHaveLength(0);+ expect((await client.query('SELECT * FROM agent_eval_test_cases')).rows).toHaveLength(0);+ expect(+ (await client.query("SELECT 1 FROM pg_extension WHERE extname = 'pg_search'")).rows,+ ).toHaveLength(0);+ expect(+ (+ await client.query(+ "SELECT 1 FROM pg_indexes WHERE indexname = 'agent_eval_memories_bm25_idx'",+ )+ ).rows,+ ).toHaveLength(0);++ await client.exec(`+ INSERT INTO users (id) VALUES ('migration-user');+ INSERT INTO agent_eval_datasets (id, identifier, name)+ VALUES ('migration-dataset', 'saved-cases', 'Saved cases');+ INSERT INTO agent_eval_runs (id, dataset_id, user_id, status, metrics)+ VALUES ('migration-run', 'migration-dataset', 'migration-user', 'completed', '{"passedCases":1}');+ INSERT INTO topics (id, user_id) VALUES ('migration-topic', 'migration-user');+ `);+ const [environment] = await db+ .insert(agentEvalEnvironments)+ .values({ config: {}, name: 'Shared environment' })+ .returning();+ const [memory] = await db+ .insert(agentEvalMemories)+ .values({+ attemptId: 'migration-attempt',+ capturedAt: new Date('2026-10-20T00:00:00Z'),+ layer: 'identity',+ payload: { description: 'Saved evidence' },+ runId: 'migration-run',+ source: 'agent',+ topicId: 'migration-topic',+ userId: 'migration-user',+ })+ .returning();+ expect(environment.id).toMatch(/^[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12}$/);+ expect(memory.id).toMatch(/^[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12}$/);+ expect(memory.metadata).toBeNull();+ expect(memory.workspaceId).toBeNull();+ await client.query(+ `INSERT INTO agent_eval_test_cases (id, dataset_id, environment_id, content)+ VALUES ('migration-case-a', 'migration-dataset', $1, '{"input":"First case"}'),+ ('migration-case-b', 'migration-dataset', $1, '{"input":"Second case"}')`,+ [environment.id],+ );+ await client.exec(`+ INSERT INTO messages (id, user_id, topic_id, role, content)+ VALUES ('migration-message', 'migration-user', 'migration-topic', 'assistant', 'Saved answer');+ INSERT INTO agent_eval_run_topics (run_id, topic_id, test_case_id, user_id, status, passed, eval_result)+ VALUES ('migration-run', 'migration-topic', 'migration-case-a', 'migration-user', 'passed', true,+ '{"reason":"Saved Judge reason","model":"frozen-judge"}');+ `);+ const before = await evidence(client);+ // SQL replay exercises idempotency independently of Drizzle's journal skip.+ const migrationIndex = journal.entries.findIndex(({ tag }) => tag === migrationTag);+ expect(migrationIndex).toBeGreaterThanOrEqual(0);+ for (const statement of readMigrationFiles({ migrationsFolder })[migrationIndex].sql) {+ await client.query(statement);+ }+ expect(await evidence(client)).toEqual(before);++ await client.query('DELETE FROM agent_eval_environments WHERE id = $1', [environment.id]);+ expect(+ (await client.query('SELECT environment_id FROM agent_eval_test_cases ORDER BY id')).rows,+ ).toEqual([{ environment_id: null }, { environment_id: null }]);+ expect((await client.query('SELECT * FROM agent_eval_run_topics')).rows).toHaveLength(1);+ await client.query("DELETE FROM agent_eval_runs WHERE id = 'migration-run'");+ expect((await client.query('SELECT * FROM agent_eval_memories')).rows).toHaveLength(0);+ } finally {+ await client.close();+ }+ }, 60_000);++ it('retains Memory evidence after thread and topic deletion until its run is deleted', async () => {+ const client = new PGlite({ extensions: { vector } });+ const db = drizzle({ client });+ try {+ await migrate(db, { migrationsFolder });+ expect+ .soft(+ (+ await client.query(`+ SELECT is_nullable FROM information_schema.columns+ WHERE table_schema = 'public' AND table_name = 'agent_eval_memories'+ AND column_name = 'topic_id'+ `)+ ).rows,+ )+ .toEqual([{ is_nullable: 'YES' }]);+ const indexedColumns = await client.query<{ column_name: string }>(`+ SELECT attribute.attname AS column_name+ FROM pg_index AS index+ JOIN pg_class AS table_class ON table_class.oid = index.indrelid+ JOIN pg_class AS index_class ON index_class.oid = index.indexrelid+ JOIN pg_am AS method ON method.oid = index_class.relam+ JOIN pg_attribute AS attribute+ ON attribute.attrelid = table_class.oid AND attribute.attnum = index.indkey[0]+ WHERE table_class.oid = 'public.agent_eval_memories'::regclass+ AND method.amname = 'btree' AND index.indisvalid AND index.indisready+ AND index.indpred IS NULL+ `);+ expect+ .soft(indexedColumns.rows.map(({ column_name }) => column_name))+ .toEqual(expect.arrayContaining(['topic_id', 'thread_id', 'workspace_id']));++ await client.exec(`+ INSERT INTO users (id) VALUES ('retention-user');+ INSERT INTO agent_eval_datasets (id, identifier, name)+ VALUES ('retention-dataset', 'retention-cases', 'Retention cases');+ INSERT INTO agent_eval_runs (id, dataset_id, user_id, status)+ VALUES ('retention-run', 'retention-dataset', 'retention-user', 'completed'),+ ('unrelated-run', 'retention-dataset', 'retention-user', 'completed');+ INSERT INTO topics (id, user_id)+ VALUES ('retention-topic', 'retention-user'), ('unrelated-topic', 'retention-user');+ INSERT INTO threads (id, topic_id, user_id, type)+ VALUES ('deleted-thread', 'retention-topic', 'retention-user', 'eval'),+ ('cascaded-thread', 'retention-topic', 'retention-user', 'eval'),+ ('unrelated-thread', 'unrelated-topic', 'retention-user', 'eval');+ `);+ const embedding = Array.from({ length: 1024 }, (_, index) => (index % 4) / 4);+ const retainedMemories = await db+ .insert(agentEvalMemories)+ .values(+ [null, 'deleted-thread', 'cascaded-thread'].map((threadId, index) => ({+ attemptId: `retention-run_retention-topic${threadId ? `_${threadId}` : ''}`,+ capturedAt: new Date('2026-10-20T00:00:00Z'),+ embedding,+ layer: 'identity' as const,+ payload: { description: 'Saved evidence', nested: { index, values: [1, 2, 3] } },+ runId: 'retention-run',+ source: 'agent' as const,+ threadId,+ topicId: 'retention-topic',+ userId: 'retention-user',+ })),+ )+ .returning();+ const [unrelatedMemory] = await db+ .insert(agentEvalMemories)+ .values({+ attemptId: 'unrelated-run_unrelated-topic_unrelated-thread',+ capturedAt: new Date('2026-10-21T00:00:00Z'),+ embedding,+ layer: 'identity',+ payload: { description: 'Other attempt evidence' },+ runId: 'unrelated-run',+ source: 'fixture',+ threadId: 'unrelated-thread',+ topicId: 'unrelated-topic',+ userId: 'retention-user',+ })+ .returning();+ const memories = () => db.select().from(agentEvalMemories).orderBy(agentEvalMemories.id);+ // Random uuid keys: compare in the same id order the query returns.+ const byId = <T extends { id: string }>(rows: T[]) =>+ [...rows].sort((left, right) => (left.id < right.id ? -1 : left.id > right.id ? 1 : 0));++ await client.query("DELETE FROM threads WHERE id = 'deleted-thread'");+ expect.soft(await memories()).toEqual(+ byId([+ ...retainedMemories.map((memory) => ({+ ...memory,+ threadId: memory.threadId === 'deleted-thread' ? null : memory.threadId,+ })),+ unrelatedMemory,+ ]),+ );++ await client.query("DELETE FROM topics WHERE id = 'retention-topic'");+ expect+ .soft(+ (await client.query("SELECT id FROM threads WHERE topic_id = 'retention-topic'")).rows,+ )+ .toEqual([]);+ expect+ .soft(await memories())+ .toEqual(+ byId([+ ...retainedMemories.map((memory) => ({ ...memory, threadId: null, topicId: null })),+ unrelatedMemory,+ ]),+ );++ await client.query("DELETE FROM agent_eval_runs WHERE id = 'retention-run'");+ expect(await memories()).toEqual([unrelatedMemory]);+ expect((await client.query('SELECT id FROM agent_eval_runs ORDER BY id')).rows).toEqual([+ { id: 'unrelated-run' },+ ]);++ // A workspace run's Memory goes with its workspace; personal rows stay.+ await client.exec(`+ INSERT INTO workspaces (id, slug, name, primary_owner_id)+ VALUES ('retention-workspace', 'retention-workspace', 'Retention', 'retention-user');+ `);+ const [workspaceMemory] = await db+ .insert(agentEvalMemories)+ .values({+ attemptId: 'unrelated-run_unrelated-topic',+ capturedAt: new Date('2026-10-22T00:00:00Z'),+ layer: 'identity',+ payload: { description: 'Workspace attempt evidence' },+ runId: 'unrelated-run',+ source: 'agent',+ topicId: 'unrelated-topic',+ userId: 'retention-user',+ workspaceId: 'retention-workspace',+ })+ .returning();+ expect(await memories()).toEqual(byId([unrelatedMemory, workspaceMemory]));+ await client.query("DELETE FROM workspaces WHERE id = 'retention-workspace'");+ expect(await memories()).toEqual([unrelatedMemory]);+ } finally {+ await client.close();+ }+ }, 60_000);++ it('upgrades canary while retaining case IDs, ownership, answers and judged run records', async () => {+ const client = new PGlite({ extensions: { vector } });+ try {+ await migrate(drizzle({ client }), { migrationsFolder: await canaryMigrationsFolder() });+ await client.exec(`+ INSERT INTO users (id) VALUES ('existing-user');+ INSERT INTO agent_eval_datasets (id, identifier, name)+ VALUES ('existing-dataset', 'existing-cases', 'Existing dataset');+ INSERT INTO agent_eval_test_cases (id, user_id, dataset_id, content)+ VALUES ('existing-case', 'existing-user', 'existing-dataset', '{"input":"Existing"}');+ INSERT INTO agent_eval_runs (id, user_id, dataset_id, status, metrics)+ VALUES ('existing-run', 'existing-user', 'existing-dataset', 'completed', '{"passedCases":1}');+ INSERT INTO topics (id, user_id) VALUES ('existing-topic', 'existing-user');+ INSERT INTO messages (id, user_id, topic_id, role, content)+ VALUES ('existing-message', 'existing-user', 'existing-topic', 'assistant', 'Saved answer');+ INSERT INTO agent_eval_run_topics (run_id, topic_id, test_case_id, user_id, status, passed, eval_result)+ VALUES ('existing-run', 'existing-topic', 'existing-case', 'existing-user', 'passed', true,+ '{"reason":"Existing Judge reason"}');+ `);+ const preservedTables = ['agent_eval_runs', 'agent_eval_run_topics', 'topics', 'messages'];+ const before = await Promise.all(+ preservedTables.map(async (table) => (await client.query(`SELECT * FROM ${table}`)).rows),+ );+ await migrate(drizzle({ client }), { migrationsFolder });+ expect(+ await Promise.all(+ preservedTables.map(async (table) => (await client.query(`SELECT * FROM ${table}`)).rows),+ ),+ ).toEqual(before);+ expect(+ (+ await client.query(+ 'SELECT id, user_id, environment_id, content FROM agent_eval_test_cases',+ )+ ).rows,+ ).toEqual([+ {+ content: { input: 'Existing' },+ environment_id: null,+ id: 'existing-case',+ user_id: 'existing-user',+ },+ ]);+ } finally {+ await client.close();+ }+ }, 60_000);+});diff --git a/packages/types/src/eval/evalMemory.ts b/packages/types/src/eval/evalMemory.tsnew file mode 100644index 00000000000..ae573482f8f--- /dev/null+++ b/packages/types/src/eval/evalMemory.ts@@ -0,0 +1,6 @@+/** Memory categories retained as evidence for an evaluation attempt. */+export type EvalMemoryLayer =+ 'activity' | 'context' | 'experience' | 'identity' | 'persona' | 'preference';++/** Whether an entry came from the initial fixture or the running Agent. */+export type EvalMemorySource = 'agent' | 'fixture';diff --git a/packages/types/src/eval/index.ts b/packages/types/src/eval/index.tsindex 65c8e3f83f3..3f58feef238 100644--- a/packages/types/src/eval/index.ts+++ b/packages/types/src/eval/index.ts@@ -4,6 +4,7 @@ export * from './agentEvalExperiment';export * from './agentEvalRun';export * from './benchmark';export * from './dataset';+export * from './evalMemory';export * from './evaluation';export * from './ragas';export * from './rubric';