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.
Example
Section titled “Example”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 }}Extended by
Section titled “Extended by”Implements
Section titled “Implements”Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new ConversationManager(): ConversationManager;Returns
Section titled “Returns”ConversationManager
Properties
Section titled “Properties”abstract readonly name: string;Defined in: src/conversation-manager/conversation-manager.ts:61
A stable string identifier for this conversation manager.
Implementation of
Section titled “Implementation of”Methods
Section titled “Methods”reduce()
Section titled “reduce()”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.
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
initAgent()
Section titled “initAgent()”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.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
agent | LocalAgent | The agent to register hooks with |
Returns
Section titled “Returns”void