Skip to content

Database Schema Reference

Agentcy uses three databases, each serving a distinct purpose:

DatabasePurposeLibrary
PostgreSQLRelational data -- users, organizations, configurations, audit logssqlx 0.7
Neo4jKnowledge graph -- nodes, relationships, vector embeddingsneo4rs 0.7
RedisCaching, job queues, real-time streamsredis 0.25

PostgreSQL Tables

All tables use UUID primary keys (via gen_random_uuid()), TIMESTAMPTZ timestamps, and updated_at auto-update triggers.

organizations

Tenants in the multi-tenant system. Each organization has isolated data.

ColumnTypeDefaultDescription
idUUID (PK)gen_random_uuid()Organization identifier
nameVARCHAR(255)Unique slug-style name
display_nameVARCHAR(255)Human-readable name
settingsJSONB{}Organization settings (LLM config, features)
created_atTIMESTAMPTZNOW()Creation timestamp
updated_atTIMESTAMPTZNOW()Last update timestamp

users

User accounts within an organization.

ColumnTypeDefaultDescription
idUUID (PK)gen_random_uuid()User identifier
organization_idUUID (FK)Parent organization
external_idVARCHAR(255)External identity (e.g., OIDC sub claim)
emailVARCHAR(255)Email address
nameVARCHAR(255)Display name
rolesTEXT[]{}Role assignments (e.g., ["admin"])
permissionsTEXT[]{}Direct permission grants
password_hashVARCHAR(255)Bcrypt hash (local auth only)
auth_providerVARCHAR(50)'local'Auth provider (local or oidc)
email_verifiedBOOLEANfalseWhether email has been verified
last_login_atTIMESTAMPTZLast successful login
created_atTIMESTAMPTZNOW()Creation timestamp
updated_atTIMESTAMPTZNOW()Last update timestamp

Unique constraint: (organization_id, external_id).

api_keys

API keys for programmatic access.

ColumnTypeDefaultDescription
idUUID (PK)gen_random_uuid()Key identifier
organization_idUUID (FK)Parent organization
user_idUUID (FK)Owner user
nameVARCHAR(255)Descriptive name
key_hashVARCHAR(512)SHA-256 hash of the API key
permissionsTEXT[]{}Scoped permissions
activeBOOLEANtrueWhether the key is active
expires_atTIMESTAMPTZOptional expiration
last_used_atTIMESTAMPTZLast usage timestamp
created_atTIMESTAMPTZNOW()Creation timestamp

source_configs

Data source connector configurations.

ColumnTypeDefaultDescription
idUUID (PK)gen_random_uuid()Source identifier
organization_idUUID (FK)Parent organization
source_typeVARCHAR(100)Connector type (e.g., github_pat, aws, sql)
nameVARCHAR(255)Display name
configJSONB{}Connector-specific configuration (encrypted at rest)
scheduleVARCHAR(255)Cron expression for automated syncs
enabledBOOLEANtrueWhether sync is enabled
last_sync_atTIMESTAMPTZLast sync timestamp
last_sync_statusVARCHAR(50)Last sync result (success, error)
last_sync_errorTEXTError message from last failed sync
node_countBIGINT0Nodes created by this source
relationship_countBIGINT0Relationships created by this source
created_atTIMESTAMPTZNOW()Creation timestamp
updated_atTIMESTAMPTZNOW()Last update timestamp

ingestion_jobs

Background ingestion job tracking.

ColumnTypeDefaultDescription
idUUID (PK)gen_random_uuid()Job identifier
organization_idUUID (FK)Parent organization
source_config_idUUID (FK)Source that triggered the job
source_typeVARCHAR(100)Source type (denormalized)
statusVARCHAR(50)'pending'Job status (pending, running, completed, failed, cancelled)
configJSONB{}Job-specific configuration
run_idVARCHAR(255)Unique run identifier
progressFLOAT0Completion progress (0.0 to 1.0)
phaseVARCHAR(50)Current phase (e.g., extracting, transforming, loading)
records_processedBIGINT0Total records processed
nodes_createdBIGINT0Graph nodes created
relationships_createdBIGINT0Graph relationships created
nodes_cleanedBIGINT0Stale nodes removed
errorTEXTError message (if failed)
worker_idVARCHAR(255)Worker that executed the job
created_atTIMESTAMPTZNOW()Creation timestamp
started_atTIMESTAMPTZExecution start time
completed_atTIMESTAMPTZExecution end time
duration_msBIGINTTotal execution duration

