Skip to main content

Class: InMemoryStorageAdapter

Defined in: packages/agentos/src/core/storage/InMemoryStorageAdapter.ts:66

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

InMemoryStorageAdapter

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:82

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:104

Closes the storage adapter and clears all data.

Warning: This deletes all conversations and messages from memory.

Returns

Promise<void>

Implementation of

IStorageAdapter.close


createConversation()

createConversation(conversation): Promise<IConversation>

Defined in: packages/agentos/src/core/storage/InMemoryStorageAdapter.ts:120

Creates a new conversation.

Parameters

conversation

IConversation

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:179

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:322

Deletes a message.

Parameters

messageId

string

Message to delete

Returns

Promise<boolean>

True if deleted

Implementation of

IStorageAdapter.deleteMessage


deleteMessagesForConversation()

deleteMessagesForConversation(conversationId): Promise<number>

Defined in: packages/agentos/src/core/storage/InMemoryStorageAdapter.ts:350

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:141

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:386

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:267

Retrieves a message by ID.

Parameters

messageId

string

Message ID

Returns

Promise<IConversationMessage | null>

The message or null

Implementation of

IStorageAdapter.getMessage


getMessageCount()

getMessageCount(conversationId): Promise<number>

Defined in: packages/agentos/src/core/storage/InMemoryStorageAdapter.ts:373

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:281

Retrieves messages for a conversation with filtering.

Parameters

conversationId

string

Conversation ID

options?

IMessageQueryOptions

Query options

Returns

Promise<IConversationMessage[]>

Array of messages

Implementation of

IStorageAdapter.getMessages


initialize()

initialize(): Promise<void>

Defined in: packages/agentos/src/core/storage/InMemoryStorageAdapter.ts:93

Initializes the storage adapter.

For in-memory adapter, this just sets the initialized flag.

Returns

Promise<void>

Implementation of

IStorageAdapter.initialize


listConversations()

listConversations(userId, options?): Promise<IConversation[]>

Defined in: packages/agentos/src/core/storage/InMemoryStorageAdapter.ts:206

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:238

Stores a message.

Parameters

message

IConversationMessage

Message to store

Returns

Promise<IConversationMessage>

The stored message

Throws

If conversation doesn't exist

Implementation of

IStorageAdapter.storeMessage


updateConversation()

updateConversation(conversationId, updates): Promise<IConversation>

Defined in: packages/agentos/src/core/storage/InMemoryStorageAdapter.ts:156

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

Implementation of

IStorageAdapter.updateConversation