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)
Extends
Section titled “Extends”Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new SlidingWindowConversationManager(config?): SlidingWindowConversationManager;Defined in: src/conversation-manager/sliding-window-conversation-manager.ts:135
Initialize the sliding window conversation manager.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
config? | SlidingWindowConversationManagerConfig | Configuration options for the sliding window manager. |
Returns
Section titled “Returns”SlidingWindowConversationManager
Overrides
Section titled “Overrides”ConversationManager.constructor
Properties
Section titled “Properties”_compressionThreshold
Section titled “_compressionThreshold”protected readonly _compressionThreshold: number;Defined in: src/conversation-manager/conversation-manager.ts:116
Inherited from
Section titled “Inherited from”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.
Overrides
Section titled “Overrides”Methods
Section titled “Methods”initAgent()
Section titled “initAgent()”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)
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
agent | LocalAgent | The agent to register hooks with |
Returns
Section titled “Returns”void
Overrides
Section titled “Overrides”reduce()
Section titled “reduce()”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.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
options | ConversationManagerReduceOptions | The reduction options |
Returns
Section titled “Returns”boolean
true if the history was reduced, false otherwise