Skip to content

ConversationManager

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

Abstract base class for conversation history management strategies.

The primary responsibility of a ConversationManager is overflow recovery: when the model returns a ContextWindowOverflowError, ConversationManager.reduce is called and MUST reduce the history enough for the next model call to succeed. If reduce returns false (no reduction performed), the error propagates out of the agent loop uncaught. This makes reduce a critical operation — implementations must be able to make meaningful progress when called with error set.

Optionally, a manager can also do proactive management (e.g. trimming after every invocation to stay within a window) by overriding initAgent, calling super.initAgent(agent) to preserve overflow recovery, then registering additional hooks.

class Last10MessagesManager extends ConversationManager {
readonly name = 'my:last-10-messages'
reduce({ agent }: ReduceOptions): boolean {
if (agent.messages.length <= 10) return false
agent.messages.splice(0, agent.messages.length - 10)
return true
}
}
new ConversationManager(): ConversationManager;

ConversationManager

abstract readonly name: string;

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

A stable string identifier for this conversation manager.

Plugin.name

abstract reduce(options): boolean;

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

Reduce the conversation history.

Called automatically when a ContextWindowOverflowError occurs (with error set).

This is a critical call: the implementation MUST remove enough history for the next model call to succeed. Returning false means no reduction was possible, and the ContextWindowOverflowError will propagate out of the agent loop.

Implementations should mutate agent.messages in place and return true if any reduction was performed, false otherwise.

ParameterTypeDescription
optionsConversationManagerReduceOptionsThe reduction options

boolean

true if the history was reduced, false otherwise


initAgent(agent): void;

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

Initialize the conversation manager with the agent instance.

Registers overflow recovery: when a ContextWindowOverflowError occurs, calls ConversationManager.reduce and retries the model call if reduction succeeded. If reduce returns false, the error propagates out of the agent loop uncaught.

Subclasses that need proactive management MUST call super.initAgent(agent) to preserve this overflow recovery behavior.

ParameterTypeDescription
agentLocalAgentThe agent to register hooks with

void

Plugin.initAgent