conversations

Chat conversation sessions.

ColumnTypeDefaultDescription
idUUID (PK)gen_random_uuid()Conversation identifier
organization_idUUID (FK)Parent organization
user_idUUID (FK)Owner user
titleVARCHAR(500)Conversation title
modelVARCHAR(100)LLM model used
message_countINT0Total messages in conversation
created_atTIMESTAMPTZNOW()Creation timestamp
updated_atTIMESTAMPTZNOW()Last activity timestamp

messages

Individual chat messages within conversations.

ColumnTypeDefaultDescription
idUUID (PK)gen_random_uuid()Message identifier
conversation_idUUID (FK)Parent conversation
roleVARCHAR(20)Message role: system, user, assistant, tool
contentTEXTMessage content
tool_callsJSONBTool call definitions (for assistant messages)
tool_call_idVARCHAR(255)Tool call ID (for tool result messages)
token_countINTToken count for billing/tracking
modelVARCHAR(100)Model that generated the message
created_atTIMESTAMPTZNOW()Creation timestamp

agent_configs

Autonomous agent configuration.

ColumnTypeDefaultDescription
idUUID (PK)gen_random_uuid()Agent identifier
organization_idUUID (FK)Parent organization
agent_typeVARCHAR(100)Agent type (e.g., schema_analyzer, dependency_mapper)
nameVARCHAR(255)Display name
configJSONB{}Agent-specific configuration
scheduleJSONB{"type": "oneshot"}Schedule configuration
enabledBOOLEANtrueWhether the agent is active
created_atTIMESTAMPTZNOW()Creation timestamp
updated_atTIMESTAMPTZNOW()Last update timestamp

agent_runs

Agent execution history.

ColumnTypeDefaultDescription
idUUID (PK)gen_random_uuid()Run identifier
agent_config_idUUID (FK)Parent agent
organization_idUUIDOrganization (denormalized)
statusVARCHAR(50)'running'Run status
nodes_createdBIGINT0Nodes created during run
nodes_updatedBIGINT0Nodes updated during run
relationships_createdBIGINT0Relationships created
insightsJSONB[]Generated insights
errorTEXTError (if failed)
started_atTIMESTAMPTZNOW()Start time
completed_atTIMESTAMPTZCompletion time

sub_agents

OpenFang sub-agent registrations.

ColumnTypeDefaultDescription
idUUID (PK)gen_random_uuid()Sub-agent identifier
organization_idUUID (FK)Parent organization
openfang_agent_idVARCHAR(255)Remote agent ID in the orchestration engine
nameVARCHAR(255)Display name
descriptionTEXTDescription
templateVARCHAR(100)Template used to create the agent
configJSONB{}Agent configuration
gateway_idUUID (FK)Orchestration gateway
created_atTIMESTAMPTZNOW()Creation timestamp
updated_atTIMESTAMPTZNOW()Last update timestamp

sub_agent_workflows

Workflow definitions for the orchestration engine.

ColumnTypeDefaultDescription
idUUID (PK)gen_random_uuid()Workflow identifier
organization_idUUID (FK)Parent organization
openfang_workflow_idVARCHAR(255)Remote workflow ID
nameVARCHAR(255)Workflow name
descriptionTEXTDescription
stepsJSONB[]Workflow step definitions
gateway_idUUID (FK)Orchestration gateway
created_atTIMESTAMPTZNOW()Creation timestamp
updated_atTIMESTAMPTZNOW()Last update timestamp

sub_agent_triggers

Event triggers that start agents or workflows.

ColumnTypeDefaultDescription
idUUID (PK)gen_random_uuid()Trigger identifier
organization_idUUID (FK)Parent organization
openfang_trigger_idVARCHAR(255)Remote trigger ID
agent_idUUID (FK)Target agent (nullable)
patternJSONBTrigger pattern (schedule, webhook, lifecycle)
prompt_templateTEXTPrompt template for the triggered action
enabledBOOLEANtrueWhether the trigger is active
gateway_idUUID (FK)Orchestration gateway
created_atTIMESTAMPTZNOW()Creation timestamp

orchestration_gateways

Orchestration engine connections.

