Skip to content

Graphorin API reference v0.1.0


Graphorin API reference / @graphorin/memory / / ContextEngine

Interface: ContextEngine

Defined in: packages/memory/src/context-engine/engine.ts:245

Public surface of the ContextEngine instance returned by createContextEngine.

Stable

Methods

assemble()

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

Defined in: packages/memory/src/context-engine/engine.ts:247

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/context-engine/engine.ts:267

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

Parameters

ParameterType
input{ agentId: string; memory: Memory; messages: readonly Message[]; runId: string; scope: SessionScope; sessionId: string; signal?: AbortSignal; source: CompactionSource; summarizer?: CompactionSummarizer; }
input.agentIdstring
input.memoryMemory
input.messagesreadonly Message[]
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/context-engine/engine.ts:283

Resolved configuration snapshot.

Returns

ResolvedContextEngineConfig


shouldCompact()

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

Defined in: packages/memory/src/context-engine/engine.ts:258

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

ParameterType
messagesreadonly Message[]
options?{ precomputedTokens?: number; }
options.precomputedTokens?number

Returns

Promise&lt;boolean&gt;