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()
assemble(memory, input): Promise<AssembledPrompt>;Defined in: packages/memory/src/memory-interface.ts:57
Assemble the layered system prompt for a single step.
Parameters
| Parameter | Type |
|---|---|
memory | Memory |
input | AssembleInput |
Returns
Promise<AssembledPrompt>
compactNow()
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
| Parameter | Type | Description |
|---|---|---|
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.agentId | string | - |
input.memory | Memory | - |
input.messages | readonly 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? | number | Per-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.runId | string | - |
input.scope | SessionScope | - |
input.sessionId | string | - |
input.signal? | AbortSignal | - |
input.source | CompactionSource | - |
input.summarizer? | CompactionSummarizer | - |
Returns
Promise<{ extraContent: readonly MessageContent[]; hookFailures: readonly { hookName: string; reason: string; }[]; result: CompactionResult; }>
config()
config(): ResolvedContextEngineConfig;Defined in: packages/memory/src/memory-interface.ts:118
Resolved configuration snapshot.
Returns
shouldCompact()
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
| Parameter | Type | Description |
|---|---|---|
messages | readonly Message[] | - |
options? | { compactableFromIndex?: number; precomputedTokens?: number; } | - |
options.compactableFromIndex? | number | Index 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<boolean>