Skip to content

Memory adapters

type MemoryState = { summary: string; recent: Exchange[] };
type Exchange = { ask: string; answer: string; at: number };
type Memory = {
load: () => Promise<MemoryState>;
save: (state: MemoryState) => Promise<void>;
};

Memory that lives for the process. The default. Accepts an initial state, for tests.

Memory persisted as one JSON string under key (default "goliath.memory"). Corrupt data reads as empty.

type KeyValueStore = {
getItem: (key: string) => Promise<string | null> | string | null;
setItem: (key: string, value: string) => Promise<void> | void;
};

AsyncStorage matches this as is. For MMKV:

keyValueMemory({
getItem: (k) => storage.getString(k) ?? null,
setItem: (k, v) => storage.set(k, v),
});

Returns { summary: "", recent: [] }. Useful when writing your own adapter.

See the Memory guide for how the scribe fills these.