FromLastNMessages

A strategy for compressing history by retaining only the last n messages in a session.

This class removes all but the last n messages from the current prompt history and then compresses the retained messages into a summary (TL;DR). It also allows integration of specific memory messages back into the prompt if needed.

Constructors

Link copied to clipboard
constructor(n: Int)

Properties

Link copied to clipboard
val n: Int

The number of most recent messages to retain during compression.

Functions

Link copied to clipboard
open suspend override fun compress(llmSession: AIAgentLLMWriteSession, preserveMemory: Boolean, memoryMessages: List<Message>)

Compresses the conversation history by retaining the last N messages, generating a summary, and composing the resulting prompt with the necessary messages.