Interface AgentMemoryProvider

Provider hook interface consumed by agent() for memory integration.

When provided on the agent config, getContext is called before each LLM generation to inject retrieved memory into the system prompt, and observe is called after each turn to encode the exchange for future recall. Both hooks are optional — implementations may choose to provide read-only or write-only memory behavior.

Auto-wires on every agent call path as of AgentOS 0.2.0: direct agent.stream() / .generate() and agent.session().send() / .stream() all invoke the hooks when the provider is present.

interface AgentMemoryProvider {
    getContext?: ((text, opts?) => Promise<null | {
        contextText?: string;
    }>);
    observe?: ((role, text) => Promise<void>);
}

Properties

getContext?: ((text, opts?) => Promise<null | {
    contextText?: string;
}>)

Retrieve a memory context block to prepend to the system prompt.

Type declaration

    • (text, opts?): Promise<null | {
          contextText?: string;
      }>
    • Parameters

      • text: string

        The user input for the current turn.

      • Optional opts: {
            tokenBudget?: number;
        }

        Retrieval options. tokenBudget caps the memory block size.

        • Optional tokenBudget?: number

      Returns Promise<null | {
          contextText?: string;
      }>

Returns

An object whose contextText (when present) is injected as a system message before the LLM call. Returning null or an object without contextText skips injection.

observe?: ((role, text) => Promise<void>)

Record an observation of a turn exchange.

Invoked twice per turn (role: 'user' with the input, then role: 'assistant' with the reply) as fire-and-forget. Rejections are swallowed so memory-backend errors do not break generation.

Type declaration

    • (role, text): Promise<void>
    • Parameters

      • role: "user" | "assistant"

        Whether the content came from the user or assistant.

      • text: string

        Plain text content of the turn.

      Returns Promise<void>