CREATE SCHEMA core;-- Tenant table (Enterprise / Team)CREATE TABLE core.tenants (id UUID PRIMARY KEY DEFAULT gen_random_uuid(),name TEXT NOT NULL,plan TEXT DEFAULT 'free',config JSONB DEFAULT '{}',created_at TIMESTAMPTZ DEFAULT NOW());-- Agent RegistryCREATE TABLE core.agents (id UUID PRIMARY KEY DEFAULT gen_random_uuid(),tenant_id UUID NOT NULL REFERENCES core.tenants(id),name TEXT NOT NULL,role TEXT NOT NULL, -- planner / researcher / coder / reviewercapabilities TEXT[], -- Capability Tagsconfig JSONB DEFAULT '{}',created_at TIMESTAMPTZ DEFAULT NOW());-- Project tableCREATE TABLE core.projects (id UUID PRIMARY KEY DEFAULT gen_random_uuid(),tenant_id UUID NOT NULL REFERENCES core.tenants(id),name TEXT NOT NULL,description TEXT,status TEXT DEFAULT 'active',created_at TIMESTAMPTZ DEFAULT NOW());-- Project members (Agents participating in a project)CREATE TABLE core.project_members (project_id UUID REFERENCES core.projects(id),agent_id UUID REFERENCES core.agents(id),role TEXT DEFAULT 'member', -- owner / member / readonlyjoined_at TIMESTAMPTZ DEFAULT NOW(),PRIMARY KEY (project_id, agent_id));
-- Project-level shared memoryCREATE TABLE memory.shared_records (id UUID PRIMARY KEY DEFAULT gen_random_uuid(),tenant_id UUID NOT NULL,project_id UUID NOT NULL,author_agent_id UUID NOT NULL, -- Memory creatorcontent TEXT NOT NULL,embedding vector(1024),record_type TEXT DEFAULT 'finding', -- finding / decision / context / artifactvisibility TEXT DEFAULT 'project', -- project / team / privatemetadata JSONB DEFAULT '{}',created_at TIMESTAMPTZ DEFAULT NOW());-- RLS: Agents within the same project can access each other's memory.ALTER TABLE memory.shared_records ENABLE ROW LEVEL SECURITY;CREATE POLICY project_access ON memory.shared_recordsUSING (project_id IN (SELECT project_id FROM core.project_membersWHERE agent_id = current_setting('app.agent_id')::uuid));
-- Researcher Agent writes research conclusions.SET app.agent_id = 'researcher-001';INSERT INTO memory.shared_records(tenant_id, project_id, author_agent_id, content, embedding, record_type)VALUES (:tenant_id,:project_id,'researcher-001',The vector search performance of the competing product PolarDB achieves a QPS of approximately 2000 on datasets at the million-row scale.tencentdb_ai.get_embedding('bge-m3', 'Vector search performance of the competing product PolarDB'),'finding');-- Planner Agent searches for Researcher's findings.SET app.agent_id = 'planner-001';SELECT content, author_agent_id, created_atFROM memory.shared_recordsWHERE project_id = :project_idORDER BY embedding <=> tencentdb_ai.get_embedding('bge-m3', 'Competing product performance data')LIMIT 5;
-- Task tableCREATE TABLE core.tasks (id UUID PRIMARY KEY DEFAULT gen_random_uuid(),project_id UUID NOT NULL,assigner_id UUID NOT NULL, -- Assignerassignee_id UUID NOT NULL, -- Assigneetitle TEXT NOT NULL,description TEXT,status TEXT DEFAULT 'pending', -- pending / in_progress / completed / failedresult TEXT,created_at TIMESTAMPTZ DEFAULT NOW(),completed_at TIMESTAMPTZ);-- Planner assigns tasks to Researcher.INSERT INTO core.tasks (project_id, assigner_id, assignee_id, title, description)VALUES (:project_id, 'planner-001', 'researcher-001','Investigate DiskANN index performance', 'Compare the performance of HNSW and DiskANN on 10 million vectors');-- Update after Researcher completes.UPDATE core.tasksSET status = 'completed',result = 'DiskANN achieves a 40% QPS improvement and a 60% memory reduction on 10 million vectors.',completed_at = NOW()WHERE id = :task_id;
-- Record team decisions.INSERT INTO memory.shared_records(tenant_id, project_id, author_agent_id, content, record_type, metadata)VALUES (:tenant_id, :project_id, 'planner-001','Decided to adopt pgvectorscale DiskANN as the vector index solution.','decision','{"reason": "Better performance and lower memory usage", "alternatives": ["HNSW", "IVFFlat"]}');
Level | Description | RLS Policy |
private | Visible only to the creator | author_agent_id = current_agent |
project | Visible to project members | All Agents in the same project |
team | Visible to all Agents within the tenant. | Same tenant_id |
-- readonly members can only be read, not written.CREATE POLICY readonly_member ON memory.shared_recordsFOR INSERTWITH CHECK (EXISTS (SELECT 1 FROM core.project_membersWHERE project_id = memory.shared_records.project_idAND agent_id = current_setting('app.agent_id')::uuidAND role IN ('owner', 'member')));
Was this page helpful?
You can also Contact sales or Submit a Ticket for help.
Help us improve! Rate your documentation experience in 5 mins.
Feedback