FastAIMemory 0.1.0 [ALPHA-2026-06-14] β Unified Conversation History and Memory Orchestration for Java
π‘ Extremely lightweight, provider-independent, thread-safe conversation history, formatters, and memory-trimming utilities for the FastJava AI Ecosystem.
FastAIMemory is a primitive context manager for Java. It stores conversation messages, optimizes history boundaries (sliding windows, character limits, token estimates), and converts structural data into target-formatted prompt strings (ChatML, Gemini, Claude) to keep LLM context clean and safe.
import fastaimemory.*;
public class Demo {
public static void main(String[] args) {
// 1. Initialize thread-safe conversation history
ConversationHistory history = new ConversationHistory();
history.system("You are a helpful coding assistant.");
history.user("Hello!");
history.assistant("Hi! How can I help you today?");
history.user("Write a quicksort in Java:");
// 2. Format history dynamically for different providers
MemoryContextBuilder builder = new MemoryContextBuilder(new ChatMLFormatter());
String chatMLPrompt = builder.build(history);
System.out.println(chatMLPrompt);
}
}- Provider Agnostic β Decoupled from specific provider APIs. Works seamlessly with OpenAI, Gemini, Claude, Ollama, and local runtimes.
- Thread Safe β Thread-safe
ConversationHistoryusing lock synchronization makes it reliable for concurrent multi-agent environments. - Polymorphic Formatters β Implement
MemoryFormatterto structure output prompts dynamically using plain text, ChatML, or specialized provider tokens. - Zero Dependencies β Built on pure Java 17, keeping compiling speeds lighting fast and jar footprint zero-bloat.
Add the JitPack repository and the dependency to your pom.xml:
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.github.andrestubbe</groupId>
<artifactId>FastAIMemory</artifactId>
<version>0.1.0</version>
</dependency>
</dependencies>Thread-safe container storing conversation turns.
add(ConversationRole role, String text): Appends a raw message.system(String text)/user(String text)/assistant(String text): Helper methods.messages(): Returns a read-only list copy of the messages.clear(): Wipes history.
Utility for trimming historical context prior to sending requests:
-
trimToMessages(List<ConversationMessage> messages, int maxMessages): Retains the firstSYSTEMmessage, keeping only the latest$N$ messages. -
trimToCharacters(List<ConversationMessage> messages, int maxChars): Trims oldest messages until text length fits within limits. -
trimToEstimatedTokens(List<ConversationMessage> messages, int maxTokens): Uses a$chars / 4$ heuristic estimation for context pruning.
- FastAI - Unified AI client interface for Java
- FastAIModel - Native local inference runtime (GGUF/ONNX)
- FastCore - Unified JNI loader and platform abstraction
This project is licensed under the MIT License - see the LICENSE file for details.
Part of the FastJava Ecosystem β Making the JVM faster. Small package. Maximum speed. Zero bloat. ππ