Skip to content

agent-sessions / Exports / ContextWindowTracker

Class: ContextWindowTracker

Table of contents

Constructors

Methods

Constructors

constructor

new ContextWindowTracker(model, contextMaxTokens?): ContextWindowTracker

Parameters

NameType
modelstring
contextMaxTokens?number

Returns

ContextWindowTracker

Defined in

agent-sessions/src/context-window-tracker.ts:30

Methods

getContextState

getContextState(): IContextWindowState

Get current context window state

Returns

IContextWindowState

Defined in

agent-sessions/src/context-window-tracker.ts:35


shouldAutoCompact

shouldAutoCompact(): boolean

Whether auto-compaction threshold has been exceeded

Returns

boolean

Defined in

agent-sessions/src/context-window-tracker.ts:49


updateFromHistory

updateFromHistory(history): void

Estimate token usage from conversation history.

First tries to read actual token counts from message metadata (provider response). Falls back to character-based estimation (chars / 4) which is a reasonable approximation for English/code.

Parameters

NameType
historyTUniversalMessage[]

Returns

void

Defined in

agent-sessions/src/context-window-tracker.ts:60


reset

reset(): void

Reset token tracking

Returns

void

Defined in

agent-sessions/src/context-window-tracker.ts:91

Released under the MIT License.