Skip to content

andrestubbe/FastAIMemory

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

8 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

FastAIMemory 0.1.0 [ALPHA-2026-06-14] β€” Unified Conversation History and Memory Orchestration for Java

Status License: MIT Java JitPack


πŸ’‘ 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.


Quick Start

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);
    }
}

Why FastAIMemory?

  • Provider Agnostic β€” Decoupled from specific provider APIs. Works seamlessly with OpenAI, Gemini, Claude, Ollama, and local runtimes.
  • Thread Safe β€” Thread-safe ConversationHistory using lock synchronization makes it reliable for concurrent multi-agent environments.
  • Polymorphic Formatters β€” Implement MemoryFormatter to 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.

Installation

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>

API Reference

ConversationHistory

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.

MemoryWindow

Utility for trimming historical context prior to sending requests:

  • trimToMessages(List<ConversationMessage> messages, int maxMessages): Retains the first SYSTEM message, 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.

Related Projects

  • FastAI - Unified AI client interface for Java
  • FastAIModel - Native local inference runtime (GGUF/ONNX)
  • FastCore - Unified JNI loader and platform abstraction

License

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. πŸš€πŸ“‹

About

πŸ€– Unified primitive conversation history and memory orchestration for the FastJava AI ecosystem

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors