Skip to main content

Database

AgentCore runs on PostgreSQL 16 with the pgvector extension for vector similarity search. The schema is managed by Prisma 6 and lives in prisma/schema.prisma.

Setup

# Start PostgreSQL
docker compose up -d postgres

# Generate Prisma client
npx prisma generate

# Run migrations
npx prisma migrate dev

# Visual database browser
npm run db:studio

Models Overview

The schema contains 26 models organized into these domains.

RBAC & Organization

ModelPurposeKey fields
SystemRoleCustom and built-in RBAC rolesname, slug, isSystem, allDepartments, departmentIds, permissions
DepartmentTenant/department boundary for most dataname, slug, color, description, settings, isArchived
UserAuthenticated users and HR stateemail, name, phone, passwordHash, legacy role, roleId, departmentId, avatarUrl, tokenVersion, permission and department overrides
PasswordResetTokenPassword reset flowuserId, token, expiresAt, usedAt

User.role keeps the legacy enum (admin, approver, dept_head, employee) for compatibility. Current authorization uses SystemRole plus per-user extraPermissions, revokedPermissions, extraDepartmentIds, and revokedDepartmentIds.

Knowledge Base

ModelPurposeKey fields
KnowledgeBaseDepartment-owned document collectiondepartmentId, name, description, config
DocumentSource document or generated output fileknowledgeBaseId, title, type, originalUrl, status, metadata
ChunkSearchable text chunkdocumentId, content, embedding, syntheticQuestions, metadata
ChunkQuestionSynthetic Q&A retrieval pathchunkId, question, embedding

Chunk.embedding and ChunkQuestion.embedding are vector(1536) columns and must match the configured embedding model dimensions.

Conversations & Namespaces

ModelPurposeKey fields
NamespaceDepartment-specific assistant configname, departmentId, systemPrompt, persona, config
NamespacePluginEnabled integration plugins per namespacenamespaceId, pluginId, config, enabled
ConversationUser conversation threaduserId, channel, status, metadata, namespaceId
MessageConversation messageconversationId, role, content, sources
PiiRedactionMapReversible PII placeholders for conversationsconversationId, placeholder, entityType, encryptedValue

Namespaces scope persona, trust matrix, adapter config, plugins, conversations, document templates, and agent tasks.

Approvals & Intents

ModelPurposeKey fields
ApprovalHITL approval workflowmessageId, approverId, status, editedContent, approverNotes, escalatedToId, escalationReason, intentName
IntentTrustTrust matrix for autonomous sendsnamespaceId, intentName, successfulCount, threshold, isAutonomous, samplingRate
IntentExampleLabeled phrases for vector intent classificationnamespaceId, intentName, phrase, embedding, metadata

Document Generation

ModelPurposeKey fields
TemplateLegacy file-backed templatesname, departmentId, filePath, variables
DocumentTemplateAPI-managed Handlebars templatesnamespaceId, departmentId, name, description, category, templateBody, variables, outputFormat, createdBy
DocumentGenerationRender history and generated outputtemplateId, userId, input, output, outputFileId, status, error

Generated files can be saved back into Document through outputFileId, which lets generated documents participate in normal knowledge-base workflows.

Employee Memory & Agent Execution

ModelPurposeKey fields
EmployeeProfileExtracted user memory/profileuserId, summary, currentProjects, preferences, frequentIntents, accessLevel, profileVersion, lastExtractedAt
AgentTaskAgent-runner task recordnamespaceId, conversationId, messageId, adapterType, status, token/cost/duration fields, metadata, timestamps
AgentToolCallStep-level agent execution traceagentTaskId, stepName, status, inputData, outputData, durationMs, errorMessage

Observability & Notifications

ModelPurposeKey fields
AuditLogBusiness and security audit trailuserId, action, entityType, entityId, changes, ipAddress, userAgent
AgentRunLangfuse/OpenAI trace summarytraceId, conversationId, provider, model, token/cost/latency fields, status
RetrievalHitRAG retrieval evidence for a traceagentRunId, chunkId, documentId, rank, score, rerankScore
NotificationUser notification centeruserId, type, title, body, entityType, entityId, readAt

Enums

Role:                admin | approver | dept_head | employee
DocumentType: pdf | docx | txt | url | image
DocumentStatus: pending | processing | ready | failed
ConversationChannel: web | whatsapp | telegram | slack | email
ConversationStatus: active | closed | escalated | awaiting_approval
MessageRole: user | assistant | system
ApprovalStatus: pending | approved | rejected | edited | escalated
AgentTaskStatus: queued | running | done | failed | timeout

Operational Notes

  • Department isolation goes through a direct departmentId or a related Namespace, User, or KnowledgeBase record.
  • Users and departments use soft deactivation (isActive = false, isArchived = true).
  • JWT invalidation uses User.tokenVersion. Password resets, logout-all, department transfers, and deactivation increment it.
  • Document uploads and generated outputs both use Document. Generated outputs carry metadata.source = "document_generation".

Migrations

Migrations are in prisma/migrations/.

npx prisma migrate dev --name <migration_name>

For production deployment:

npx prisma migrate deploy