Package com.tnsai.memory
package com.tnsai.memory
Memory management and persistence for agent conversation history.
This package provides abstractions and implementations for storing and retrieving agent memory, including conversation history and contextual information.
Memory Architecture
┌─────────────────────────────────────────────────────────────┐
│ MemoryStore │
│ (Interface) │
└──────────────────────────┬──────────────────────────────────┘
│
┌────────────────┼────────────────┐
│ │ │
▼ ▼ ▼
┌─────────────┐ ┌─────────────┐ ┌─────────────┐
│InMemoryStore│ │FileMemory │ │ (Custom) │
│ (Default) │ │ Store │ │ │
└─────────────┘ └─────────────┘ └─────────────┘
Memory Store Implementations
| Implementation | Persistence | Use Case |
|---|---|---|
| InMemoryStore | Volatile (lost on restart) | Development, stateless agents |
| FileMemoryStore | File-based | Simple persistence |
Usage Example
// Default in-memory store (agent uses this by default)
public class MyAgent extends Agent {
// Uses InMemoryStore automatically
}
// Custom memory store
public class PersistentAgent extends Agent {
@Override
protected MemoryStore getMemoryStore() {
return new FileMemoryStore("./agent-memory.json");
}
}
// Direct usage
MemoryStore store = new InMemoryStore();
store.add(ChatMessage.user("Hello"));
store.add(ChatMessage.assistant("Hi there!"));
List<ChatMessage> history = store.getHistory();
Memory Operations
- add: Add a message to memory
- getHistory: Retrieve conversation history
- clear: Clear all stored messages
- getLastN: Get the last N messages
Memory Context Window
Memory stores can be configured to limit the number of messages retained, helping manage LLM context window limits.
Thread Safety
All built-in memory store implementations are thread-safe, using appropriate synchronization for concurrent access.
- See Also:
-
ClassDescriptionAbstract base class for memory stores.Resolves memory configuration from
@Memoryand@VectorMemoryannotations.Result of memory resolution containing the configured store and optional consolidation pipeline.File-based persistent memory store.In-memory implementation of MemoryStore.Programmatic form of the@MemorySpecannotation — the builder-path counterpart that closes the@MemorySpecparity gap (TNS-546).Fluent builder for the programmatic path.Consolidates conversation memory by summarizing older messages.Defines a hierarchical memory namespace as workspace:session.Abstraction for agent memory (conversation history).Factory for creating MemoryStore instances based onMemorySpecannotation.Memory store with hierarchical namespace support.Registry for shared memory stores across agents.A memory store wrapper that enables memory sharing between agents.