Class: ContextWindowTracker
Makaio Framework / services-core / ContextWindowTracker
Class: ContextWindowTracker
Section titled “Class: ContextWindowTracker”Defined in: ../../../packages/services/core/src/session/context-window/context-window-tracker.ts:27
Tracks context window state per session, aggregating across agents.
Subscribes to AgentSubjects.contextWindow.updated and maintains per-session state using “worst agent” aggregation strategy.
Example
Section titled “Example”const tracker = new ContextWindowTracker(MakaioBus);tracker.start();
// Later, query session stateconst state = tracker.getSessionState('session-123');if (state?.level === 'critical') { // Suggest compression}
// Cleanup on shutdowntracker.stop();Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new ContextWindowTracker(
bus,config?):ContextWindowTracker
Defined in: ../../../packages/services/core/src/session/context-window/context-window-tracker.ts:33
Parameters
Section titled “Parameters”config?
Section titled “config?”Returns
Section titled “Returns”ContextWindowTracker
Methods
Section titled “Methods”clearSession()
Section titled “clearSession()”clearSession(
sessionId):void
Defined in: ../../../packages/services/core/src/session/context-window/context-window-tracker.ts:102
Clear state for a specific session (e.g., on session close). Removes both the session state and all agent states for that session.
Parameters
Section titled “Parameters”sessionId
Section titled “sessionId”string
The session to clear
Returns
Section titled “Returns”void
getSessionState()
Section titled “getSessionState()”getSessionState(
sessionId):SessionContextWindowState|undefined
Defined in: ../../../packages/services/core/src/session/context-window/context-window-tracker.ts:93
Get aggregated context state for a session.
State persists until explicitly cleared via clearSession(). Clear is called by MakaioSessionService on:
- session.close (session closed)
- session.compressed (context compression)
Even if we haven’t heard from agents recently, the context window is still full - the state remains valid.
Parameters
Section titled “Parameters”sessionId
Section titled “sessionId”string
The session to get state for
Returns
Section titled “Returns”SessionContextWindowState | undefined
The aggregated context window state, or undefined if no data
start()
Section titled “start()”start():
void
Defined in: ../../../packages/services/core/src/session/context-window/context-window-tracker.ts:44
Start tracking context window updates. Idempotent - calling multiple times is safe.
Returns
Section titled “Returns”void
stop()
Section titled “stop()”stop():
void
Defined in: ../../../packages/services/core/src/session/context-window/context-window-tracker.ts:73
Stop tracking and clear all state.
Returns
Section titled “Returns”void