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 / IngestionStorage interfaces; an in-memory InMemoryRecordStorage is included for testing

  • Configurable timing: Ingest per-LLM-call or on agent completion

  • Prompt augmentation modes: System prompt or user prompt or custom implementation

Key Components

ComponentDescription
src/commonMain/kotlin/ai/koog/agents/longtermmemory/feature/LongTermMemory.ktAgent feature with DSL config for retrieval & ingestion
src/commonMain/kotlin/ai/koog/agents/longtermmemory/retrieval/RetrievalStorage.ktInterface for searching memory records
src/commonMain/kotlin/ai/koog/agents/longtermmemory/ingestion/IngestionStorage.ktInterface for adding memory records
src/commonMain/kotlin/ai/koog/agents/longtermmemory/retrieval/SearchStrategy.ktConverts user query into a SearchRequest (similarity or keyword)
src/commonMain/kotlin/ai/koog/agents/longtermmemory/ingestion/extraction/MemoryRecordExtractor.ktTransforms messages into MemoryRecords for storage
src/commonMain/kotlin/ai/koog/agents/longtermmemory/retrieval/augmentation/PromptAugmenter.ktInterface for augmenting prompts with relevant context
src/commonMain/kotlin/ai/koog/agents/longtermmemory/retrieval/augmentation/SystemPromptAugmenter.ktInserts retrieved context as a system message
src/commonMain/kotlin/ai/koog/agents/longtermmemory/retrieval/augmentation/UserPromptAugmenter.ktInserts retrieved context as a user message
src/commonMain/kotlin/ai/koog/agents/longtermmemory/storage/InMemoryRecordStorage.ktIn-memory storage implementing both retrieval and ingestion interfaces

Packages

Link copied to clipboard
common
Link copied to clipboard
common
common
Link copied to clipboard
common
Link copied to clipboard
common
Link copied to clipboard
common