Skip to content

SlidingWindowConversationManager

Defined in: src/conversation-manager/sliding-window-conversation-manager.ts:121

Implements a sliding window strategy for managing conversation history.

This class handles the logic of maintaining a conversation window that preserves tool usage pairs and avoids invalid window states. When the message count exceeds the window size, it will either truncate large tool results or remove the oldest messages while ensuring tool use/result pairs remain valid.

Registers hooks for:

  • AfterInvocationEvent: Applies sliding window management after each invocation
  • AfterModelCallEvent: Reduces context on overflow errors and requests retry (via super)
  • BeforeModelCallEvent: Proactive compression when threshold is exceeded (via super)
new SlidingWindowConversationManager(config?): SlidingWindowConversationManager;

Defined in: src/conversation-manager/sliding-window-conversation-manager.ts:135

Initialize the sliding window conversation manager.

ParameterTypeDescription
config?SlidingWindowConversationManagerConfigConfiguration options for the sliding window manager.

SlidingWindowConversationManager

ConversationManager.constructor

protected readonly _compressionThreshold: number;

Defined in: src/conversation-manager/conversation-manager.ts:116

ConversationManager._compressionThreshold


readonly name: "strands:sliding-window-conversation-manager" = 'strands:sliding-window-conversation-manager';

Defined in: src/conversation-manager/sliding-window-conversation-manager.ts:128

Unique identifier for this conversation manager.

ConversationManager.name

initAgent(agent): void;

Defined in: src/conversation-manager/sliding-window-conversation-manager.ts:151

Initialize the plugin by registering hooks with the agent.

Registers:

  • AfterInvocationEvent callback to apply sliding window management
  • AfterModelCallEvent callback to handle context overflow and request retry (via super)
  • BeforeModelCallEvent callback for proactive compression (via super)
ParameterTypeDescription
agentLocalAgentThe agent to register hooks with

void

ConversationManager.initAgent


reduce(options): boolean;

Defined in: src/conversation-manager/sliding-window-conversation-manager.ts:171

Reduce the conversation history.

When error is set (reactive overflow recovery), attempts to truncate large tool results first before falling back to message trimming.

When error is undefined (proactive compression), only trims messages without attempting tool result truncation.

ParameterTypeDescription
optionsConversationManagerReduceOptionsThe reduction options

boolean

true if the history was reduced, false otherwise

ConversationManager.reduce