@voltx/memory
v0.3.0
Published
VoltX memory — short-term and long-term memory for agents and conversations
Downloads
298
Maintainers
Readme
Conversation memory for the VoltX framework. Store and retrieve chat history for agents and chatbots. Supports in-memory (dev) and Postgres (production) backends.
Installation
npm install @voltx/memoryQuick Start
import { createMemory } from "@voltx/memory";
// In-memory (development)
const memory = createMemory({ maxMessages: 50 });
// Postgres (production)
const memory = createMemory("postgres", {
url: process.env.DATABASE_URL,
});Usage
// Add messages to a conversation
await memory.add("conv-1", { role: "user", content: "Hello!" });
await memory.add("conv-1", { role: "assistant", content: "Hi there!" });
// Retrieve conversation history
const messages = await memory.get("conv-1");
// → [{ role: "user", content: "Hello!" }, { role: "assistant", content: "Hi there!" }]
// List all conversations
const conversations = await memory.list();
// Clear a conversation
await memory.clear("conv-1");With a Chatbot
import { streamText } from "@voltx/ai";
import { createMemory } from "@voltx/memory";
const memory = createMemory({ maxMessages: 50 });
export async function POST(c) {
const { messages, conversationId } = await c.req.json();
// Store user message
await memory.add(conversationId, messages[messages.length - 1]);
// Get full history
const history = await memory.get(conversationId);
const result = await streamText({
model: "cerebras:llama-4-scout-17b-16e",
messages: history.map((m) => ({ role: m.role, content: m.content })),
});
// Store assistant response
result.text.then((text) => {
memory.add(conversationId, { role: "assistant", content: text });
});
return result.toSSEResponse();
}Backends
| Backend | Use Case | Persistence |
|---------|----------|-------------|
| InMemoryStore | Development, testing | Process lifetime only |
| PostgresStore | Production | Persistent (Neon serverless driver) |
Configuration
In-Memory
const memory = createMemory({
maxMessages: 100, // max messages per conversation (default: 100)
});Postgres
const memory = createMemory("postgres", {
url: process.env.DATABASE_URL, // Neon connection string
tableName: "voltx_messages", // custom table name (optional)
});Part of VoltX
This package is part of the VoltX framework. See the monorepo for full documentation.
License
MIT — Made by the Promptly AI Team
