Creates a new SQL storage adapter instance.
Storage configuration
const storage = new SqlStorageAdapter({
filePath: './agentos.db',
priority: ['better-sqlite3']
});
Initializes the storage adapter and creates the database schema.
Schema created:
conversations table with indexes on userId and agentIdmessages table with indexes on conversationId and timestampMust be called before any other operations.
If database connection or schema creation fails
await storage.initialize();
console.log('Storage ready!');
Creates a new conversation record.
Conversation to create
The created conversation
If conversation with same ID exists or validation fails
Retrieves a conversation by ID.
The conversation ID
The conversation or null if not found
Updates a conversation's fields.
Conversation to update
Fields to update
Updated conversation
If conversation doesn't exist
Lists conversations for a user with optional filtering.
User whose conversations to list
Optional options: { Query options
Optional limit?: numberOptional offset?: numberOptional agentArray of conversations
Stores a message and updates conversation's lastActivity.
Message to store
The stored message
If conversation doesn't exist
Retrieves a message by ID.
Message ID
The message or null
Retrieves messages for a conversation with filtering.
Conversation ID
Optional options: IMessageQueryOptionsQuery options
Array of messages
Calculates total token usage for a conversation.
Conversation to analyze
Aggregated token usage
SQL storage adapter implementation for AgentOS.
Provides full persistence for conversations and messages using a SQL database. Wraps @framers/sql-storage-adapter to provide AgentOS-specific schema and operations.
Features:
Database Schema:
conversationstable: Stores conversation metadatamessagestable: Stores individual messages with foreign key to conversationsSqlStorageAdapter
Implements
Example