Skip to content

MemoryInjectionConfig

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

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 injected text is ephemeral: it augments the model input for that call only and never persists into the durable conversation or session.

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.

optional 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


optional maxEntries?: number;

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

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

optional query?: (context) => string;

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

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


optional format?: (context) => string;

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

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.

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

string