ColumnTypeDefaultDescription
idUUID (PK)gen_random_uuid()Gateway identifier
organization_idUUID (FK)Parent organization
nameVARCHAR(255)Display name
engine_typeVARCHAR(50)'openfang'Engine type: openfang, langchain, crewai, custom
base_urlTEXTEngine base URL
api_keyTEXTAuthentication key
contextJSONB{}Arbitrary configuration
is_defaultBOOLEANfalseDefault gateway for the organization
is_activeBOOLEANtrueWhether the gateway is active
last_health_checkTIMESTAMPTZLast health check time
last_health_statusVARCHAR(50)Health status: ok, error, unreachable
worker_token_idUUID (FK)Linked worker token
created_atTIMESTAMPTZNOW()Creation timestamp
updated_atTIMESTAMPTZNOW()Last update timestamp

Unique index: one default gateway per organization.

worker_tokens

Pre-created tokens for worker registration.

ColumnTypeDefaultDescription
idUUID (PK)gen_random_uuid()Token identifier
organization_idUUID (FK)Parent organization
nameVARCHAR(255)Token name
token_hashVARCHAR(255)SHA-256 hash (unique)
labelsJSONB{}Worker labels
capabilitiesTEXT[]["execute", "ingest"]Allowed capabilities
max_concurrent_tasksINTEGER4Concurrency limit
created_byVARCHAR(255)Creating user
last_used_atTIMESTAMPTZLast usage
revoked_atTIMESTAMPTZRevocation timestamp
worker_idUUIDRegistered worker ID
created_atTIMESTAMPTZNOW()Creation timestamp

role_definitions

RBAC role definitions for the zero-trust system.

ColumnTypeDefaultDescription
idUUID (PK)gen_random_uuid()Role identifier
organization_idUUID (FK)Parent organization
nameVARCHAR(100)Role name (unique per org)
descriptionTEXTHuman-readable description
permissionsTEXT[]{}Granted permissions
is_builtinBOOLEANfalseWhether this is a system-defined role
created_atTIMESTAMPTZNOW()Creation timestamp
updated_atTIMESTAMPTZNOW()Last update timestamp

Built-in roles: admin, editor, viewer, operator.

policy_sources

OPA policy sources -- git repositories or inline policy containers.

ColumnTypeDefaultDescription
idUUID (PK)gen_random_uuid()Source identifier
organization_idUUID (FK)Parent organization
nameVARCHAR(255)Source name
source_typeVARCHAR(50)git_repo or inline
git_urlTEXTGit repository URL
git_branchVARCHAR(255)'main'Branch to sync
git_pathVARCHAR(500)'/'Path within repo
git_ssh_key_encryptedTEXTEncrypted SSH key for private repos
last_synced_atTIMESTAMPTZLast sync timestamp
sync_statusVARCHAR(50)'never'Sync status
sync_errorTEXTLast sync error
enabledBOOLEANtrueWhether the source is active
created_atTIMESTAMPTZNOW()Creation timestamp
updated_atTIMESTAMPTZNOW()Last update timestamp

policies

Individual OPA/Rego policy rules.

ColumnTypeDefaultDescription
idUUID (PK)gen_random_uuid()Policy identifier
organization_idUUID (FK)Parent organization
source_idUUID (FK)Parent policy source (nullable for inline)
nameVARCHAR(255)Policy name
descriptionTEXTDescription
package_pathVARCHAR(500)Rego package path (e.g., agentcy.connectors.sql)
rego_codeTEXTRego source code
enabledBOOLEANtrueWhether the policy is active
file_pathVARCHAR(500)Original file path (for git sources)
created_atTIMESTAMPTZNOW()Creation timestamp
updated_atTIMESTAMPTZNOW()Last update timestamp

policy_audit_log

Audit trail for all policy evaluations.

ColumnTypeDefaultDescription
idUUID (PK)gen_random_uuid()Audit entry identifier
organization_idUUIDOrganization
user_idVARCHAR(255)User who triggered the action
actionVARCHAR(255)Action attempted
resource_typeVARCHAR(100)Resource type
resource_idVARCHAR(255)Resource identifier
decisionVARCHAR(20)allow or deny
matched_policyVARCHAR(255)Policy that matched (if denied)
reasonTEXTHuman-readable reason
input_snapshotJSONBFull policy input for forensics
created_atTIMESTAMPTZNOW()Timestamp

audit_log

General system audit log.

