Skip to content

Graphorin API reference v0.7.0


Graphorin API reference / @graphorin/memory / / ContextEngine

Interface: ContextEngine

Defined in: packages/memory/src/memory-interface.ts:55

Public surface of the ContextEngine instance returned by createContextEngine.

Stable

Methods

assemble()

ts
assemble(memory, input): Promise<AssembledPrompt>;

Defined in: packages/memory/src/memory-interface.ts:57

Assemble the layered system prompt for a single step.

Parameters

ParameterType
memoryMemory
inputAssembleInput

Returns

Promise&lt;AssembledPrompt&gt;


compactNow()

ts
compactNow(input): Promise<{
  extraContent: readonly MessageContent[];
  hookFailures: readonly {
     hookName: string;
     reason: string;
  }[];
  result: CompactionResult;
}>;

Defined in: packages/memory/src/memory-interface.ts:88

Run a compaction call. Phase 12 calls this when the trigger fires (source: 'auto-trigger') or the operator invokes agent.compact(...) (source: 'manual').

Parameters

ParameterTypeDescription
input{ agentId: string; memory: Memory; messages: readonly Message[]; prefixMessages?: readonly Message[]; preserveRecentTurns?: number; procedural?: { tags?: readonly string[]; topic?: string; }; runId: string; scope: SessionScope; sessionId: string; signal?: AbortSignal; source: CompactionSource; summarizer?: CompactionSummarizer; }-
input.agentIdstring-
input.memoryMemory-
input.messagesreadonly Message[]-
input.prefixMessages?readonly Message[]The caller's pinned system prefix - the messages EXCLUDED from messages before this call (context-engine-04). Used only for accounting: the anti-thrash guard and the "still above threshold" warning must compare against the FULL post-splice context (prefix + summary + preserved + essentials), or a real system prompt defeats the guard and a summarizer call fires every step at the context edge. Never compacted, never returned.
input.preserveRecentTurns?numberPer-call override of the strategy's preserve-recent count (CE-3).
input.procedural?{ tags?: readonly string[]; topic?: string; }Topic/tags narrowing for the procedural-rules re-anchor hook (CE-6).
input.procedural.tags?readonly string[]-
input.procedural.topic?string-
input.runIdstring-
input.scopeSessionScope-
input.sessionIdstring-
input.signal?AbortSignal-
input.sourceCompactionSource-
input.summarizer?CompactionSummarizer-

Returns

Promise<{ extraContent: readonly MessageContent[]; hookFailures: readonly { hookName: string; reason: string; }[]; result: CompactionResult; }>


config()

ts
config(): ResolvedContextEngineConfig;

Defined in: packages/memory/src/memory-interface.ts:118

Resolved configuration snapshot.

Returns

ResolvedContextEngineConfig


shouldCompact()

ts
shouldCompact(messages, options?): Promise<boolean>;

Defined in: packages/memory/src/memory-interface.ts:68

Trigger evaluation primitive used by Phase 12 (agent runtime) at the top of every step. Returns true when the in-flight buffer's token count crosses the per-provider trigger threshold. Pass precomputedTokens to amortize the count via the per-message cache surfaced by SessionMemoryStoreExt.totalCachedTokens(scope) (DEC-131) - the production hot path is an O(1) comparison when the cache is warm.

Parameters

ParameterTypeDescription
messagesreadonly Message[]-
options?{ compactableFromIndex?: number; precomputedTokens?: number; }-
options.compactableFromIndex?numberIndex of the first COMPACTABLE message (context-engine-04): the caller's pinned, never-compacted system prefix ends here. The SOTA-4 reclaim floor counts only messages.slice(from) older turns as reclaimable - without it a large system prompt is counted as reclaimable and the floor fires the summarizer for near-zero real reclaim. Default 0 (everything compactable).
options.precomputedTokens?number-

Returns

Promise&lt;boolean&gt;