Skip to content

MemoryInjectionConfig

Defined in: src/memory/types.ts:228

Configuration for memory context injection.

When enabled on a MemoryManager, the manager searches memory before a model call and makes the top results available to the model for that call, so relevant knowledge is present without the model choosing to search. The results are written into the latest user message as an InjectedBlock, which stays in the conversation and the session. Extraction leaves it out.

Extends the generic InjectionConfig (which carries trigger) with the memory-owned knobs: how many entries to retrieve, how to derive the query, and how to render the results.

trigger?:
| InjectionTrigger
| ((context) => boolean);

Defined in: src/injection/types.ts:43

When injection runs. An InjectionTrigger name selects a built-in policy; a predicate is the escape hatch — it receives the InjectionContext and returns whether to inject this call. A predicate that throws fails open (injection is skipped, the model call proceeds).

'userTurn'

InjectionConfig.trigger


maxEntries?: number;

Defined in: src/memory/types.ts:241

Maximum number of entries to retrieve and inject per model call.

A store ranks by semantic similarity, which is not the same as contextual usefulness, so the default injects a small candidate set rather than betting on the top hit. Raising this improves recall at the cost of a larger prepend (context bloat); lower it for a tighter injection.

With multiple stores, results are concatenated in store-registration order with no cross-store ranking, so this cap can favor entries from earlier-registered stores.

5

query?: (context) => string;

Defined in: src/memory/types.ts:249

Derives the search query from the current conversation. Return undefined or an empty string to skip injection for this call. A callback that throws fails open (injection is skipped).

Defaults to an adaptive query: the latest user message’s text on a user turn, otherwise the most recent assistant message’s text (the previous step on an autonomous turn).

ParameterType
context{ messages: MessageData[]; }
context.messagesMessageData[]

string


format?: (context) => string;

Defined in: src/memory/types.ts:263

Renders retrieved entries into the injected text. A callback that throws fails open (injection is skipped).

Defaults to a <memory> XML block with one <entry> per result, carrying a source attribute naming the originating store (when known) so the model can attribute and weigh each memory. The default escapes entry content and source, so a custom format that emits markup is responsible for its own escaping.

Receives only entries that aren’t already in a block this manager wrote earlier in the conversation. With a custom format, an entry counts as written when its content appears in such a block.

ParameterType
context{ entries: MemoryEntry[]; }
context.entriesMemoryEntry[]

string