ColumnTypeDefaultDescription
idUUID (PK)gen_random_uuid()Entry identifier
organization_idUUIDOrganization
user_idUUIDUser who performed the action
actionVARCHAR(100)Action performed
resource_typeVARCHAR(100)Target resource type
resource_idVARCHAR(255)Target resource ID
detailsJSONB{}Additional details
ip_addressVARCHAR(45)Client IP address
created_atTIMESTAMPTZNOW()Timestamp

Neo4j Graph Model

The knowledge graph stores ingested data from all connectors. Node labels and relationship types depend on the connected sources.

Common Node Labels

LabelSourceDescription
RepositoryGitHubGit repository
PullRequestGitHubPull request
IssueGitHubIssue
GitHubUserGitHubGitHub user account
BranchGitHubGit branch
CommitGitHubGit commit
EC2InstanceAWSEC2 virtual machine
S3BucketAWSS3 storage bucket
SecurityGroupAWSEC2 security group
IAMRoleAWSIAM role
VPCAWSVirtual private cloud
LambdaAWSLambda function
RDSInstanceAWSRDS database instance
GCEInstanceGCPCompute Engine instance
GKEClusterGCPKubernetes Engine cluster
CloudSQLInstanceGCPCloud SQL instance
PodKubernetesKubernetes pod
ServiceKubernetesKubernetes service
DeploymentKubernetesKubernetes deployment
NamespaceKubernetesKubernetes namespace
ConfigMapKubernetesKubernetes config map
TableSQLDatabase table
ColumnSQLTable column
ForeignKeySQLForeign key constraint
IndexSQLTable index
CollectionMongoDBMongoDB collection
FieldMongoDBDocument field
APIEndpointOpenAPIREST API endpoint
VercelProjectVercelVercel project
SupabaseProjectSupabaseSupabase project

Common Relationship Types

RelationshipDescription
OWNED_BYOwnership (repo by org, bucket by account)
PR_OFPull request belongs to repository
ISSUE_OFIssue belongs to repository
BRANCH_OFBranch belongs to repository
COMMITTED_TOCommit on a branch
AUTHORED_BYAuthorship (PR, commit, issue)
MEMBER_OFUser membership in organization
IN_VPCResource resides in a VPC
IN_SECURITY_GROUPEC2 instance in a security group
IN_NAMESPACEKubernetes resource in a namespace
PART_OFPod part of deployment
EXPOSESService exposes a port
CONNECTS_TONetwork connection between resources
COLUMN_OFColumn belongs to table
REFERENCESForeign key references another table
INDEX_OFIndex on a table
FIELD_OFField belongs to collection
IN_SCHEMATable/view in a database schema
IN_DATABASESchema in a database
DEPENDS_ONDependency relationship
USESResource uses another resource (e.g., Lambda uses IAM role)

Node Properties

All nodes include these common properties:

PropertyTypeDescription
_idStringInternal node identifier
_source_idStringSource connector that created this node
_source_typeStringSource type (e.g., aws, github_pat)
_organization_idStringOwning organization
_ingested_atDateTimeWhen the node was created/updated
_labelsList[String]Neo4j labels

Vector Indexes

When RAG is initialized, a vector index is created for semantic search:

Index NameDimensionsSimilarityDescription
node_embeddings1536 (OpenAI) or 1024 (Anthropic)CosineVector embeddings of node descriptions

Initialize the index:

bash
curl -X POST http://localhost:18080/api/v1/rag/index/initialize \
  -H "Authorization: Bearer $TOKEN"

Redis Key Patterns

Redis is used for caching, job coordination, and real-time event streaming.

Key Patterns

PatternTypeTTLDescription
job:{job_id}Hash24hJob status and metadata
job:{job_id}:progressString24hJob progress percentage
source:{source_id}:lockString5mSync lock to prevent concurrent syncs
source:{source_id}:statusHashCurrent source sync status
worker:{worker_id}HashWorker registration and heartbeat data
worker:{worker_id}:tasksListPending tasks for a worker
session:{session_id}Hash1hChat session state
cache:graph:stats:{org_id}String5mCached graph statistics
cache:catalog:{org_id}String10mCached source catalog

Streams

StreamDescription
events:ingestionIngestion progress events for all sources
events:connector:{source_id}Connector-specific events (tool execution, sync progress)
events:agent:{agent_id}Agent execution events

Pub/Sub Channels

ChannelDescription
sync:{source_id}Sync completion notifications
approval:{conversation_id}Tool approval request/response signals

Built by AgentcyLabs. For in-house deployment or Agentcy Cloud (PaaS) access, visit agentcylabs.com.