Skip to main content

Overview

ArgentOS is migrating from SQLite to PostgreSQL 17 + Redis for its storage backend. The migration enables concurrent multi-agent access, shared knowledge across agents, and inter-agent communication via Redis Streams and pub/sub. The migration follows a three-phase zero-downtime strategy using a abstraction that routes reads and writes to the correct backend based on configuration.

Why PG+Redis

Three-Phase Migration

1

Phase 1: Dual-Write (SQLite Reads)

Both databases receive all writes. SQLite serves reads. This validates PG write path without risk.
2

Phase 2: Dual-Write (PostgreSQL Reads)

Flip readFrom to "postgres". SQLite still receives writes as a safety net. Verify PG serves all reads correctly.
3

Phase 3: PostgreSQL Only

SQLite becomes historical backup. All reads and writes go through PostgreSQL.

StorageAdapter Interface

The StorageAdapter interface in src/data/adapter.ts defines the unified API that all backend implementations conform to:

MemoryAdapter

Covers all memory operations:
  • createItem() / getItem() / deleteItem() — CRUD
  • searchItems() — Hybrid keyword + vector search
  • createEntity() / getEntity() — Entity management
  • createReflection() / createLesson() — SIS substrates
  • embedItem() — Embedding storage
  • getStats() — Storage statistics

TaskAdapter

Full task lifecycle:
  • createTask() / updateTask() / deleteTask() — CRUD
  • listTasks() / searchTasks() — Listing and FTS
  • getTasksByProject() — Project grouping
  • Dependencies and priority ordering

TeamAdapter

Team and member management for multi-agent workflows.

Adapter Implementations

Wraps the existing MemuStore and DataAPI modules. This is the battle-tested default backend that has served ArgentOS since day one.Source: src/data/sqlite-adapter.ts

Storage Factory

src/data/storage-factory.ts creates the correct adapter based on configuration:
The factory is a singleton — subsequent calls return the same adapter instance.

PostgreSQL Schema

The PostgreSQL schema is defined in src/data/pg/schema.ts using Drizzle ORM. It contains 20 tables:

Core Tables

Knowledge Tables

Task Tables

Infrastructure Tables

Indexes

pgvector HNSW indexes for approximate nearest-neighbor embedding search:
tsvector GIN indexes for full-text search:

Row-Level Security (RLS)

RLS policies isolate agent data in shared tables:
The PG adapter sets the app.agent_id session variable on each connection from the pool, ensuring agents can only access their own data unless explicitly granted cross-agent access.

Redis Usage

Redis (port 6380) provides hot-path state and inter-agent communication:

Connection

PG Write Mirror

The pg-write-mirror.ts module intercepts writes to the existing MemuStore (SQLite) and mirrors them to PostgreSQL. This enables gradual migration without changing all callers at once:

Configuration

Full storage configuration in ~/.argentos/argent.json:

Non-Default Ports

ArgentOS uses non-standard ports to avoid conflicts with other services:

Setup Scripts

PG-Only Features

Some features have no SQLite equivalent and require PostgreSQL:
  • Knowledge collections and collection grants (ACL)
  • Shared knowledge library (cross-agent)
  • Agent registry (multi-agent family)
  • Service keys and auth credentials (encrypted)
  • Session tracking and observations

What Is Already Routed Through StorageAdapter

The following operations work with all three backends:
  • All memory operations (create, search, embed, delete)
  • Task CRUD and full-text search
  • Team management
  • Knowledge ingestion, search, and ACL
  • Family workflow and multi-agent task migration

Key Files