Documentation Index
Fetch the complete documentation index at: https://docs.argentos.ai/llms.txt
Use this file to discover all available pages before exploring further.
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
| Problem | SQLite Limitation | PG+Redis Solution |
|---|---|---|
| Multi-agent access | Single-writer lock | Connection pool with concurrent writes |
| Shared knowledge | Per-agent databases | Shared tables with agent_id scoping + RLS |
| Inter-agent communication | No built-in mechanism | Redis Streams + pub/sub |
| Vector search at scale | sqlite-vec extension (limited) | pgvector with HNSW indexes |
| Full-text search | FTS5 (good but single-process) | tsvector with GIN indexes |
| Hot state for dashboard | File polling | Redis key/value with pub/sub |
Three-Phase Migration
Phase 1: Dual-Write (SQLite Reads)
Both databases receive all writes. SQLite serves reads. This validates PG write path without risk.
Phase 2: Dual-Write (PostgreSQL Reads)
Flip
readFrom to "postgres". SQLite still receives writes as a safety net. Verify PG serves all reads correctly.StorageAdapter Interface
TheStorageAdapter interface in src/data/adapter.ts defines the unified API that all backend implementations conform to:
MemoryAdapter
Covers all memory operations:createItem()/getItem()/deleteItem()— CRUDsearchItems()— Hybrid keyword + vector searchcreateEntity()/getEntity()— Entity managementcreateReflection()/createLesson()— SIS substratesembedItem()— Embedding storagegetStats()— Storage statistics
TaskAdapter
Full task lifecycle:createTask()/updateTask()/deleteTask()— CRUDlistTasks()/searchTasks()— Listing and FTSgetTasksByProject()— Project grouping- Dependencies and priority ordering
TeamAdapter
Team and member management for multi-agent workflows.Adapter Implementations
- SQLiteAdapter
- PgAdapter
- DualAdapter
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.tsStorage Factory
src/data/storage-factory.ts creates the correct adapter based on configuration:
PostgreSQL Schema
The PostgreSQL schema is defined insrc/data/pg/schema.ts using Drizzle ORM. It contains 20 tables:
Core Tables
| Table | Description |
|---|---|
agents | Agent registry (multi-agent family) |
memory_items | Durable memory facts |
entities | Named entities with profiles |
reflections | Periodic summaries |
lessons | SIS-derived actionable patterns |
resources | Resource metadata |
categories | Memory categories |
item_categories | Item-category junction |
Knowledge Tables
| Table | Description |
|---|---|
knowledge_collections | Named document buckets |
knowledge_collection_grants | Per-agent ACL grants |
Task Tables
| Table | Description |
|---|---|
tasks | Task records with status, priority |
teams | Team definitions |
team_members | Team membership |
Infrastructure Tables
| Table | Description |
|---|---|
service_keys | Encrypted credential storage |
observations | Session event capture (Memo) |
model_feedback | Model performance tracking |
live_candidates | Memory deduplication candidates |
Indexes
pgvector HNSW indexes for approximate nearest-neighbor embedding 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:| Feature | Redis Structure | Purpose |
|---|---|---|
| Agent state | Key/value | Dashboard displays current agent state |
| Presence | Key with TTL | Track which agents are online |
| Pub/sub | Channels | Real-time event broadcasting |
| Streams | Consumer groups | Inter-agent message queues |
| Heartbeat locks | Keys with TTL | Prevent duplicate heartbeat runs |
Connection
PG Write Mirror
Thepg-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:
| Service | ArgentOS Port | Default Port |
|---|---|---|
| PostgreSQL | 5433 | 5432 |
| Redis | 6380 | 6379 |
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
| File | LOC | Description |
|---|---|---|
src/data/adapter.ts | — | StorageAdapter interface definition |
src/data/sqlite-adapter.ts | — | SQLite implementation (wraps MemuStore) |
src/data/pg-adapter.ts | 1,362 | PostgreSQL implementation (Drizzle ORM) |
src/data/dual-adapter.ts | 618 | Dual-write orchestrator |
src/data/storage-factory.ts | — | Config-driven adapter creation |
src/data/storage-config.ts | — | Feature flags and port constants |
src/data/pg-write-mirror.ts | — | MemuStore write interception |
src/data/pg-client.ts | — | postgres.js connection pool |
src/data/redis-client.ts | — | ioredis connection |
src/data/pg/schema.ts | — | Drizzle ORM schema (20 tables) |
src/data/pg/migrations/ | — | SQL migration files |
scripts/setup-postgres.sh | — | PG17 + pgvector install |
scripts/setup-redis.sh | — | Redis install + LaunchAgent |
