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>;};inMemory(initial?)
Section titled “inMemory(initial?)”Memory that lives for the process. The default. Accepts an initial state, for tests.
keyValueMemory(store, key?)
Section titled “keyValueMemory(store, key?)”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),});emptyMemory()
Section titled “emptyMemory()”Returns { summary: "", recent: [] }. Useful when writing your own adapter.
See the Memory guide for how the scribe fills these.