Skip to main content
Version: 0.9.x

Class: MessageCountContextStrategy

Defined in: utils/llms/context_strategy/MessageCountContextStrategy.ts:8

A simple context strategy that retains a fixed number of the most recent messages. This strategy trims the conversation history based purely on the message count.

Implements​

Constructors​

Constructor​

new MessageCountContextStrategy(windowLength?): MessageCountContextStrategy

Defined in: utils/llms/context_strategy/MessageCountContextStrategy.ts:13

Initializes the MessageCountContextStrategy.

Parameters​

windowLength?​

number = 5

The maximum number of recent messages to retain in the context. Defaults to 5.

Returns​

MessageCountContextStrategy

Methods​

buildContext()​

buildContext(systemPrompt, history, _maxContextLength, _getTokenCount): Message[]

Defined in: utils/llms/context_strategy/MessageCountContextStrategy.ts:23

Builds the context by slicing the history to retain only the most recent windowLength messages.

Parameters​

systemPrompt​

string

The top-level instructions for the model.

history​

Message[]

The complete conversation history.

_maxContextLength​

number

Unused in this strategy.

_getTokenCount​

(messages) => number

Unused in this strategy.

Returns​

Message[]

The truncated message history with the system prompt at the beginning.

Implementation of​

ContextStrategy.buildContext