API Reference

Memory Types

Type definitions for memory layers, hooks, storage adapters, and projection policies in Noetic.

MemoryLayer

The core memory layer interface.

interface MemoryLayer<TState = unknown> {
  id: string;
  name: string;
  slot: number;
  scope: MemoryScope;
  budget?: BudgetConfig;
  hooks: MemoryHooks<TState>;
  timeouts?: Partial<LayerTimeouts>;
}
FieldTypeRequiredDescription
idstringyesUnique layer identifier
namestringyesHuman-readable name
slotnumberyesOrdering priority (lower = earlier in prompt)
scopeMemoryScopeyesPersistence boundary
budgetBudgetConfignoToken budget allocation
hooksMemoryHooks<TState>yesLifecycle callbacks
timeoutsPartial<LayerTimeouts>noPer-hook timeout overrides (ms)

MemoryScope

type MemoryScope = 'thread' | 'resource' | 'global' | 'execution';

BudgetConfig

type BudgetConfig =
  | number
  | { min: number; max: number }
  | 'auto';

Slot Constants

const Slot = {
  WORKING_MEMORY: 100,
  ENTITY: 150,
  OBSERVATIONS: 200,
  PROCEDURAL: 250,
  EPISODIC: 300,
  RAG: 350,
  SEMANTIC_RECALL: 400,
} as const;

MemoryHooks

interface MemoryHooks<TState = unknown> {
  init?: (params: InitParams) => Promise<InitResult<TState>>;
  recall?: (params: RecallParams<TState>) => Promise<RecallResult<TState> | null>;
  store?: (params: StoreParams<TState>) => Promise<StoreResult<TState> | undefined>;
  onSpawn?: (params: SpawnParams<TState>) => Promise<SpawnResult<TState> | null>;
  onReturn?: (params: ReturnParams<TState>) => Promise<ReturnResult<TState> | undefined>;
  onComplete?: (params: CompleteParams<TState>) => Promise<void | { state: TState }>;
  dispose?: (params: DisposeParams<TState>) => Promise<void>;
}

Hook Parameter Types

InitParams

FieldTypeDescription
storageScopedStorageScoped storage for this layer
scopeKeystringResolved scope key
ctxExecutionContextExecution context

InitResult

FieldTypeDescription
stateTStateInitial layer state

RecallParams

FieldTypeDescription
logItemLogCurrent conversation log
querystringCurrent user query
ctxExecutionContextExecution context
stateTStateCurrent layer state
budgetnumberAllocated token budget

RecallResult

FieldTypeDescription
itemsItem[]Items to inject into the prompt
tokenCountnumberTokens consumed by the items
stateTStateUpdated state (optional)

StoreParams

FieldTypeDescription
newItemsItem[]New items from the LLM response
logItemLogFull conversation log
responseLLMResponseComplete LLM response
ctxExecutionContextExecution context
stateTStateCurrent layer state

StoreResult

FieldTypeDescription
stateTStateUpdated state

SpawnParams

FieldTypeDescription
parentStateTStateParent layer state
childCtxExecutionContextChild execution context

SpawnResult

FieldTypeDescription
childStateTState | nullState for the child (null = don't propagate)
itemsItem[]Additional items for the child (optional)

ReturnParams

FieldTypeDescription
childStateTStateChild's final state
childLogItemLogChild's conversation log
parentStateTStateParent's current state
resultunknownChild's completion result

ReturnResult

FieldTypeDescription
parentStateTStateUpdated parent state
resultunknownTransformed result for pipeline (optional)

CompleteParams

FieldTypeDescription
logItemLogFull conversation log
ctxExecutionContextExecution context
stateTStateCurrent layer state
outcomeExecutionOutcomeHow the execution ended

DisposeParams

FieldTypeDescription
stateTStateFinal layer state

ExecutionOutcome

type ExecutionOutcome = 'success' | 'failure' | 'aborted';

ExecutionContext

Context available to memory layer hooks (different from the step Context).

interface ExecutionContext {
  executionId: string;
  threadId: string;
  resourceId?: string;
  depth: number;
  stepNumber: number;
  tokenUsage: { input: number; output: number };
  cost: number;
  model?: string;
  tokenize(text: string): number;
  trace: {
    setAttribute(key: string, value: string | number | boolean): void;
    addEvent(name: string, attributes?: Record<string, string | number | boolean>): void;
  };
}

LayerTimeouts

FieldTypeDescription
initnumberTimeout for init hook (ms, optional)
recallnumberTimeout for recall hook (ms, optional)
storenumberTimeout for store hook (ms, optional)
onSpawnnumberTimeout for onSpawn hook (ms, optional)
onReturnnumberTimeout for onReturn hook (ms, optional)
onCompletenumberTimeout for onComplete hook (ms, optional)
disposenumberTimeout for dispose hook (ms, optional)

ProjectionPolicy

interface ProjectionPolicy {
  tokenBudget: number;
  responseReserve: number;
  overflow: 'truncate' | 'summarize' | 'sliding_window';
  overflowModel?: string;
  windowSize?: number;
}
FieldTypeRequiredDescription
tokenBudgetnumberyesTotal token budget for all layers
responseReservenumberyesTokens reserved for the model response
overflow'truncate' | 'summarize' | 'sliding_window'yesStrategy when total recall exceeds budget
overflowModelstringnoModel for summarization overflow
windowSizenumbernoItems to keep for sliding window overflow

StorageAdapter

interface StorageAdapter {
  get<T>(key: string): Promise<T | null>;
  set<T>(key: string, value: T): Promise<void>;
  delete(key: string): Promise<void>;
  list(prefix: string): Promise<string[]>;
}
MethodDescription
get(key)Retrieve a value by key (returns null if not found)
set(key, value)Store a value
delete(key)Delete a value
list(prefix)List all keys with the given prefix

ScopedStorage

Same interface as StorageAdapter but scoped to a specific layer and scope key.

interface ScopedStorage {
  get<T>(key: string): Promise<T | null>;
  set<T>(key: string, value: T): Promise<void>;
  delete(key: string): Promise<void>;
  list(prefix?: string): Promise<string[]>;
}

MemoryTraceSpan

Observability data for a single memory hook execution.

interface MemoryTraceSpan {
  layerId: string;
  hook: 'init' | 'recall' | 'store' | 'onSpawn' | 'onReturn' | 'onComplete' | 'dispose';
  durationMs: number;
  status: 'ok' | 'error' | 'timeout' | 'skipped';
  budget?: { allocated: number; used: number; yielded: number };
  itemCount?: number;
  error?: { message: string; stack?: string };
}

On this page