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
RetrievalStorage/IngestionStorageinterfaces; 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 |
| src/commonMain/kotlin/ai/koog/agents/longtermmemory/retrieval/RetrievalStorage.kt | Interface for searching memory records |
| src/commonMain/kotlin/ai/koog/agents/longtermmemory/ingestion/IngestionStorage.kt | Interface for adding memory records |
| src/commonMain/kotlin/ai/koog/agents/longtermmemory/retrieval/SearchStrategy.kt | Converts user query into a SearchRequest (similarity or keyword) |
| src/commonMain/kotlin/ai/koog/agents/longtermmemory/ingestion/extraction/MemoryRecordExtractor.kt | Transforms messages into MemoryRecords 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 |