| name | bx-ai-memory |
| description | Use this skill when implementing memory in BoxLang AI: aiMemory() types (windowed, summary, session, file, cache, JDBC, vector), multi-tenant isolation with userId and conversationId, using memory with agents and pipelines, and choosing the right memory type. |
bx-ai: Memory Systems
aiMemory() BIF
aiMemory( type, key="", userId="", conversationId="", config={} )
type — memory type name (see table below)
key — unique identifier for this memory instance
userId — tenant user identifier (multi-tenant isolation)
conversationId — isolate separate conversations for the same user
config — type-specific configuration struct
Memory Types
| Type | Best For | Persistence |
|---|
windowed | Last N messages | In-memory |
summary | Long conversations (auto-summarizes) | In-memory |
session | Single request/session | In-memory |
file | Simple persistence across restarts | File system |
cache | Fast shared memory | CacheBox |
jdbc | Multi-server production use | Database |
chroma | Semantic search (vector) | ChromaDB |
pinecone | Semantic search (vector) | Pinecone |
weaviate | Semantic search (vector) | Weaviate |
in-memory-vector | Dev/test semantic search | In-memory |
Creating Memory
memory = aiMemory( "windowed", config: { maxMessages: 20 } )
memory = aiMemory( "summary", config: {
maxMessages : 10,
summaryProvider: "openai"
})
memory = aiMemory( "session" )
memory = aiMemory( "file", config: {
filePath: expandPath( "./data/conversations" )
})
memory = aiMemory( "jdbc", config: {
datasource: "myApp",
table : "ai_conversations"
})
memory = aiMemory( "cache", config: {
cacheName: "default"
})
Multi-Tenant Isolation
All memory types support isolation via userId and conversationId:
memory = aiMemory( "windowed",
key : createUUID(),
userId: "user-alice",
config: { maxMessages: 10 }
)
supportMemory = aiMemory( "windowed",
key : createUUID(),
userId : "user-alice",
conversationId: "support-ticket-456",
config : { maxMessages: 20 }
)
salesMemory = aiMemory( "windowed",
key : createUUID(),
userId : "user-alice",
conversationId: "sales-inquiry-789",
config : { maxMessages: 20 }
)
Using Memory with an Agent
memory = aiMemory( "windowed",
key : "chat-#session.sessionId#",
userId: auth.getCurrentUserId(),
config: { maxMessages: 30 }
)
agent = aiAgent(
name : "SupportBot",
instructions: "You are a helpful support agent. Remember the user's context.",
memory : memory
)
agent.run( "I'm having trouble with my subscription." )
agent.run( "It's been broken for 3 days." )
agent.run( "Can you summarize my issue?" )
Memory API
memory.add( "user", "My name is Alice" )
memory.add( "assistant", "Hello Alice, how can I help?" )
messages = memory.getMessages()
recent = memory.getMessages( 5 )
memory.clear()
count = memory.size()
Vector Memory (Semantic Search)
For RAG and semantic retrieval, see the RAG skill. Quick reference:
vectorMem = aiMemory( "in-memory-vector", config: {
embeddingProvider: "openai",
embeddingModel : "text-embedding-3-small"
})
vectorMem = aiMemory( "chroma", config: {
collection : "knowledge_base",
embeddingProvider: "openai",
serverUrl : "http://localhost:8000"
})
aliceMem = aiMemory( "chroma",
key : createUUID(),
userId: "alice",
config: { collection: "user_notes", embeddingProvider: "openai" }
)
vectorMem.add( "BoxLang is a modern JVM language" )
results = vectorMem.getRelevant( "What language runs on the JVM?", 5 )
Choosing the Right Memory Type
- Development / testing →
windowed or in-memory-vector
- Single user, single server →
file or cache
- Multi-server production →
jdbc
- RAG / document search →
chroma, pinecone, or weaviate
- Long conversations →
summary to avoid context overflow
- Multi-tenant apps → any type with
userId + conversationId
Common Pitfalls
- ❌ Do NOT store API keys or secrets in memory
- ❌ Do NOT use
session memory for multi-turn conversations across requests
- ✅ Always set
userId in multi-user applications to prevent data leakage
- ✅ Use
summary memory for customer support bots with long conversations
- ✅ Reuse the same memory instance across multiple
agent.run() calls for continuity