agents-features-longterm-memory
Provides the LongTermMemory feature for AI agents, enabling persistent storage and retrieval of memory records (documents) across agent runs via vector databases or other storage backends. Supports Retrieval-Augmented Generation (RAG) and message ingestion as two independently configurable flows.
Overview
The agents-features-longterm-memory module adds long-term memory capabilities to Koog AI agents:
Retrieval (RAG): Searches a memory store for context relevant to the user's query and augments the LLM prompt before each call
Ingestion: Extracts and persists conversation messages into a memory store for future retrieval
Flexible storage: Plug any backend via
SearchStorage/WriteStorageinterfaces from therag-basemodule; an in-memoryInMemoryRecordStorageis included for testingConfigurable timing: Ingest per-LLM-call or on agent completion
Prompt augmentation modes: System prompt or user prompt or custom implementation
Key Components
| Component | Description |
|---|---|
| src/commonMain/kotlin/ai/koog/agents/longtermmemory/feature/LongTermMemory.kt | Agent feature with DSL config for retrieval & ingestion |
| ../../../../../../rag/rag-base/src/commonMain/kotlin/ai/koog/rag/base/storage/SearchStorage.kt | Interface for searching memory records (defined in rag-base) |
| ../../../../../../rag/rag-base/src/commonMain/kotlin/ai/koog/rag/base/storage/WriteStorage.kt | Interface for adding memory records (defined in rag-base) |
| src/commonMain/kotlin/ai/koog/agents/longtermmemory/retrieval/SearchStrategy.kt | Converts user query into a SimilaritySearchRequest; SimilaritySearchStrategy is the default and recommended implementation |
| src/commonMain/kotlin/ai/koog/agents/longtermmemory/retrieval/QueryExtractor.kt | Extracts the search query string from a Prompt for retrieval |
| src/commonMain/kotlin/ai/koog/agents/longtermmemory/retrieval/QueryExtractor.kt | Default QueryExtractor that uses the last user message content |
| src/commonMain/kotlin/ai/koog/agents/longtermmemory/ingestion/extraction/ExtractionStrategy.kt | Transforms messages into TextDocuments for storage |
| src/commonMain/kotlin/ai/koog/agents/longtermmemory/retrieval/augmentation/PromptAugmenter.kt | Interface for augmenting prompts with relevant context |
| src/commonMain/kotlin/ai/koog/agents/longtermmemory/retrieval/augmentation/SystemPromptAugmenter.kt | Inserts retrieved context as a system message |
| src/commonMain/kotlin/ai/koog/agents/longtermmemory/retrieval/augmentation/UserPromptAugmenter.kt | Inserts retrieved context as a user message |
| src/commonMain/kotlin/ai/koog/agents/longtermmemory/storage/InMemoryRecordStorage.kt | In-memory storage implementing both retrieval and ingestion interfaces |