Class: InMemoryStorageAdapter
Defined in: packages/agentos/src/core/storage/InMemoryStorageAdapter.ts:91
In-memory storage adapter for AgentOS.
Provides a complete implementation of IStorageAdapter without any persistence. All data is stored in JavaScript Map and Array structures.
Use Cases:
- Unit and integration testing
- Development environments
- Stateless sessions
- CI/CD pipelines
- Prototyping and demos
Characteristics:
- Zero setup (no database required)
- Extremely fast (no I/O)
- Non-persistent (data lost on process exit)
- Thread-safe in single-threaded environments
Implements
Example
// Perfect for testing
const storage = new InMemoryStorageAdapter();
await storage.initialize();
const conversation = await storage.createConversation({
id: 'test-conv',
userId: 'test-user',
createdAt: Date.now(),
lastActivity: Date.now()
});
// No cleanup needed for tests
await storage.close();
Implements
Constructors
Constructor
new InMemoryStorageAdapter():
InMemoryStorageAdapter
Defined in: packages/agentos/src/core/storage/InMemoryStorageAdapter.ts:107
Creates a new in-memory storage adapter.
No configuration needed since everything is in memory.
Returns
InMemoryStorageAdapter
Example
const storage = new InMemoryStorageAdapter();
Methods
close()
close():
Promise<void>
Defined in: packages/agentos/src/core/storage/InMemoryStorageAdapter.ts:129
Closes the storage adapter and clears all data.
Warning: This deletes all conversations and messages from memory.
Returns
Promise<void>
Implementation of
createConversation()
createConversation(
conversation):Promise<IConversation>
Defined in: packages/agentos/src/core/storage/InMemoryStorageAdapter.ts:145
Creates a new conversation.
Parameters
conversation
Conversation to create
Returns
Promise<IConversation>
The created conversation
Throws
If conversation with same ID already exists
Implementation of
IStorageAdapter.createConversation
deleteConversation()
deleteConversation(
conversationId):Promise<boolean>
Defined in: packages/agentos/src/core/storage/InMemoryStorageAdapter.ts:205
Deletes a conversation and all its messages.
Parameters
conversationId
string
Conversation to delete
Returns
Promise<boolean>
True if deleted, false if not found
Implementation of
IStorageAdapter.deleteConversation
deleteMessage()
deleteMessage(
messageId):Promise<boolean>
Defined in: packages/agentos/src/core/storage/InMemoryStorageAdapter.ts:352
Deletes a message.
Parameters
messageId
string
Message to delete
Returns
Promise<boolean>
True if deleted
Implementation of
deleteMessagesForConversation()
deleteMessagesForConversation(
conversationId):Promise<number>
Defined in: packages/agentos/src/core/storage/InMemoryStorageAdapter.ts:380
Deletes all messages in a conversation.
Parameters
conversationId
string
Conversation whose messages to delete
Returns
Promise<number>
Number of messages deleted
Implementation of
IStorageAdapter.deleteMessagesForConversation
getConversation()
getConversation(
conversationId):Promise<IConversation|null>
Defined in: packages/agentos/src/core/storage/InMemoryStorageAdapter.ts:167
Retrieves a conversation by ID.
Parameters
conversationId
string
Conversation ID
Returns
Promise<IConversation | null>
The conversation or null
Implementation of
IStorageAdapter.getConversation
getConversationTokenUsage()
getConversationTokenUsage(
conversationId):Promise<ITokenUsage>
Defined in: packages/agentos/src/core/storage/InMemoryStorageAdapter.ts:416
Calculates total token usage for a conversation.
Parameters
conversationId
string
Conversation to analyze
Returns
Promise<ITokenUsage>
Aggregated token usage
Implementation of
IStorageAdapter.getConversationTokenUsage
getMessage()
getMessage(
messageId):Promise<IConversationMessage|null>
Defined in: packages/agentos/src/core/storage/InMemoryStorageAdapter.ts:297
Retrieves a message by ID.
Parameters
messageId
string
Message ID
Returns
Promise<IConversationMessage | null>
The message or null
Implementation of
getMessageCount()
getMessageCount(
conversationId):Promise<number>
Defined in: packages/agentos/src/core/storage/InMemoryStorageAdapter.ts:403
Counts messages in a conversation.
Parameters
conversationId
string
Conversation to count
Returns
Promise<number>
Message count
Implementation of
IStorageAdapter.getMessageCount
getMessages()
getMessages(
conversationId,options?):Promise<IConversationMessage[]>
Defined in: packages/agentos/src/core/storage/InMemoryStorageAdapter.ts:311
Retrieves messages for a conversation with filtering.
Parameters
conversationId
string
Conversation ID
options?
Query options
Returns
Promise<IConversationMessage[]>
Array of messages
Implementation of
initialize()
initialize():
Promise<void>
Defined in: packages/agentos/src/core/storage/InMemoryStorageAdapter.ts:118
Initializes the storage adapter.
For in-memory adapter, this just sets the initialized flag.
Returns
Promise<void>
Implementation of
listConversations()
listConversations(
userId,options?):Promise<IConversation[]>
Defined in: packages/agentos/src/core/storage/InMemoryStorageAdapter.ts:232
Lists conversations for a user.
Parameters
userId
string
User whose conversations to list
options?
Query options
agentId?
string
limit?
number
offset?
number
Returns
Promise<IConversation[]>
Array of conversations
Implementation of
IStorageAdapter.listConversations
storeMessage()
storeMessage(
message):Promise<IConversationMessage>
Defined in: packages/agentos/src/core/storage/InMemoryStorageAdapter.ts:265
Stores a message.
Parameters
message
Message to store
Returns
Promise<IConversationMessage>
The stored message
Throws
If conversation doesn't exist, or a message with the same ID is already stored (SqlStorageAdapter's primary key refuses it too)
Implementation of
updateConversation()
updateConversation(
conversationId,updates):Promise<IConversation>
Defined in: packages/agentos/src/core/storage/InMemoryStorageAdapter.ts:182
Updates a conversation.
Parameters
conversationId
string
Conversation to update
updates
Partial<IConversation>
Fields to update
Returns
Promise<IConversation>
Updated conversation
Throws
If conversation doesn't exist