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 / WriteStorage interfaces from the rag-base module; an in-memory InMemoryRecordStorage is included for testing

  • On-completion ingestion: The accumulated session prompt/history is ingested once when the agent run completes

  • Prompt augmentation modes: System prompt, 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
../../../../../../rag/rag-base/src/commonMain/kotlin/ai/koog/rag/base/storage/SearchStorage.ktInterface for searching memory records (defined in rag-base)
../../../../../../rag/rag-base/src/commonMain/kotlin/ai/koog/rag/base/storage/WriteStorage.ktInterface for adding memory records (defined in rag-base)
src/commonMain/kotlin/ai/koog/agents/longtermmemory/retrieval/search/SearchStrategy.ktConverts user query into a SearchRequest; SimilaritySearchStrategy is the default implementation
src/commonMain/kotlin/ai/koog/agents/longtermmemory/retrieval/search/SearchQueryProvider.ktProvides the search query string from a Prompt for retrieval
src/commonMain/kotlin/ai/koog/agents/longtermmemory/retrieval/search/LastUserMessageQueryProvider.ktDefault SearchQueryProvider that uses the last user message content
src/commonMain/kotlin/ai/koog/agents/longtermmemory/ingestion/extraction/DocumentExtractor.ktTransforms messages into TextDocuments for storage
src/commonMain/kotlin/ai/koog/agents/longtermmemory/ingestion/extraction/MessagePassingDocumentExtractor.ktDefault DocumentExtractor; filters messages by role (User/Assistant by default)
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
common
Link copied to clipboard
common